34 #include <seqan3/io/detail/record.hpp>
113 template <
typename t>
131 requires std::same_as<typename t::ref_sequences, ref_info_not_given> || requires ()
138 (!std::same_as<typename t::ref_sequences, ref_info_not_given> ||
140 requires std::ranges::forward_range<std::ranges::range_reference_t<typename t::ref_ids>>;
141 requires std::ranges::forward_range<typename t::ref_ids>;
182 template <
typename ref_sequences_t = ref_info_not_given,
typename ref_
ids_t = std::deque<std::
string>>
197 template <
typename _sequence_alphabet>
201 template <
typename _
id_alphabet>
208 template <
typename _quality_alphabet>
338 #ifdef SEQAN3_DEPRECATED_310
350 #ifdef SEQAN3_DEPRECATED_310
375 using dummy_ref_type = decltype(
views::repeat_n(
typename traits_type::sequence_alphabet{},
size_t{}) |
379 using ref_sequence_unsliced_type =
380 detail::lazy_conditional_t<std::ranges::range<typename traits_type::ref_sequences const>,
381 detail::lazy<std::ranges::range_reference_t,
382 typename traits_type::ref_sequences
const>,
386 using ref_sequence_sliced_type = decltype(std::declval<ref_sequence_unsliced_type>() |
views::slice(0, 0));
395 typename traits_type::sequence_alphabet>;
397 using id_type =
typename traits_type::template id_container<char>;
408 ref_sequence_sliced_type>;
428 typename traits_type::quality_alphabet>;
435 #ifdef SEQAN3_DEPRECATED_310
442 using header_type = sam_file_header<typename traits_type::ref_ids>;
449 decltype(std::declval<sequence_type &>() |
views::slice(0, 0))>,
461 #ifdef SEQAN3_DEPRECATED_310
473 #ifdef SEQAN3_DEPRECATED_310
503 #ifdef SEQAN3_DEPRECATED_310
515 #ifdef SEQAN3_DEPRECATED_310
521 #ifdef SEQAN3_DEPRECATED_310
526 "You selected the deprecated seqan3::field::ref_seq. It will not be available in the record.");
528 "You selected the deprecated seqan3::field::evalue. It will not be available in the record.");
530 "You selected the deprecated seqan3::field::bit_score. It will not be available in the record.");
533 static_assert([] () constexpr
535 for (
field f : selected_field_ids::as_array)
536 if (!field_ids::contains(f))
540 "You selected a field that is not valid for alignment files, please refer to the documentation "
541 "of sam_file_input::field_ids for the accepted values.");
563 using iterator = detail::in_file_iterator<sam_file_input>;
629 template <input_stream stream_t, sam_file_input_format file_format>
631 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type,
stream_char_type>
634 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
636 primary_stream{&stream, stream_deleter_noop}
638 init_by_format<file_format>();
642 template <input_stream stream_t, sam_file_input_format file_format>
644 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type,
stream_char_type>
647 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
649 primary_stream{
new stream_t{
std::move(stream)}, stream_deleter_default}
651 init_by_format<file_format>();
678 typename traits_type::ref_ids & ref_ids,
679 typename traits_type::ref_sequences & ref_sequences,
684 set_references(ref_ids, ref_sequences);
714 template <input_stream stream_t, sam_file_input_format file_format>
716 typename traits_type::ref_ids & ref_ids,
717 typename traits_type::ref_sequences & ref_sequences,
718 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
720 primary_stream{&stream, stream_deleter_noop}
723 set_references(ref_ids, ref_sequences);
725 init_by_format<file_format>();
729 template <input_stream stream_t, sam_file_input_format file_format>
731 typename traits_type::ref_ids & ref_ids,
732 typename traits_type::ref_sequences & ref_sequences,
733 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
735 primary_stream{
new stream_t{
std::move(stream)}, stream_deleter_default}
738 set_references(ref_ids, ref_sequences);
740 init_by_format<file_format>();
746 typename traits_type::ref_ids &&,
747 typename traits_type::ref_sequences &&,
750 template <input_stream stream_t, sam_file_input_format file_format>
752 typename traits_type::ref_ids &&,
753 typename traits_type::ref_sequences &&,
782 if (!first_record_was_read)
785 first_record_was_read =
true;
856 if (!first_record_was_read)
859 first_record_was_read =
true;
871 primary_stream->rdbuf()->pubsetbuf(stream_buffer.
data(), stream_buffer.
size());
873 std::ios_base::in | std::ios::binary);
875 if (!primary_stream->good())
878 secondary_stream = detail::make_secondary_istream(*primary_stream, filename);
879 detail::set_format(format, filename);
883 template <
typename format_type>
884 void init_by_format()
886 static_assert(list_traits::contains<format_type, valid_formats>,
887 "You selected a format that is not in the valid_formats of this file.");
889 format = detail::sam_file_input_format_exposer<format_type>{};
890 secondary_stream = detail::make_secondary_istream(*primary_stream);
917 stream_ptr_t primary_stream{
nullptr, stream_deleter_noop};
919 stream_ptr_t secondary_stream{
nullptr, stream_deleter_noop};
922 bool first_record_was_read{
false};
927 using format_type =
typename detail::variant_from_tags<
valid_formats,
928 detail::sam_file_input_format_exposer>::type;
938 typename traits_type::ref_sequences
const * reference_sequences_ptr{
nullptr};
950 template <std::ranges::forward_range ref_sequences_t>
951 void set_references(
typename traits_type::ref_ids & ref_ids, ref_sequences_t && ref_sequences)
953 assert(std::ranges::distance(ref_ids) == std::ranges::distance(ref_sequences));
956 reference_sequences_ptr = &ref_sequences;
959 for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
961 header_ptr->ref_id_info.emplace_back(std::ranges::distance(ref_sequences[idx]),
"");
963 if constexpr (std::ranges::contiguous_range<std::ranges::range_reference_t<
964 typename traits_type::ref_ids>> &&
965 std::ranges::sized_range<std::ranges::range_reference_t<typename traits_type::ref_ids>> &&
966 std::ranges::borrowed_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>)
968 auto &&
id = header_ptr->ref_ids()[idx];
973 header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
980 void read_next_record()
983 record_buffer.clear();
984 detail::get_or_ignore<field::header_ptr>(record_buffer) = header_ptr.get();
994 auto call_read_func = [
this] (
auto & ref_seq_info)
998 f.read_alignment_record(*secondary_stream,
1002 detail::get_or_ignore<field::seq>(record_buffer),
1003 detail::get_or_ignore<field::qual>(record_buffer),
1004 detail::get_or_ignore<field::id>(record_buffer),
1005 detail::get_or_ignore<field::offset>(record_buffer),
1006 detail::get_or_ignore<field::ref_seq>(record_buffer),
1007 detail::get_or_ignore<field::ref_id>(record_buffer),
1008 detail::get_or_ignore<field::ref_offset>(record_buffer),
1009 detail::get_or_ignore<field::alignment>(record_buffer),
1010 detail::get_or_ignore<field::cigar>(record_buffer),
1011 detail::get_or_ignore<field::flag>(record_buffer),
1012 detail::get_or_ignore<field::mapq>(record_buffer),
1013 detail::get_or_ignore<field::mate>(record_buffer),
1014 detail::get_or_ignore<field::tags>(record_buffer),
1015 detail::get_or_ignore<field::evalue>(record_buffer),
1016 detail::get_or_ignore<field::bit_score>(record_buffer));
1020 assert(!
format.valueless_by_exception());
1022 if constexpr (!std::same_as<typename traits_type::ref_sequences, ref_info_not_given>)
1023 call_read_func(*reference_sequences_ptr);
1025 call_read_func(std::ignore);
1037 template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_
ids>
1044 template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_
ids>
1051 template <input_stream stream_type, sam_file_input_format file_format>
1058 template <input_stream stream_type, sam_file_input_format file_format>
1065 template <std::ranges::forward_range ref_ids_t,
1066 std::ranges::forward_range ref_sequences_t,
1075 template <std::ranges::forward_range ref_ids_t,
1076 std::ranges::forward_range ref_sequences_t>
1084 template <input_stream stream_type,
1085 std::ranges::forward_range ref_ids_t,
1086 std::ranges::forward_range ref_sequences_t,
1096 template <input_stream stream_type,
1097 std::ranges::forward_range ref_ids_t,
1098 std::ranges::forward_range ref_sequences_t,
1108 template <input_stream stream_type,
1109 std::ranges::forward_range ref_ids_t,
1110 std::ranges::forward_range ref_sequences_t,
1112 sam_file_input(stream_type && stream, ref_ids_t &, ref_sequences_t &, file_format
const &)
1119 template <input_stream stream_type,
1120 std::ranges::forward_range ref_ids_t,
1121 std::ranges::forward_range ref_sequences_t,
1123 sam_file_input(stream_type & stream, ref_ids_t &, ref_sequences_t &, file_format
const &)
Provides seqan3::aa27, container aliases and string literals.
Provides seqan3::gap_decorator.
Provides the seqan3::cigar alphabet.
Provides alphabet adaptations for standard char types.
A combined alphabet that can hold values of either of its alternatives.
Definition: alphabet_variant.hpp:131
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:51
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition: dna5.hpp:51
A gap decorator allows the annotation of sequences with gap symbols while leaving the underlying sequ...
Definition: gap_decorator.hpp:83
Quality type for traditional Sanger and modern Illumina Phred scores.
Definition: phred42.hpp:47
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:332
Provides seqan3::dna15, container aliases and string literals.
Provides seqan3::dna5, container aliases and string literals.
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition: sam_flag.hpp:73
field
An enumerator for the fields used in file formats.
Definition: record.hpp:63
@ flag
The alignment flag (bit information), uint16_t value.
@ ref_offset
Sequence (seqan3::field::ref_seq) relative start position (0-based), unsigned value.
@ ref_seq
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
@ mapq
The mapping quality of the seqan3::field::seq alignment, usually a Phred-scaled score.
@ bit_score
The bit score (statistical significance indicator), unsigned value.
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
@ mate
The mate pair information given as a std::tuple of reference name, offset and template length.
@ header_ptr
A pointer to the seqan3::sam_file_header object storing header information.
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
@ evalue
The e-value (length normalized bit score), double value.
@ id
The identifier, usually a string.
@ tags
The optional tags in the SAM format, stored in a dictionary.
@ seq
The "sequence", usually a range of nucleotides or amino acids.
@ qual
The qualities, usually in Phred score notation.
constexpr bool contains
Whether a type occurs in a type list or not.
Definition: traits.hpp:231
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition: traits.hpp:471
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:151
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:189
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:95
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:74
Provides the seqan3::detail::in_file_iterator class template.
The generic alphabet concept that covers most data types used in ranges.
Resolves to std::ranges::explicitly_convertible_to<type1, type2>(). <dl class="no-api">This entity i...
A more refined container concept than seqan3::container.
Refines seqan3::alphabet and adds assignability.
A concept that indicates whether a writable alphabet represents quality scores.
Provides exceptions used in the I/O module.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides seqan3::phred42 quality scores.
Provides quality alphabet composites.
Adaptations of concepts from the Ranges TS.
Provides seqan3::sam_record.
Provides helper data structures for the seqan3::sam_file_output.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:172
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem.
Definition: exception.hpp:40
Type that contains multiple types.
Definition: type_list.hpp:29
Provides seqan3::tuple_like.
Provides traits for seqan3::type_list.
Provides seqan3::views::repeat_n.
Provides seqan3::views::slice.