8000 [IO] Make seqan3::sam_file_header::program_info_t easier to copy by tsnorri · Pull Request #3145 · seqan/seqan3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[IO] Make seqan3::sam_file_header::program_info_t easier to copy #3145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions include/seqan3/io/sam_file/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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].
Expand Down
37 changes: 37 additions & 0 deletions test/unit/io/sam_file/sam_file_output_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <gtest/gtest.h>

#include <iterator>
#include <ranges>
#include <sstream>
#include <type_traits>

#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/io/sam_file/output.hpp>
Expand Down Expand Up @@ -197,6 +199,41 @@ void assign_impl(source_t && source)
EXPECT_EQ(reinterpret_cast<std::ostringstream &>(fout.get_stream()).str(), output_comp);
}

// ----------------------------------------------------------------------------
// header
// ----------------------------------------------------------------------------
// See https://github.com/seqan/seqan3/issues/3137
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.
// input_ref_ids_type is std::deque<std::string> by default.
using input_ref_ids_type = std::remove_cvref_t<decltype(input_header.ref_ids())>;
using output_ref_ids_type = std::array<std::string, 0>;
static_assert(!std::is_same_v<input_ref_ids_type, output_ref_ids_type>);

seqan3::sam_file_output fout{std::ostringstream{},
output_ref_ids_type{},
std::ranges::empty_view<std::size_t>{},
seqan3::format_sam{}};
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(output_header.program_infos);
EXPECT_FALSE(pg_infos.empty());
EXPECT_EQ("cool_program", pg_infos.front().name);
}

// ----------------------------------------------------------------------------
// row
// ----------------------------------------------------------------------------
Expand Down
0