Skip to content

Commit

Permalink
[FIX] Parsing BAM headers with 64 reference sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Mar 3, 2021
1 parent df9fd5f commit 939a603
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions include/seqan3/io/sam_file/format_sam_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,36 @@ inline void format_sam_base::read_header(stream_view_type && stream_view,
ref_seqs_type & /*ref_id_to_pos_map*/)
{
auto it = std::ranges::begin(stream_view);
auto end = std::ranges::end(stream_view);
std::string string_buffer{};

auto parse_tag_value = [&stream_view, &it, this] (auto & value) // helper function to parse the next tag value
auto call_read_field = [&it, &string_buffer, this] (auto predicate, auto & value)
{
detail::consume(stream_view | views::take_until_or_throw(is_char<':'>)); // skip tag name
std::ranges::next(std::ranges::begin(stream_view)); // skip ':'
read_field(stream_view | views::take_until_or_throw(is_char<'\t'> || is_char<'\n'>), value);
it = std::ranges::begin(stream_view); // make sure iterator is up2date
string_buffer.clear();
while (!predicate(*it))
{
string_buffer.push_back(*it);
++it;
}
read_field(string_buffer, value);
};

auto consume = [&it] ()
{
while (!is_char<':'>(*it))
++it;
++it;
};

auto parse_tag_value = [&] (auto & value) // helper function to parse the next tag value
{
consume();
call_read_field(is_char<'\t'> || is_char<'\n'>, value);
};

while (is_char<'@'>(*it))
while (it != end)
{
assert(is_char<'@'>(*it)); // or throw?
++it; // skip @

switch (*it)
Expand Down Expand Up @@ -518,7 +537,7 @@ inline void format_sam_base::read_header(stream_view_type && stream_view,
if (is_char<'\t'>(*it)) // read rest of the tags
{
++it; // skip tab
read_field(stream_view | views::take_until_or_throw(is_char<'\n'>), get<1>(info));
call_read_field(is_char<'\n'>, get<1>(info));
}
++it; // skip newline

Expand Down Expand Up @@ -560,7 +579,7 @@ inline void format_sam_base::read_header(stream_view_type && stream_view,
if (is_char<'\t'>(*it)) // read rest of the tags
{
++it;
read_field(stream_view | views::take_until_or_throw(is_char<'\n'>), get<1>(tmp));
call_read_field(is_char<'\n'>, get<1>(tmp));
}
++it; // skip newline

Expand Down Expand Up @@ -619,7 +638,7 @@ inline void format_sam_base::read_header(stream_view_type && stream_view,
++it; // skip C
++it; // skip O
++it; // skip :
read_field(stream_view | views::take_until_or_throw(is_char<'\n'>), tmp);
call_read_field(is_char<'\n'>, tmp);
++it; // skip newline

hdr.comments.emplace_back(std::move(tmp));
Expand Down

0 comments on commit 939a603

Please sign in to comment.