68 template <
typename ref_
id_type,
typename ref_
id_tmp_type,
typename header_type,
typename ref_seqs_type>
76 template <
typename stream_view_type, std::ranges::forward_range target_range_type>
79 template <std::ranges::forward_range target_range_type>
82 template <arithmetic arithmetic_target_type>
85 template <
typename stream_view_type,
typename ref_
ids_type,
typename ref_seqs_type>
90 template <
typename stream_t,
typename header_type>
104template <
typename ref_
id_type,
typename ref_
id_tmp_type,
typename header_type,
typename ref_seqs_type>
107 header_type & header,
114 if (
search == header.ref_dict.end())
116 if constexpr (detail::decays_to_ignore_v<ref_seqs_type>)
120 throw format_error{
"Unknown reference id found in record which is not present in the header."};
125 auto pos = std::ranges::size(header.ref_ids()) - 1;
126 header.ref_dict[header.ref_ids()[pos]] = pos;
132 throw format_error{
"Unknown reference id found in record which is not present in the given ids."};
186template <
typename stream_view_type, std::ranges::forward_range target_range_type>
198 if (
char c = *
it; !(++
it == std::ranges::end(
stream_view) && c ==
'*'))
202 | views::char_to<target_range_value_t>,
214template <std::ranges::forward_range target_range_type>
217 if (str.
size() == 1 && str[0] ==
'*')
220 if constexpr (std::assignable_from<target_range_type, std::string_view>)
226 target.resize(str.
size());
227 for (
size_t i = 0;
i < str.
size(); ++
i)
228 target[
i] =
assign_char_to(str[
i], std::ranges::range_value_t<target_range_type>{});
241template <arithmetic arithmetic_target_type>
247 if (
res.ec == std::errc::invalid_argument ||
res.ptr != str.
end())
249 +
"' could not be cast into type " + detail::type_name_as_string<arithmetic_target_type>};
251 if (
res.ec == std::errc::result_out_of_range)
253 +
"' into type " + detail::type_name_as_string<arithmetic_target_type>
254 +
" would cause an overflow."};
278template <
typename stream_view_type,
typename ref_
ids_type,
typename ref_seqs_type>
305 string_buffer.clear();
308 string_buffer.push_back(*
it);
393 if (
hdr.format_version.empty())
402 std::ranges::range_value_t<
decltype(
hdr.ref_ids())>
id;
445 if constexpr (!detail::decays_to_ignore_v<ref_seqs_type>)
452 "' found in SAM header ",
453 "(header.ref_ids(): ",
460 throw format_error{
"Provided and header-based reference length differ."};
462 hdr.ref_id_info[
id_it->second] = std::move(info);
466 static_assert(!detail::is_type_specialisation_of_v<
decltype(
hdr.ref_ids()),
std::deque>,
467 "The range over reference ids must be of type std::deque such that pointers are not "
470 hdr.ref_ids().push_back(
id);
471 hdr.ref_id_info.push_back(info);
472 hdr.ref_dict[(
hdr.ref_ids())[(
hdr.ref_ids()).size() - 1]] = (
hdr.ref_ids()).size() - 1;
505 hdr.read_groups.emplace_back(std::move(
tmp));
568 hdr.program_infos.emplace_back(std::move(
tmp));
579 hdr.comments.emplace_back(std::move(
tmp));
605template <
typename stream_t,
typename header_type>
609 if constexpr (!detail::decays_to_ignore_v<header_type>)
617 if (!header.sorting.empty()
618 && !(header.sorting ==
"unknown" || header.sorting ==
"unsorted" || header.sorting ==
"queryname"
619 || header.sorting ==
"coordinate"))
620 throw format_error{
"SAM format error: The header.sorting member must be "
621 "one of [unknown, unsorted, queryname, coordinate]."};
623 if (!header.grouping.empty()
624 && !(header.grouping ==
"none" || header.grouping ==
"query" || header.grouping ==
"reference"))
625 throw format_error{
"SAM format error: The header.grouping member must be "
626 "one of [none, query, reference]."};
645 stream <<
"@HD\tVN:";
648 if (!header.sorting.empty())
649 stream <<
"\tSO:" << header.sorting;
651 if (!header.subsorting.empty())
652 stream <<
"\tSS:" << header.subsorting;
654 if (!header.grouping.empty())
655 stream <<
"\tGO:" << header.grouping;
657 if (!header.user_tags.empty())
658 stream <<
'\t' << header.user_tags;
665 stream <<
"@SQ\tSN:";
678 for (
auto const &
read_group : header.read_groups)
690 for (
auto const &
program : header.program_infos)
696 stream <<
"\tPN:" <<
program.name;
698 if (!
program.command_line_call.empty())
699 stream <<
"\tCL:" <<
program.command_line_call;
702 stream <<
"\tPP:" <<
program.previous;
704 if (!
program.description.empty())
705 stream <<
"\tDS:" <<
program.description;
708 stream <<
"\tVN:" <<
program.version;
710 if (!
program.user_tags.empty())
711 stream <<
'\t' <<
program.user_tags;
717 for (
auto const &
comment : header.comments)
T back_inserter(T... args)
Provides seqan3::views::char_to.
Provides various utility functions.
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:517
constexpr void write_eol(it_t &it, bool const add_cr)
Write "\n" or "\r\n" to the stream iterator, depending on arguments.
Definition io/detail/misc.hpp:46
@ comment
Comment field of arbitrary content, usually a string.
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition predicate.hpp:60
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
Provides various utility functions.
Auxiliary functions for the SAM IO.
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std::string to_string(value_type &&... values)
Streams all parameters via the seqan3::debug_stream and returns a concatenated string.
Definition to_string.hpp:26
constexpr auto const & get(configuration< configs_t... > const &config) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition configuration.hpp:412
Provides seqan3::debug_stream and related types.
Provides seqan3::views::repeat_n.
Provides seqan3::views::slice.
Object storing information for a search (of a search scheme).
Definition search_scheme_precomputed.hpp:25
The options type defines various option members that influence the behavior of all or some formats.
Definition sam_file/output_options.hpp:23
bool add_carriage_return
The default plain text line-ending is "\n", but on Windows an additional carriage return is recommend...
Definition sam_file/output_options.hpp:27
Stores information of the program/tool that was used to create a SAM/BAM file.
Definition header.hpp:30
Provides traits to inspect some information of a type, for example its name.
Provides seqan3::views::zip.