SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
sam_file/input.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <cassert>
16#include <concepts>
17#include <filesystem>
18#include <fstream>
19#include <ranges>
20#include <string>
21#include <variant>
22#include <vector>
23
33#include <seqan3/io/detail/record.hpp>
46
47namespace seqan3
48{
49
50// ---------------------------------------------------------------------------------------------------------------------
51// sam_file_input_traits
52// ---------------------------------------------------------------------------------------------------------------------
53
112template <typename t>
113concept sam_file_input_traits =
114 requires (t v) {
115 // field::seq
120
121 // field::id
123
124 // field::qual
127
128 // field::ref_seq
129 // either ref_info_not_given or a range over ranges over alphabet (e.g. std::vector<dna4_vector>)
130 requires std::same_as<typename t::ref_sequences, ref_info_not_given>
131 || requires () {
132 requires alphabet<std::ranges::range_reference_t<
133 std::ranges::range_reference_t<typename t::ref_sequences>>>;
134 };
135
136 // field::ref_id
138 && (!std::same_as<typename t::ref_sequences, ref_info_not_given>
140 std::ranges::range_reference_t<std::ranges::range_reference_t<typename t::ref_ids>>>);
141 requires std::ranges::forward_range<std::ranges::range_reference_t<typename t::ref_ids>>;
142 requires std::ranges::forward_range<typename t::ref_ids>;
143
144 // field::offset is fixed to int32_t
145 // field::ref_offset is fixed to std::optional<int32_t>
146 // field::flag is fixed to seqan3::sam_flag
147 // field::mapq is fixed to uint8_t
148 // field::evalue is fixed to double
149 // field::bitscore is fixed to double
150 // field::mate is fixed to std::tuple<ref_id_container<ref_id_alphabet>, ref_offset_type, int32_t>
151 };
153
154// ---------------------------------------------------------------------------------------------------------------------
155// sam_file_input_default_traits
156// ---------------------------------------------------------------------------------------------------------------------
157
173template <typename ref_sequences_t = ref_info_not_given, typename ref_ids_t = std::deque<std::string>>
175{
183
186
188 template <typename _sequence_alphabet>
190
192 template <typename _id_alphabet>
194
197
199 template <typename _quality_alphabet>
201
203 using ref_sequences = ref_sequences_t;
204
206 using ref_ids = ref_ids_t;
208};
209
210// ---------------------------------------------------------------------------------------------------------------------
211// sam_file_input
212// ---------------------------------------------------------------------------------------------------------------------
213
229template <sam_file_input_traits traits_type_ = sam_file_input_default_traits<>,
230 detail::fields_specialisation selected_field_ids_ = fields<field::seq,
231 field::id,
232 field::offset,
233 field::ref_id,
234 field::ref_offset,
235 field::cigar,
236 field::mapq,
237 field::qual,
238 field::flag,
239 field::mate,
240 field::tags,
241 field::header_ptr>,
242 detail::type_list_of_sam_file_input_formats valid_formats_ = type_list<format_sam, format_bam>>
244{
245public:
251 using traits_type = traits_type_;
253 using selected_field_ids = selected_field_ids_;
255 using valid_formats = valid_formats_;
257 using stream_char_type = char;
259
260private:
262 using dummy_ref_type = decltype(views::repeat_n(typename traits_type::sequence_alphabet{}, size_t{})
263 | std::views::transform(detail::access_restrictor_fn{}));
264
266 using ref_sequence_unsliced_type = detail::lazy_conditional_t<
267 std::ranges::range<typename traits_type::ref_sequences const>,
268 detail::lazy<std::ranges::range_reference_t, typename traits_type::ref_sequences const>,
269 dummy_ref_type>;
270
272 using ref_sequence_sliced_type = decltype(std::declval<ref_sequence_unsliced_type>() | views::slice(0, 0));
273
274public:
283 using id_type = typename traits_type::template id_container<char>;
285 using offset_type = int32_t;
293 dummy_ref_type,
294 ref_sequence_sliced_type>;
311 using mapq_type = uint8_t;
313 using quality_type = typename traits_type::template quality_container<typename traits_type::quality_alphabet>;
322
323public:
326 id_type,
331 mapq_type,
333 flag_type,
334 mate_type,
336 header_type *>;
337
359 field::id,
370
372 "The field::alignment is deprecated and only field::cigar is supported. Please see "
373 "seqan3::alignment_from_cigar on how to get an alignment from the cigar information.");
374
375 static_assert(
376 []() constexpr
377 {
378 for (field f : selected_field_ids::as_array)
379 if (!field_ids::contains(f))
380 return false;
381 return true;
382 }(),
383 "You selected a field that is not valid for SAM files, please refer to the documentation "
384 "of sam_file_input::field_ids for the accepted values.");
385
390
400 using const_reference = void;
402 using size_type = size_t;
406 using iterator = detail::in_file_iterator<sam_file_input>;
408 using const_iterator = void;
410 using sentinel = std::default_sentinel_t;
412
417 sam_file_input() = delete;
427 ~sam_file_input() = default;
428
447 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
448 primary_stream{new std::ifstream{}, stream_deleter_default}
449 {
450 init_by_filename(std::move(filename));
451 }
452
472 template <input_stream stream_t, sam_file_input_format file_format>
473 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
474 sam_file_input(stream_t & stream,
475 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
476 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
477 primary_stream{&stream, stream_deleter_noop}
478 {
479 init_by_format<file_format>();
480 }
481
483 template <input_stream stream_t, sam_file_input_format file_format>
484 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
485 sam_file_input(stream_t && stream,
486 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
487 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
488 primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
489 {
490 init_by_format<file_format>();
491 }
492
517 typename traits_type::ref_ids & ref_ids,
518 typename traits_type::ref_sequences & ref_sequences,
519 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
520 primary_stream{new std::ifstream{}, stream_deleter_default}
521 {
522 // initialize reference information
523 set_references(ref_ids, ref_sequences);
524
525 init_by_filename(std::move(filename));
526 }
527
553 template <input_stream stream_t, sam_file_input_format file_format>
554 sam_file_input(stream_t & stream,
555 typename traits_type::ref_ids & ref_ids,
556 typename traits_type::ref_sequences & ref_sequences,
557 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
558 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
559 primary_stream{&stream, stream_deleter_noop}
560 {
561 // initialize reference information
562 set_references(ref_ids, ref_sequences);
563
564 init_by_format<file_format>();
565 }
566
568 template <input_stream stream_t, sam_file_input_format file_format>
569 sam_file_input(stream_t && stream,
570 typename traits_type::ref_ids & ref_ids,
571 typename traits_type::ref_sequences & ref_sequences,
572 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
573 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
574 primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
575 {
576 // initialize reference information
577 set_references(ref_ids, ref_sequences);
578
579 init_by_format<file_format>();
580 }
581
583 // explicitly delete rvalues for reference information
585 typename traits_type::ref_ids &&,
586 typename traits_type::ref_sequences &&,
587 selected_field_ids const &) = delete;
588
589 template <input_stream stream_t, sam_file_input_format file_format>
590 sam_file_input(stream_t &&,
591 typename traits_type::ref_ids &&,
592 typename traits_type::ref_sequences &&,
593 file_format const &,
594 selected_field_ids const &) = delete;
597
619 {
620 // buffer first record
621 if (!first_record_was_read)
622 {
623 read_next_record();
624 first_record_was_read = true;
625 }
626
627 return {*this};
628 }
629
643 sentinel end() noexcept
644 {
645 return {};
646 }
647
671 reference front() noexcept
672 {
673 return *begin();
674 }
676
679
693 {
694 // make sure header is read
695 if (!first_record_was_read)
696 {
697 read_next_record();
698 first_record_was_read = true;
699 }
700
701 return *header_ptr;
702 }
703
704protected:
706
708 void init_by_filename(std::filesystem::path filename)
709 {
710 primary_stream->rdbuf()->pubsetbuf(stream_buffer.data(), stream_buffer.size());
711 static_cast<std::basic_ifstream<char> *>(primary_stream.get())
712 ->open(filename, std::ios_base::in | std::ios::binary);
713 // open stream
714 if (!primary_stream->good())
715 throw file_open_error{"Could not open file " + filename.string() + " for reading."};
716
717 secondary_stream = detail::make_secondary_istream(*primary_stream, filename);
718 detail::set_format(format, filename);
719 }
720
722 template <typename format_type>
723 void init_by_format()
724 {
725 static_assert(list_traits::contains<format_type, valid_formats>,
726 "You selected a format that is not in the valid_formats of this file.");
727
728 format = detail::sam_file_input_format_exposer<format_type>{};
729 secondary_stream = detail::make_secondary_istream(*primary_stream);
730 }
731
734
739 record_type record_buffer;
741 std::vector<char> stream_buffer{std::vector<char>(1'000'000)};
743 std::streampos position_buffer{};
745
753 static void stream_deleter_noop(std::basic_istream<stream_char_type> *)
754 {}
756 static void stream_deleter_default(std::basic_istream<stream_char_type> * ptr)
757 {
758 delete ptr;
759 }
760
762 stream_ptr_t primary_stream{nullptr, stream_deleter_noop};
764 stream_ptr_t secondary_stream{nullptr, stream_deleter_noop};
765
767 bool first_record_was_read{false};
769 bool at_end{false};
770
772 using format_type = typename detail::variant_from_tags<valid_formats, detail::sam_file_input_format_exposer>::type;
773
775 format_type format;
777
782 typename traits_type::ref_sequences const * reference_sequences_ptr{nullptr};
783
794 template <std::ranges::forward_range ref_sequences_t>
795 void set_references(typename traits_type::ref_ids & ref_ids, ref_sequences_t && ref_sequences)
796 {
797 assert(std::ranges::distance(ref_ids) == std::ranges::distance(ref_sequences));
798
799 header_ptr = std::unique_ptr<header_type>{std::make_unique<header_type>(ref_ids)};
800 reference_sequences_ptr = &ref_sequences;
801
802 // initialise reference map and ref_dict if ref_ids are non-empty
803 for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
804 {
805 header_ptr->ref_id_info.emplace_back(std::ranges::distance(ref_sequences[idx]), "");
806
807 if constexpr (std::ranges::contiguous_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>
808 && std::ranges::sized_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>
809 && std::ranges::borrowed_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>)
810 {
811 auto && id = header_ptr->ref_ids()[idx];
812 header_ptr->ref_dict[std::span{std::ranges::data(id), std::ranges::size(id)}] = idx;
813 }
814 else
815 {
816 header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
817 }
818 }
819 }
821
823 void read_next_record()
824 {
825 // clear the record
826 record_buffer.clear();
827 detail::get_or_ignore<field::header_ptr>(record_buffer) = header_ptr.get();
828
829 // at end if we could not read further
830 if (std::istreambuf_iterator<stream_char_type>{*secondary_stream}
832 {
833 at_end = true;
834 return;
835 }
836
837 auto call_read_func = [this](auto & ref_seq_info)
838 {
840 [&](auto & f)
841 {
842 f.read_alignment_record(*secondary_stream,
843 options,
844 ref_seq_info,
845 *header_ptr,
846 position_buffer,
847 detail::get_or_ignore<field::seq>(record_buffer),
848 detail::get_or_ignore<field::qual>(record_buffer),
849 detail::get_or_ignore<field::id>(record_buffer),
850 detail::get_or_ignore<field::offset>(record_buffer),
851 detail::get_or_ignore<field::ref_seq>(record_buffer),
852 detail::get_or_ignore<field::ref_id>(record_buffer),
853 detail::get_or_ignore<field::ref_offset>(record_buffer),
854 detail::get_or_ignore<field::cigar>(record_buffer),
855 detail::get_or_ignore<field::flag>(record_buffer),
856 detail::get_or_ignore<field::mapq>(record_buffer),
857 detail::get_or_ignore<field::mate>(record_buffer),
858 detail::get_or_ignore<field::tags>(record_buffer),
859 detail::get_or_ignore<field::evalue>(record_buffer),
860 detail::get_or_ignore<field::bit_score>(record_buffer));
861 },
862 format);
863 };
864
865 assert(!format.valueless_by_exception());
866
867 if constexpr (!std::same_as<typename traits_type::ref_sequences, ref_info_not_given>)
868 call_read_func(*reference_sequences_ptr);
869 else
870 call_read_func(std::ignore);
871 }
872
874 friend iterator;
875};
876
882template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_ids>
883sam_file_input(stream_type && stream, file_format const &, selected_field_ids const &)
884 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
887
889template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_ids>
890sam_file_input(stream_type & stream, file_format const &, selected_field_ids const &)
891 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
894
896template <input_stream stream_type, sam_file_input_format file_format>
897sam_file_input(stream_type && stream, file_format const &)
898 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
899 typename sam_file_input<>::selected_field_ids, // actually use the default
901
903template <input_stream stream_type, sam_file_input_format file_format>
904sam_file_input(stream_type & stream, file_format const &)
905 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
906 typename sam_file_input<>::selected_field_ids, // actually use the default
908
910template <std::ranges::forward_range ref_ids_t,
911 std::ranges::forward_range ref_sequences_t,
912 detail::fields_specialisation selected_field_ids>
913sam_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &, selected_field_ids const &)
917 typename sam_file_input<>::valid_formats>; // actually use the default
918
920template <std::ranges::forward_range ref_ids_t, std::ranges::forward_range ref_sequences_t>
921sam_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &) -> sam_file_input<
923 typename sam_file_input<>::selected_field_ids, // actually use the default
924 typename sam_file_input<>::valid_formats>; // actually use the default
925
927template <input_stream stream_type,
928 std::ranges::forward_range ref_ids_t,
929 std::ranges::forward_range ref_sequences_t,
930 sam_file_input_format file_format,
931 detail::fields_specialisation selected_field_ids>
932sam_file_input(stream_type && stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &)
937
939template <input_stream stream_type,
940 std::ranges::forward_range ref_ids_t,
941 std::ranges::forward_range ref_sequences_t,
942 sam_file_input_format file_format,
943 detail::fields_specialisation selected_field_ids>
944sam_file_input(stream_type & stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &)
949
951template <input_stream stream_type,
952 std::ranges::forward_range ref_ids_t,
953 std::ranges::forward_range ref_sequences_t,
954 sam_file_input_format file_format>
955sam_file_input(stream_type && stream, ref_ids_t &, ref_sequences_t &, file_format const &) -> sam_file_input<
957 typename sam_file_input<>::selected_field_ids, // actually use the default
959
961template <input_stream stream_type,
962 std::ranges::forward_range ref_ids_t,
963 std::ranges::forward_range ref_sequences_t,
964 sam_file_input_format file_format>
965sam_file_input(stream_type & stream, ref_ids_t &, ref_sequences_t &, file_format const &) -> sam_file_input<
967 typename sam_file_input<>::selected_field_ids, // actually use the default
970
971} // namespace seqan3
Provides seqan3::aa27, container aliases and string literals.
Provides the seqan3::cigar alphabet.
Provides alphabet adaptations for standard char types.
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
Quality type for traditional Sanger and modern Illumina Phred scores..
Definition: phred42.hpp:47
Stores the header information of alignment files.
Definition: header.hpp:34
The generic concept for alignment file input formats.
Definition: sam_file/input_format_concept.hpp:151
A class for reading SAM files, both SAM and its binary representation BAM are supported.
Definition: sam_file/input.hpp:244
sam_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &) -> sam_file_input< sam_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t > >, typename sam_file_input<>::selected_field_ids, typename sam_file_input<>::valid_formats >
Deduce ref_sequences_t and ref_ids_t, default the rest.
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: sam_file/input.hpp:643
size_t size_type
An unsigned integer type, usually std::size_t.
Definition: sam_file/input.hpp:402
std::optional< int32_t > ref_id_type
The type of field::ref_id is fixed to std::optional<int32_t>.
Definition: sam_file/input.hpp:302
void const_reference
The const_reference type is void because files are not const-iterable.
Definition: sam_file/input.hpp:400
sam_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &, selected_field_ids const &) -> sam_file_input< sam_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t > >, selected_field_ids, typename sam_file_input<>::valid_formats >
Deduce selected fields, ref_sequences_t and ref_ids_t, default the rest.
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: sam_file/input.hpp:255
char stream_char_type
Character type of the stream(s).
Definition: sam_file/input.hpp:257
detail::in_file_iterator< sam_file_input > iterator
The iterator type of this view (an input iterator).
Definition: sam_file/input.hpp:406
sam_file_input(stream_type &&stream, ref_ids_t &, ref_sequences_t &, file_format const &) -> sam_file_input< sam_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t > >, typename sam_file_input<>::selected_field_ids, type_list< file_format > >
Deduce ref_sequences_t and ref_ids_t, and file format.
sam_file_input(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: sam_file/input.hpp:446
sam_file_input(stream_type &stream, file_format const &) -> sam_file_input< typename sam_file_input<>::traits_type, typename sam_file_input<>::selected_field_ids, type_list< file_format > >
Deduce file_format, and default the rest.
std::default_sentinel_t sentinel
The type returned by end().
Definition: sam_file/input.hpp:410
sam_file_input(stream_t &stream, typename traits_type::ref_ids &ref_ids, typename traits_type::ref_sequences &ref_sequences, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from an existing stream and with specified format.
Definition: sam_file/input.hpp:554
typename traits_type::template sequence_container< typename traits_type::sequence_alphabet > sequence_type
The type of field::seq (default std::vector<seqan3::dna5>).
Definition: sam_file/input.hpp:281
std::optional< int32_t > ref_offset_type
The type of field::ref_offset is fixed to a std::optional<int32_t>.
Definition: sam_file/input.hpp:309
traits_type_ traits_type
A traits type that defines aliases and template for storage of the fields.
Definition: sam_file/input.hpp:251
int32_t offset_type
The type of field::offset is fixed to int32_t.
Definition: sam_file/input.hpp:285
sam_file_input(stream_type &stream, ref_ids_t &, ref_sequences_t &, file_format const &) -> sam_file_input< sam_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t > >, typename sam_file_input<>::selected_field_ids, type_list< file_format > >
Deduce selected fields, ref_sequences_t and ref_ids_t, and file format.
sam_file_input_options< typename traits_type::sequence_legal_alphabet > options
The options are public and its members can be set directly.
Definition: sam_file/input.hpp:678
sam_file_input(stream_type &&stream, file_format const &) -> sam_file_input< typename sam_file_input<>::traits_type, typename sam_file_input<>::selected_field_ids, type_list< file_format > >
Deduce file_format, and default the rest.
sam_file_input(stream_t &stream, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from an existing stream and with specified format.
Definition: sam_file/input.hpp:474
sam_file_header< typename traits_type::ref_ids > header_type
The type of field::header_ptr (default: sam_file_header<typename traits_type::ref_ids>).
Definition: sam_file/input.hpp:321
typename traits_type::template id_container< char > id_type
The type of field::id (default std::string by default).
Definition: sam_file/input.hpp:283
sam_file_input & operator=(sam_file_input &&)=default
Move assignment is defaulted.
sam_file_input(stream_t &&stream, typename traits_type::ref_ids &ref_ids, typename traits_type::ref_sequences &ref_sequences, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: sam_file/input.hpp:569
sam_record< detail::select_types_with_ids_t< field_types, field_ids, selected_field_ids >, selected_field_ids > record_type
The type of the record, a specialisation of seqan3::record; acts as a tuple of the selected field typ...
Definition: sam_file/input.hpp:388
sam_file_input()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
iterator begin()
Returns an iterator to current position in the file.
Definition: sam_file/input.hpp:618
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: sam_file/input.hpp:253
sam_file_input(stream_type &stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &) -> sam_file_input< sam_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t > >, selected_field_ids, type_list< file_format > >
Deduce selected fields, ref_sequences_t and ref_ids_t, and file format.
sam_file_input(std::filesystem::path filename, typename traits_type::ref_ids &ref_ids, typename traits_type::ref_sequences &ref_sequences, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename and given additional reference information.
Definition: sam_file/input.hpp:516
sam_file_input & operator=(sam_file_input const &)=delete
Copy assignment is explicitly deleted because you cannot have multiple access to the same file.
sam_file_input(sam_file_input &&)=default
Move construction is defaulted.
void const_iterator
The const iterator type is void because files are not const-iterable.
Definition: sam_file/input.hpp:408
header_type & header()
Access the file's header.
Definition: sam_file/input.hpp:692
sam_file_input(sam_file_input const &)=delete
Copy construction is explicitly deleted because you cannot have multiple access to the same file.
uint8_t mapq_type
The type of field::mapq is fixed to uint8_t.
Definition: sam_file/input.hpp:311
sam_flag flag_type
The type of field::flag is fixed to seqan3::sam_flag.
Definition: sam_file/input.hpp:315
sam_file_input(stream_type &&stream, file_format const &, selected_field_ids const &) -> sam_file_input< typename sam_file_input<>::traits_type, selected_field_ids, type_list< file_format > >
Deduce selected fields, file_format, and default the rest.
sam_file_input(stream_t &&stream, file_format const &format_tag, selected_field_ids const &fields_tag=selected_field_ids{})
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: sam_file/input.hpp:485
sam_file_input(stream_type &&stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &) -> sam_file_input< sam_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t > >, selected_field_ids, type_list< file_format > >
Deduce selected fields, ref_sequences_t and ref_ids_t, and file format.
~sam_file_input()=default
Destructor is defaulted.
std::tuple< ref_id_type, ref_offset_type, int32_t > mate_type
The type of field::mate is fixed to std::tuple<ref_id_type, ref_offset_type, int32_t>).
Definition: sam_file/input.hpp:319
reference front() noexcept
Return the record we are currently at in the file.
Definition: sam_file/input.hpp:671
typename traits_type::template quality_container< typename traits_type::quality_alphabet > quality_type
The type of field::qual (default std::vector<seqan3::phred42>).
Definition: sam_file/input.hpp:313
sam_file_input(stream_type &stream, file_format const &, selected_field_ids const &) -> sam_file_input< typename sam_file_input<>::traits_type, selected_field_ids, type_list< file_format > >
Deduce selected fields, file_format, and default the rest.
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:343
T data(T... args)
Provides seqan3::dna15, container aliases and string literals.
Provides seqan3::dna5, container aliases and string literals.
Provides the seqan3::format_bam.
Provides the seqan3::format_sam.
T format(T... args)
T get(T... args)
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition: sam_flag.hpp:76
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.
@ 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.
@ 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.
@ 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: type_list/traits.hpp:252
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: type_list/traits.hpp:470
constexpr size_t size
The size of a type pack.
Definition: type_pack/traits.hpp:146
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:178
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:91
Provides the seqan3::detail::in_file_iterator class template.
The generic alphabet concept that covers most data types used in ranges.
Checks whether from can be explicitly converted to to.
The requirements a traits_type for seqan3::sam_file_input must meet.
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.
Stream concepts.
Provides various utility functions required only for input.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides seqan3::phred42 quality scores.
Provides quality alphabet composites.
Provides seqan3::views::repeat_n.
Provides seqan3::sam_file_input_format and auxiliary classes.
Provides seqan3::sam_record.
Provides helper data structures for the seqan3::sam_file_output.
T size(T... args)
Provides seqan3::views::slice.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:128
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem.
Definition: io/exception.hpp:39
The default traits for seqan3::sam_file_input.
Definition: sam_file/input.hpp:175
ref_ids_t ref_ids
The type of the reference identifiers is deduced on construction.
Definition: sam_file/input.hpp:206
ref_sequences_t ref_sequences
The type of the reference sequences is deduced on construction.
Definition: sam_file/input.hpp:203
Type that contains multiple types.
Definition: type_list.hpp:29
Provides seqan3::detail::transformation_trait_or.
Provides traits for seqan3::type_list.
Provides seqan3::tuple_like.
T visit(T... args)