|
32 | 32 | #include <bio/map_io/header.hpp> |
33 | 33 | #include <bio/map_io/misc.hpp> |
34 | 34 | #include <bio/map_io/sam_flag.hpp> |
| 35 | +#include <bio/map_io/sam_tag_dictionary.hpp> |
35 | 36 |
|
36 | 37 | namespace bio |
37 | 38 | { |
@@ -109,6 +110,13 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_ |
109 | 110 | get<field::tlen>(raw_record) = (*file_it).fields[8]; |
110 | 111 | get<field::seq>(raw_record) = (*file_it).fields[9]; |
111 | 112 | get<field::qual>(raw_record) = (*file_it).fields[10]; |
| 113 | + |
| 114 | + // fields[10].end() that is guaranteed to be char* |
| 115 | + char const * end_qual = (*file_it).fields[10].data() + (*file_it).fields[10].size() + 1/*\t or \n*/; |
| 116 | + // line.end() that is guaranteed to be char* |
| 117 | + char const * end_line = (*file_it).line.data() + (*file_it).line.size(); |
| 118 | + // SAM tags go from end of qual til end of line (possibly empty) |
| 119 | + get<field::tags>(raw_record) = std::string_view{end_qual, static_cast<size_t>(end_line - end_qual)}; |
112 | 120 | } |
113 | 121 |
|
114 | 122 | /* PARSED RECORD HANDLING */ |
@@ -160,7 +168,7 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_ |
160 | 168 | } |
161 | 169 | } |
162 | 170 |
|
163 | | - /* POS, MAPQ are handled correctly by default, unless we want pos to be read into an std:optional */ |
| 171 | + /* POS, MAPQ are handled correctly by default */ |
164 | 172 |
|
165 | 173 | //!\brief Overload for parsing CIGAR. |
166 | 174 | void parse_field(vtag_t<field::cigar> const & /**/, std::vector<seqan3::cigar> & cigar_vector) |
@@ -242,6 +250,16 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_ |
242 | 250 | parse_field_aux(raw_field, parsed_field); // reading into e.g. dna4 vector |
243 | 251 | } |
244 | 252 |
|
| 253 | + //!\brief Overload for parsing the SAM tag dictionary. |
| 254 | + void parse_field(vtag_t<field::tags> const & /**/, map_io::sam_tag_dictionary & dictionary) |
| 255 | + { |
| 256 | + std::string_view raw_field = get<field::tags>(raw_record); |
| 257 | + |
| 258 | + if (!raw_field.empty()) |
| 259 | + for (std::string_view const tag_field : raw_field | detail::eager_split('\t')) |
| 260 | + dictionary.parse_and_emplace(tag_field); |
| 261 | + } |
| 262 | + |
245 | 263 | //!\brief Overload for parsing the private data. |
246 | 264 | void parse_field(vtag_t<field::_private> const & /**/, map_io::record_private_data & parsed_field) |
247 | 265 | { |
|
0 commit comments