SeqAn3 3.1.0-rc.2
The Modern C++ library for sequence analysis.
input.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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 <seqan3/std/concepts>
17#include <seqan3/std/filesystem>
18#include <fstream>
19#include <seqan3/std/ranges>
20#include <string>
21#include <variant>
22#include <vector>
23
47
48namespace seqan3
49{
50
51// ---------------------------------------------------------------------------------------------------------------------
52// sam_file_input_traits
53// ---------------------------------------------------------------------------------------------------------------------
54
113template <typename t>
114SEQAN3_CONCEPT sam_file_input_traits = requires (t v)
115{
116 // field::seq
121
122 // field::id
124
125 // field::qual
128
129 // field::ref_seq
130 // either ref_info_not_given or a range over ranges over alphabet (e.g. std::vector<dna4_vector>)
131 requires std::same_as<typename t::ref_sequences, ref_info_not_given> || requires ()
132 {
134 };
135
136 // field::ref_id
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>;
142
143 // field::offset is fixed to int32_t
144 // field::ref_offset is fixed to std::optional<int32_t>
145 // field::flag is fixed to seqan3::sam_flag
146 // field::mapq is fixed to uint8_t
147 // field::evalue is fixed to double
148 // field::bitscore is fixed to double
149 // field::mate is fixed to std::tuple<ref_id_container<ref_id_alphabet>, ref_offset_type, int32_t>
150
151 // field::alignment
152 // the alignment type cannot be configured.
153 // Type of tuple entry 1 (reference) is set to
154 // 1) a std::ranges::subrange over std::ranges::range_value_t<typename t::ref_sequences> if reference information was given
155 // or 2) a "dummy" sequence type:
156 // views::repeat_n(sequence_alphabet{}, size_t{}) | std::views::transform(detail::access_restrictor_fn{})
157 // Type of tuple entry 2 (query) is set to
158 // 1) a std::ranges::subrange over std::ranges::range_value_t<typename t::ref_sequences> if reference information was given
159 // or 2) a "dummy" sequence type:
160};
162
163// ---------------------------------------------------------------------------------------------------------------------
164// sam_file_input_default_traits
165// ---------------------------------------------------------------------------------------------------------------------
166
182template <typename ref_sequences_t = ref_info_not_given, typename ref_ids_t = std::deque<std::string>>
184{
192
195
197 template <typename _sequence_alphabet>
199
201 template <typename _id_alphabet>
203
206
208 template <typename _quality_alphabet>
210
212 using ref_sequences = ref_sequences_t;
213
215 using ref_ids = ref_ids_t;
217};
218
219// ---------------------------------------------------------------------------------------------------------------------
220// sam_file_input
221// ---------------------------------------------------------------------------------------------------------------------
222
333template <
335 detail::fields_specialisation selected_field_ids_ = fields<field::seq,
336 field::id,
350{
351public:
357 using traits_type = traits_type_;
359 using selected_field_ids = selected_field_ids_;
361 using valid_formats = valid_formats_;
363 using stream_char_type = char;
365
366private:
368 using dummy_ref_type = decltype(views::repeat_n(typename traits_type::sequence_alphabet{}, size_t{}) |
369 std::views::transform(detail::access_restrictor_fn{}));
370
373 detail::lazy_conditional_t<std::ranges::range<typename traits_type::ref_sequences const>,
374 detail::lazy<std::ranges::range_reference_t,
375 typename traits_type::ref_sequences const>,
377
379 using ref_sequence_sliced_type = decltype(std::declval<ref_sequence_unsliced_type>() | views::slice(0, 0));
380public:
387 using sequence_type = typename traits_type::template sequence_container<
388 typename traits_type::sequence_alphabet>;
390 using id_type = typename traits_type::template id_container<char>;
392 using offset_type = int32_t;
418 using mapq_type = uint8_t;
420 using quality_type = typename traits_type::template quality_container<
421 typename traits_type::quality_alphabet>;
430
431private:
436 decltype(std::declval<sequence_type &>() | views::slice(0, 0))>,
437 typename traits_type::template sequence_container<
439
440public:
443
446 id_type,
452 mapq_type,
454 flag_type,
455 mate_type,
457 header_type *>;
458
481 field::id,
493
494 static_assert([] () constexpr
495 {
496 for (field f : selected_field_ids::as_array)
497 if (!field_ids::contains(f))
498 return false;
499 return true;
500 }(),
501 "You selected a field that is not valid for alignment files, please refer to the documentation "
502 "of sam_file_input::field_ids for the accepted values.");
503
508
518 using const_reference = void;
520 using size_type = size_t;
526 using const_iterator = void;
528 using sentinel = std::default_sentinel_t;
530
535 sam_file_input() = delete;
545 ~sam_file_input() = default;
546
565 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
567 {
568 init_by_filename(std::move(filename));
569 }
570
590 template <input_stream stream_t, sam_file_input_format file_format>
592 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
594 sam_file_input(stream_t & stream,
595 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
596 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
598 {
599 init_by_format<file_format>();
600 }
601
603 template <input_stream stream_t, sam_file_input_format file_format>
605 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
607 sam_file_input(stream_t && stream,
608 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
609 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
610 primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
611 {
612 init_by_format<file_format>();
613 }
614
639 typename traits_type::ref_ids & ref_ids,
640 typename traits_type::ref_sequences & ref_sequences,
641 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
643 {
644 // initialize reference information
645 set_references(ref_ids, ref_sequences);
646
647 init_by_filename(std::move(filename));
648 }
649
675 template <input_stream stream_t, sam_file_input_format file_format>
676 sam_file_input(stream_t & stream,
677 typename traits_type::ref_ids & ref_ids,
678 typename traits_type::ref_sequences & ref_sequences,
679 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
680 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
682 {
683 // initialize reference information
684 set_references(ref_ids, ref_sequences);
685
686 init_by_format<file_format>();
687 }
688
690 template <input_stream stream_t, sam_file_input_format file_format>
691 sam_file_input(stream_t && stream,
692 typename traits_type::ref_ids & ref_ids,
693 typename traits_type::ref_sequences & ref_sequences,
694 file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
695 selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
696 primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
697 {
698 // initialize reference information
699 set_references(ref_ids, ref_sequences);
700
701 init_by_format<file_format>();
702 }
703
705 // explicitly delete rvalues for reference information
707 typename traits_type::ref_ids &&,
708 typename traits_type::ref_sequences &&,
709 selected_field_ids const &) = delete;
710
711 template <input_stream stream_t, sam_file_input_format file_format>
712 sam_file_input(stream_t &&,
713 typename traits_type::ref_ids &&,
714 typename traits_type::ref_sequences &&,
715 file_format const &,
716 selected_field_ids const &) = delete;
719
741 {
742 // buffer first record
744 {
747 }
748
749 return {*this};
750 }
751
765 sentinel end() noexcept
766 {
767 return {};
768 }
769
793 reference front() noexcept
794 {
795 return *begin();
796 }
798
801
815 {
816 // make sure header is read
818 {
821 }
822
823 return *header_ptr;
824 }
825
826protected:
828
831 {
832 primary_stream->rdbuf()->pubsetbuf(stream_buffer.data(), stream_buffer.size());
833 static_cast<std::basic_ifstream<char> *>(primary_stream.get())->open(filename,
834 std::ios_base::in | std::ios::binary);
835 // open stream
836 if (!primary_stream->good())
837 throw file_open_error{"Could not open file " + filename.string() + " for reading."};
838
840 detail::set_format(format, filename);
841 }
842
844 template <typename format_type>
846 {
847 static_assert(list_traits::contains<format_type, valid_formats>,
848 "You selected a format that is not in the valid_formats of this file.");
849
852 }
853
856
865
876
881
885 bool at_end{false};
886
890
894
899 typename traits_type::ref_sequences const * reference_sequences_ptr{nullptr};
900
911 template <std::ranges::forward_range ref_sequences_t>
912 void set_references(typename traits_type::ref_ids & ref_ids, ref_sequences_t && ref_sequences)
913 {
914 assert(std::ranges::distance(ref_ids) == std::ranges::distance(ref_sequences));
915
916 header_ptr = std::unique_ptr<header_type>{std::make_unique<header_type>(ref_ids)};
917 reference_sequences_ptr = &ref_sequences;
918
919 // initialise reference map and ref_dict if ref_ids are non-empty
920 for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
921 {
922 header_ptr->ref_id_info.emplace_back(std::ranges::distance(ref_sequences[idx]), "");
923
924 if constexpr (std::ranges::contiguous_range<std::ranges::range_reference_t<
925 typename traits_type::ref_ids>> &&
926 std::ranges::sized_range<std::ranges::range_reference_t<typename traits_type::ref_ids>> &&
927 std::ranges::borrowed_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>)
928 {
929 auto && id = header_ptr->ref_ids()[idx];
930 header_ptr->ref_dict[std::span{std::ranges::data(id), std::ranges::size(id)}] = idx;
931 }
932 else
933 {
934 header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
935 }
936 }
937 }
939
942 {
943 // clear the record
945 detail::get_or_ignore<field::header_ptr>(record_buffer) = header_ptr.get();
946
947 // at end if we could not read further
950 {
951 at_end = true;
952 return;
953 }
954
955 auto call_read_func = [this] (auto & ref_seq_info)
956 {
957 std::visit([&] (auto & f)
958 {
959 f.read_alignment_record(*secondary_stream,
960 options,
961 ref_seq_info,
962 *header_ptr,
963 detail::get_or_ignore<field::seq>(record_buffer),
964 detail::get_or_ignore<field::qual>(record_buffer),
965 detail::get_or_ignore<field::id>(record_buffer),
966 detail::get_or_ignore<field::offset>(record_buffer),
967 detail::get_or_ignore<field::ref_seq>(record_buffer),
968 detail::get_or_ignore<field::ref_id>(record_buffer),
969 detail::get_or_ignore<field::ref_offset>(record_buffer),
970 detail::get_or_ignore<field::alignment>(record_buffer),
971 detail::get_or_ignore<field::cigar>(record_buffer),
972 detail::get_or_ignore<field::flag>(record_buffer),
973 detail::get_or_ignore<field::mapq>(record_buffer),
974 detail::get_or_ignore<field::mate>(record_buffer),
975 detail::get_or_ignore<field::tags>(record_buffer),
976 detail::get_or_ignore<field::evalue>(record_buffer),
977 detail::get_or_ignore<field::bit_score>(record_buffer));
978 }, format);
979 };
980
981 assert(!format.valueless_by_exception());
982
983 if constexpr (!std::same_as<typename traits_type::ref_sequences, ref_info_not_given>)
984 call_read_func(*reference_sequences_ptr);
985 else
986 call_read_func(std::ignore);
987 }
988
990 friend iterator;
991};
992
998template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_ids>
999sam_file_input(stream_type && stream, file_format const &, selected_field_ids const &)
1000 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
1003
1005template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_ids>
1006sam_file_input(stream_type & stream, file_format const &, selected_field_ids const &)
1007 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
1010
1012template <input_stream stream_type, sam_file_input_format file_format>
1013sam_file_input(stream_type && stream, file_format const &)
1014 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
1015 typename sam_file_input<>::selected_field_ids, // actually use the default
1017
1019template <input_stream stream_type, sam_file_input_format file_format>
1020sam_file_input(stream_type & stream, file_format const &)
1021 -> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
1022 typename sam_file_input<>::selected_field_ids, // actually use the default
1024
1026template <std::ranges::forward_range ref_ids_t,
1027 std::ranges::forward_range ref_sequences_t,
1029sam_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &, selected_field_ids const &)
1033 typename sam_file_input<>::valid_formats>; // actually use the default
1034
1036template <std::ranges::forward_range ref_ids_t,
1037 std::ranges::forward_range ref_sequences_t>
1038sam_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &)
1041 typename sam_file_input<>::selected_field_ids, // actually use the default
1042 typename sam_file_input<>::valid_formats>; // actually use the default
1043
1045template <input_stream stream_type,
1046 std::ranges::forward_range ref_ids_t,
1047 std::ranges::forward_range ref_sequences_t,
1048 sam_file_input_format file_format,
1050sam_file_input(stream_type && stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &)
1055
1057template <input_stream stream_type,
1058 std::ranges::forward_range ref_ids_t,
1059 std::ranges::forward_range ref_sequences_t,
1060 sam_file_input_format file_format,
1062sam_file_input(stream_type & stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &)
1067
1069template <input_stream stream_type,
1070 std::ranges::forward_range ref_ids_t,
1071 std::ranges::forward_range ref_sequences_t,
1072 sam_file_input_format file_format>
1073sam_file_input(stream_type && stream, ref_ids_t &, ref_sequences_t &, file_format const &)
1076 typename sam_file_input<>::selected_field_ids, // actually use the default
1078
1080template <input_stream stream_type,
1081 std::ranges::forward_range ref_ids_t,
1082 std::ranges::forward_range ref_sequences_t,
1083 sam_file_input_format file_format>
1084sam_file_input(stream_type & stream, ref_ids_t &, ref_sequences_t &, file_format const &)
1087 typename sam_file_input<>::selected_field_ids, // actually use the default
1090
1091} // namespace seqan3
Provides seqan3::aa27, container aliases and string literals.
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
Input iterator necessary for providing a range-like interface in input file.
Definition: in_file_iterator.hpp:41
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
Stores the header information of alignment files.
Definition: header.hpp:32
A class for reading alignment files, e.g. SAM, BAM, BLAST ...
Definition: input.hpp:350
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: input.hpp:765
size_t size_type
An unsigned integer type, usually std::size_t.
Definition: input.hpp:520
std::optional< int32_t > ref_id_type
The type of field::ref_id is fixed to std::optional<int32_t>.
Definition: input.hpp:409
void set_references(typename traits_type::ref_ids &ref_ids, ref_sequences_t &&ref_sequences)
Updates the reference information members and the header.
Definition: input.hpp:912
void const_reference
The const_reference type is void because files are not const-iterable.
Definition: input.hpp:518
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.
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: input.hpp:594
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: input.hpp:361
decltype(views::repeat_n(typename traits_type::sequence_alphabet{}, size_t{})|std::views::transform(detail::access_restrictor_fn{})) dummy_ref_type
The dummy ref sequence type if no reference information were given.
Definition: input.hpp:369
char stream_char_type
Character type of the stream(s).
Definition: input.hpp:363
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.
typename traits_type::template sequence_container< typename traits_type::sequence_alphabet > sequence_type
The type of field::seq (default std::vector<seqan3::dna5>).
Definition: input.hpp:388
sam_file_input(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: input.hpp:564
bool at_end
File is one position behind the last record.
Definition: input.hpp:885
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: input.hpp:528
void read_next_record()
Tell the format to move to the next record and update the buffer.
Definition: input.hpp:941
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: input.hpp:676
std::vector< char > stream_buffer
A larger (compared to stl default) stream buffer to use when reading from a file.
Definition: input.hpp:863
stream_ptr_t primary_stream
The primary stream is the user provided stream or the file stream if constructed from filename.
Definition: input.hpp:878
format_type format
The actual std::variant holding a pointer to the detected/selected format.
Definition: input.hpp:892
std::optional< int32_t > ref_offset_type
The type of field::ref_offset is fixed to an std::optional<int32_t>.
Definition: input.hpp:416
traits_type_ traits_type
A traits type that defines aliases and template for storage of the fields.
Definition: input.hpp:357
int32_t offset_type
The type of field::offset is fixed to int32_t.
Definition: input.hpp:392
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: input.hpp:800
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.
static void stream_deleter_noop(std::basic_istream< stream_char_type > *)
Stream deleter that does nothing (no ownership assumed).
Definition: input.hpp:873
detail::lazy_conditional_t< std::ranges::range< typename traits_type::ref_sequences const >, detail::lazy< std::ranges::range_reference_t, typename traits_type::ref_sequences const >, dummy_ref_type > ref_sequence_unsliced_type
The unsliced ref sequence type if reference information were given.
Definition: input.hpp:376
typename traits_type::template id_container< char > id_type
The type of field::id (default std::string by default).
Definition: input.hpp:390
sam_file_input & operator=(sam_file_input &&)=default
Move assignment is defaulted.
friend iterator
Befriend iterator so it can access the buffers.
Definition: input.hpp:990
stream_ptr_t secondary_stream
The secondary stream is a compression layer on the primary or just points to the primary (no compress...
Definition: input.hpp:880
typename traits_type::template quality_container< typename traits_type::quality_alphabet > quality_type
The type of field::qual (default std::vector<seqan3::phred42>).
Definition: input.hpp:421
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: input.hpp:691
std::tuple< gap_decorator< ref_sequence_type >, alignment_query_type > alignment_type
The type of field::alignment (default: std::pair<std::vector<gapped<dna5>>, std::vector<gapped<dna5>>...
Definition: input.hpp:442
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: input.hpp:506
typename detail::variant_from_tags< valid_formats, detail::sam_file_input_format_exposer >::type format_type
Type of the format, an std::variant over the valid_formats.
Definition: input.hpp:889
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: input.hpp:740
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: input.hpp:359
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.
bool first_record_was_read
Tracks whether the very first record is buffered when calling begin().
Definition: input.hpp:883
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: input.hpp:638
sam_file_input & operator=(sam_file_input const &)=delete
Copy assignment is explicitly deleted because you cannot have multiple access to the same file.
record_type record_buffer
Buffer for a single record.
Definition: input.hpp:861
sam_file_input(sam_file_input &&)=default
Move construction is defaulted.
void init_by_format()
/brief Initialisation based on a format (construction via stream).
Definition: input.hpp:845
void const_iterator
The const iterator type is void because files are not const-iterable.
Definition: input.hpp:526
std::unique_ptr< header_type > header_ptr
The file header object.
Definition: input.hpp:855
header_type & header()
Access the file's header.
Definition: input.hpp:814
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: input.hpp:418
sam_flag flag_type
The type of field::flag is fixed to seqan3::sam_flag.
Definition: input.hpp:423
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: input.hpp:607
decltype(std::declval< ref_sequence_unsliced_type >()|views::slice(0, 0)) ref_sequence_sliced_type
The ref sequence type if reference information were given.
Definition: input.hpp:379
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_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.
static void stream_deleter_default(std::basic_istream< stream_char_type > *ptr)
Stream deleter with default behaviour (ownership assumed).
Definition: input.hpp:875
~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: input.hpp:427
void init_by_filename(std::filesystem::path filename)
Definition: input.hpp:830
reference front() noexcept
Return the record we are currently at in the file.
Definition: input.hpp:793
traits_type::ref_sequences const * reference_sequences_ptr
A pointer to the reference sequence information if given on construction.
Definition: input.hpp:899
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:334
The Concepts library.
Provides auxiliary data structures and functions for seqan3::record and seqan3::fields.
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...
Provides the seqan3::format_bam.
Provides the seqan3::format_sam.
Provides seqan3::gap_decorator.
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:74
SEQAN3_CONCEPT type_list_of_sam_file_input_formats
Auxiliary concept that checks whether a type is a seqan3::type_list and all types meet seqan3::sam_fi...
Definition: input_format_concept.hpp:246
field
An enumerator for the fields used in file formats.
Definition: record.hpp:63
void set_format(format_variant_type &format, std::filesystem::path const &file_name)
Sets the file format according to the file name extension.
Definition: misc.hpp:67
auto make_secondary_istream(std::basic_istream< char_t > &primary_stream, std::filesystem::path &filename) -> std::unique_ptr< std::basic_istream< char_t >, std::function< void(std::basic_istream< char_t > *)> >
Depending on the magic bytes of the given stream, return a decompression stream or forward the primar...
Definition: misc_input.hpp:81
SEQAN3_CONCEPT fields_specialisation
Auxiliary concept that checks whether a type is a specialisation of seqan3::fields.
Definition: record.hpp:35
@ 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: 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:183
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.
Resolves to std::ranges::explicitly_convertible_to<type1, type2>(). <dl class="no-api">This entity i...
The generic concept for alignment file input formats.
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: cigar_operation_table.hpp:2
Provides seqan3::phred42 quality scores.
Provides quality alphabet composites.
Adaptations of concepts from the Ranges TS.
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.
Provides seqan3::views::slice.
An empty type whose only purpose is to hold an uninstantiated template plus its arguments.
Definition: lazy_conditional.hpp:33
Internal class used to expose the actual format interface to read alignment records from the file.
Definition: input_format_concept.hpp:46
Base class to deduce the std::variant type from format tags.
Definition: misc.hpp:30
A class template that holds a choice of seqan3::field.
Definition: record.hpp:128
static constexpr bool contains(field f)
Whether a field is contained in the parameter pack.
Definition: record.hpp:149
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem.
Definition: exception.hpp:39
void clear() noexcept(noexcept(std::apply(expander, std::declval< record & >())))
Clears containers that provide .clear() and (re-)initialises all other elements with = {}.
Definition: record.hpp:235
The default traits for seqan3::sam_file_input.
Definition: input.hpp:184
ref_ids_t ref_ids
The type of the reference identifiers is deduced on construction.
Definition: input.hpp:215
ref_sequences_t ref_sequences
The type of the reference sequences is deduced on construction.
Definition: input.hpp:212
The options type defines various option members that influence the behaviour of all or some formats.
Definition: input_options.hpp:24
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)