Skip to content

Commit eec77d5

Browse files
committed
more work
1 parent 4b26821 commit eec77d5

File tree

7 files changed

+372
-131
lines changed

7 files changed

+372
-131
lines changed

include/bio/format/sam_input_handler.hpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,27 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
132132
/* POS, MAPQ are handled correctly by default, unless we want pos to be read into an std:optional */
133133

134134
//!\brief Overload for parsing CIGAR.
135-
void parse_field(vtag_t<field::cigar> const & /**/, std::vector<seqan3::cigar> & parsed_field)
135+
void parse_field(vtag_t<field::cigar> const & /**/, std::vector<seqan3::cigar> & cigar_vector)
136136
{
137137
std::string_view raw_field = get<field::cigar>(raw_record);
138138

139139
if (raw_field != ".")
140140
{
141-
size_t ref_length, seq_length; // used to construct the seqan3::field::alignment
142-
std::tie(parsed_field, ref_length, seq_length) = seqan3::detail::parse_cigar(raw_field);
141+
uint32_t cigar_count{};
142+
char const * ptr = raw_field.data();
143+
char const * end = ptr + raw_field.size();
144+
145+
while (ptr < end)
146+
{
147+
auto const res = std::from_chars(ptr, end, cigar_count); // reads number up to next chatacter
148+
149+
if (res.ec != std::errc{}) // parse number
150+
throw format_error{"Corrupted cigar string encountered"}; // todo, how in b.i.o?
151+
152+
ptr = res.ptr + 1; // skip cigar operation character
153+
154+
cigar_vector.emplace_back(cigar_count, seqan3::cigar::operation{}.assign_char(*res.ptr));
155+
}
143156
}
144157
}
145158

@@ -190,8 +203,9 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
190203
format_input_handler & operator=(format_input_handler &&) = default;
191204

192205
template <typename options_t>
193-
format_input_handler(std::istream & str, options_t const & options) : base_t{str}, file_it{str, false /*no_init!*/}
194-
206+
format_input_handler(std::istream & str, options_t const & options) :
207+
base_t{str},
208+
file_it{str, false /*no_init!*/}
195209
{
196210
// extract options
197211
if constexpr (requires { (bool)options.print_warnings; })
@@ -207,7 +221,7 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
207221
header_string += file_it->line;
208222
header_string += "\n";
209223
}
210-
// header = map_io::header<std::vector<std::string>>{std::move(header_string)};
224+
header = map_io::header<std::vector<std::string>>{std::move(header_string)};
211225
}
212226

213227
auto const & get_header() const { return header; }

0 commit comments

Comments
 (0)