From b3a9a6f9513f2db10aaf5cd558fbc2ea5561edf8 Mon Sep 17 00:00:00 2001 From: Tuukka Norri Date: Thu, 20 Apr 2023 16:01:54 +0300 Subject: [PATCH 1/3] [MISC] Make seqan3::sam_file_header::program_info_t easier to copy See #3137. --- include/seqan3/io/sam_file/header.hpp | 32 +++++++++------- .../unit/io/sam_file/sam_file_output_test.cpp | 37 +++++++++++++++++++ 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/include/seqan3/io/sam_file/header.hpp b/include/seqan3/io/sam_file/header.hpp index b98af2ea8d..1e670abdaf 100644 --- a/include/seqan3/io/sam_file/header.hpp +++ b/include/seqan3/io/sam_file/header.hpp @@ -24,6 +24,21 @@ namespace seqan3 { +/*!\brief Stores information of the program/tool that was used to create a SAM/BAM file. + * \ingroup io_sam_file + * + * \remark For a complete overview, take a look at \ref io_sam_file + */ +struct sam_file_program_info_t +{ + std::string id; //!< A unique (file scope) id. + std::string name; //!< The official name. + std::string command_line_call; //!< The command line call that produces the file. + std::string previous; //!< The id of the previous program if program calls were chained. + std::string description; //!< A description of the program and/or program call. + std::string version; //!< The program/tool version. +}; + /*!\brief Stores the header information of SAM/BAM files. * \ingroup io_sam_file * @@ -63,19 +78,10 @@ class sam_file_header {} //!\} - //!\brief Stores information of the program/tool that was used to create the file. - struct program_info_t - { - std::string id; //!< A unique (file scope) id. - std::string name; //!< The official name. - std::string command_line_call; //!< The command line call that produces the file. - std::string previous; //!< The id of the previous program if program calls were chained. - std::string description; //!< A description of the program and/or program call. - std::string version; //!< The program/tool version. - }; - - std::string format_version; //!< The file format version. Note: this is overwritten by our formats on output. - std::string sorting; //!< The sorting of the file. SAM: [unknown, unsorted, queryname, coordinate]. + using program_info_t = + sam_file_program_info_t; //!< Stores information of the program/tool that was used to create the file. + std::string format_version; //!< The file format version. Note: this is overwritten by our formats on output. + std::string sorting; //!< The sorting of the file. SAM: [unknown, unsorted, queryname, coordinate]. std::string subsorting; //!< The sub-sorting of the file. SAM: [unknown, unsorted, queryname, coordinate](:[A-Za-z0-9_-]+)+. std::string grouping; //!< The grouping of the file. SAM: [none, query, reference]. diff --git a/test/unit/io/sam_file/sam_file_output_test.cpp b/test/unit/io/sam_file/sam_file_output_test.cpp index 0d4fc35cb1..b8be9cbe7c 100644 --- a/test/unit/io/sam_file/sam_file_output_test.cpp +++ b/test/unit/io/sam_file/sam_file_output_test.cpp @@ -8,7 +8,9 @@ #include #include +#include #include +#include #include #include @@ -197,6 +199,41 @@ void assign_impl(source_t && source) EXPECT_EQ(reinterpret_cast(fout.get_stream()).str(), output_comp); } +// ---------------------------------------------------------------------------- +// header +// ---------------------------------------------------------------------------- +TEST(header, copy_program_info_t) +{ + std::string comp = + R"(@HD VN:1.6 SO:unknown GO:none +@SQ SN:ref LN:26 +@PG ID:prog1 PN:cool_program +@CO This is a comment. +read1 41 ref 1 61 1S1M1D1M1I ref 10 300 ACGT !##$ AS:i:2 NM:i:7 +)"; + seqan3::sam_file_input fin{std::istringstream{comp}, seqan3::format_sam{}}; + + auto & input_header(fin.header()); + + // We would like to test that (some of) the headers can be copied even if + // ref_ids_types do not match. + typedef std::remove_cvref_t + input_ref_ids_type; // std::deque by default. + typedef std::array output_ref_ids_type; + static_assert(!std::is_same_v); + + seqan3::sam_file_output fout{std::ostringstream{}, + output_ref_ids_type{}, + std::ranges::empty_view{}, + seqan3::format_sam{}}; + fout.header().program_infos = fin.header().program_infos; + + // Verify that the above was sufficient to copy the headers. + auto const & pg_infos(fout.header().program_infos); + EXPECT_FALSE(pg_infos.empty()); + EXPECT_EQ("cool_program", pg_infos.front().name); +} + // ---------------------------------------------------------------------------- // row // ---------------------------------------------------------------------------- From 1027c9f0b91761f6dbf16b16b31829db129f59c2 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 24 Apr 2023 12:14:38 +0200 Subject: [PATCH 2/3] [MISC] Review --- test/unit/io/sam_file/sam_file_output_test.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/unit/io/sam_file/sam_file_output_test.cpp b/test/unit/io/sam_file/sam_file_output_test.cpp index b8be9cbe7c..e018c9c880 100644 --- a/test/unit/io/sam_file/sam_file_output_test.cpp +++ b/test/unit/io/sam_file/sam_file_output_test.cpp @@ -212,24 +212,23 @@ TEST(header, copy_program_info_t) read1 41 ref 1 61 1S1M1D1M1I ref 10 300 ACGT !##$ AS:i:2 NM:i:7 )"; seqan3::sam_file_input fin{std::istringstream{comp}, seqan3::format_sam{}}; - auto & input_header(fin.header()); - // We would like to test that (some of) the headers can be copied even if - // ref_ids_types do not match. - typedef std::remove_cvref_t - input_ref_ids_type; // std::deque by default. - typedef std::array output_ref_ids_type; + // We would like to test that (some of) the headers can be copied even if ref_ids_types do not match. + // input_ref_ids_type is std::deque by default. + using input_ref_ids_type = std::remove_cvref_t; + using output_ref_ids_type = std::array; static_assert(!std::is_same_v); seqan3::sam_file_output fout{std::ostringstream{}, output_ref_ids_type{}, std::ranges::empty_view{}, seqan3::format_sam{}}; - fout.header().program_infos = fin.header().program_infos; + auto & output_header(fout.header()); + output_header.program_infos = input_header.program_infos; // Verify that the above was sufficient to copy the headers. - auto const & pg_infos(fout.header().program_infos); + auto const & pg_infos(output_header.program_infos); EXPECT_FALSE(pg_infos.empty()); EXPECT_EQ("cool_program", pg_infos.front().name); } From de6d10522af12f56c002524ab337a670552683cd Mon Sep 17 00:00:00 2001 From: Svenja Mehringer Date: Tue, 25 Apr 2023 11:38:21 +0200 Subject: [PATCH 3/3] Update test/unit/io/sam_file/sam_file_output_test.cpp --- test/unit/io/sam_file/sam_file_output_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/io/sam_file/sam_file_output_test.cpp b/test/unit/io/sam_file/sam_file_output_test.cpp index e018c9c880..d5931348bb 100644 --- a/test/unit/io/sam_file/sam_file_output_test.cpp +++ b/test/unit/io/sam_file/sam_file_output_test.cpp @@ -202,6 +202,7 @@ void assign_impl(source_t && source) // ---------------------------------------------------------------------------- // header // ---------------------------------------------------------------------------- +// See https://github.com/seqan/seqan3/issues/3137 TEST(header, copy_program_info_t) { std::string comp =