SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
input.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 <fstream>
17 #include <string>
18 #include <variant>
19 #include <vector>
20 
37 #include <seqan3/io/detail/record.hpp>
38 #include <seqan3/io/exception.hpp>
39 #include <seqan3/io/record.hpp>
44 #include <seqan3/std/concepts>
45 #include <seqan3/std/filesystem>
46 #include <seqan3/std/ranges>
47 
48 namespace seqan3
49 {
50 
51 // ---------------------------------------------------------------------------------------------------------------------
52 // alignment_file_input_traits
53 // ---------------------------------------------------------------------------------------------------------------------
54 
111 template <typename t>
114 SEQAN3_CONCEPT alignment_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 // alignment_file_input_default_traits
165 // ---------------------------------------------------------------------------------------------------------------------
166 
182 template <typename ref_sequences_t = ref_info_not_given, typename ref_ids_t = std::deque<std::string>>
184 {
190  using sequence_alphabet = dna5;
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 // alignment_file_input
221 // ---------------------------------------------------------------------------------------------------------------------
222 
333 template <
335  detail::fields_specialisation selected_field_ids_ = fields<field::seq,
336  field::id,
338  field::ref_seq,
339  field::ref_id,
340  field::ref_offset,
342  field::cigar,
343  field::mapq,
344  field::qual,
345  field::flag,
346  field::mate,
347  field::tags,
348  field::evalue,
349  field::bit_score,
351  detail::type_list_of_alignment_file_input_formats valid_formats_ = type_list<format_sam, format_bam>>
353 {
354 public:
359  using traits_type = traits_type_;
362  using selected_field_ids = selected_field_ids_;
364  using valid_formats = valid_formats_;
366  using stream_char_type = char;
368 
369 private:
371  using dummy_ref_type = decltype(views::repeat_n(typename traits_type::sequence_alphabet{}, size_t{}) |
372  std::views::transform(detail::access_restrictor_fn{}));
373 
375  using ref_sequence_unsliced_type =
376  detail::lazy_conditional_t<std::ranges::range<typename traits_type::ref_sequences const>,
377  detail::lazy<std::ranges::range_reference_t,
378  typename traits_type::ref_sequences const>,
379  dummy_ref_type>;
380 
382  using ref_sequence_sliced_type = decltype(std::declval<ref_sequence_unsliced_type>() | views::slice(0, 0));
383 public:
389  using sequence_type = typename traits_type::template sequence_container<
391  typename traits_type::sequence_alphabet>;
393  using id_type = typename traits_type::template id_container<char>;
395  using offset_type = int32_t;
403  dummy_ref_type,
404  ref_sequence_sliced_type>;
421  using mapq_type = uint8_t;
423  using quality_type = typename traits_type::template quality_container<
424  typename traits_type::quality_alphabet>;
432  using e_value_type = double;
434  using bitscore_type = double;
437 
438 private:
443  decltype(std::declval<sequence_type &>() | views::slice(0, 0))>,
444  typename traits_type::template sequence_container<
446 
447 public:
450 
453  id_type,
454  offset_type,
456  ref_id_type,
460  mapq_type,
461  quality_type,
462  flag_type,
463  mate_type,
465  e_value_type,
467  header_type *>;
468 
494  field::id,
496  field::ref_seq,
497  field::ref_id,
498  field::ref_offset,
500  field::cigar,
501  field::mapq,
502  field::qual,
503  field::flag,
504  field::mate,
505  field::tags,
506  field::evalue,
507  field::bit_score,
509 
510  static_assert([] () constexpr
511  {
512  for (field f : selected_field_ids::as_array)
513  if (!field_ids::contains(f))
514  return false;
515  return true;
516  }(),
517  "You selected a field that is not valid for aligment files, please refer to the documentation "
518  "of alignment_file_input::field_ids for the accepted values.");
519 
524 
529  using value_type = record_type;
534  using const_reference = void;
536  using size_type = size_t;
540  using iterator = detail::in_file_iterator<alignment_file_input>;
542  using const_iterator = void;
544  using sentinel = std::default_sentinel_t;
546 
550  alignment_file_input() = delete;
562 
581  selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
582  primary_stream{new std::ifstream{}, stream_deleter_default}
583  {
584  init_by_filename(std::move(filename));
585  }
586 
606  template <input_stream stream_t, alignment_file_input_format file_format>
608  requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
610  alignment_file_input(stream_t & stream,
611  file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
612  selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
613  primary_stream{&stream, stream_deleter_noop}
614  {
615  init_by_format<file_format>();
616  }
617 
619  template <input_stream stream_t, alignment_file_input_format file_format>
621  requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
623  alignment_file_input(stream_t && stream,
624  file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
625  selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
626  primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
627  {
628  init_by_format<file_format>();
629  }
630 
655  typename traits_type::ref_ids & ref_ids,
656  typename traits_type::ref_sequences & ref_sequences,
657  selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
658  primary_stream{new std::ifstream{}, stream_deleter_default}
659  {
660  // initialize reference information
661  set_references(ref_ids, ref_sequences);
662 
663  init_by_filename(std::move(filename));
664  }
665 
691  template <input_stream stream_t, alignment_file_input_format file_format>
692  alignment_file_input(stream_t & stream,
693  typename traits_type::ref_ids & ref_ids,
694  typename traits_type::ref_sequences & ref_sequences,
695  file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
696  selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
697  primary_stream{&stream, stream_deleter_noop}
698  {
699  // initialize reference information
700  set_references(ref_ids, ref_sequences);
701 
702  init_by_format<file_format>();
703  }
704 
706  template <input_stream stream_t, alignment_file_input_format file_format>
707  alignment_file_input(stream_t && stream,
708  typename traits_type::ref_ids & ref_ids,
709  typename traits_type::ref_sequences & ref_sequences,
710  file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
711  selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
712  primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
713  {
714  // initialize reference information
715  set_references(ref_ids, ref_sequences);
716 
717  init_by_format<file_format>();
718  }
719 
721  // explicitly delete rvalues for reference information
723  typename traits_type::ref_ids &&,
724  typename traits_type::ref_sequences &&,
725  selected_field_ids const &) = delete;
726 
727  template <input_stream stream_t, alignment_file_input_format file_format>
728  alignment_file_input(stream_t &&,
729  typename traits_type::ref_ids &&,
730  typename traits_type::ref_sequences &&,
731  file_format const &,
732  selected_field_ids const &) = delete;
735 
757  {
758  // buffer first record
759  if (!first_record_was_read)
760  {
761  read_next_record();
762  first_record_was_read = true;
763  }
764 
765  return {*this};
766  }
767 
781  sentinel end() noexcept
782  {
783  return {};
784  }
785 
809  reference front() noexcept
810  {
811  return *begin();
812  }
814 
817 
831  {
832  // make sure header is read
833  if (!first_record_was_read)
834  {
835  read_next_record();
836  first_record_was_read = true;
837  }
838 
839  return *header_ptr;
840  }
841 
842 protected:
844 
846  void init_by_filename(std::filesystem::path filename)
847  {
848  primary_stream->rdbuf()->pubsetbuf(stream_buffer.data(), stream_buffer.size());
849  static_cast<std::basic_ifstream<char> *>(primary_stream.get())->open(filename,
850  std::ios_base::in | std::ios::binary);
851  // open stream
852  if (!primary_stream->good())
853  throw file_open_error{"Could not open file " + filename.string() + " for reading."};
854 
855  secondary_stream = detail::make_secondary_istream(*primary_stream, filename);
856  detail::set_format(format, filename);
857  }
858 
860  template <typename format_type>
861  void init_by_format()
862  {
863  static_assert(list_traits::contains<format_type, valid_formats>,
864  "You selected a format that is not in the valid_formats of this file.");
865 
866  format = detail::alignment_file_input_format_exposer<format_type>{};
867  secondary_stream = detail::make_secondary_istream(*primary_stream);
868  }
869 
871  std::unique_ptr<header_type> header_ptr{new header_type{}};
872 
876  record_type record_buffer;
879  std::vector<char> stream_buffer{std::vector<char>(1'000'000)};
881 
889  static void stream_deleter_noop(std::basic_istream<stream_char_type> *) {}
891  static void stream_deleter_default(std::basic_istream<stream_char_type> * ptr) { delete ptr; }
892 
894  stream_ptr_t primary_stream{nullptr, stream_deleter_noop};
896  stream_ptr_t secondary_stream{nullptr, stream_deleter_noop};
897 
899  bool first_record_was_read{false};
901  bool at_end{false};
902 
904  using format_type = typename detail::variant_from_tags<valid_formats,
905  detail::alignment_file_input_format_exposer>::type;
906 
908  format_type format;
910 
914  typename traits_type::ref_sequences const * reference_sequences_ptr{nullptr};
916 
927  template <std::ranges::forward_range ref_sequences_t>
928  void set_references(typename traits_type::ref_ids & ref_ids, ref_sequences_t && ref_sequences)
929  {
930  assert(std::ranges::distance(ref_ids) == std::ranges::distance(ref_sequences));
931 
932  header_ptr = std::unique_ptr<header_type>{std::make_unique<header_type>(ref_ids)};
933  reference_sequences_ptr = &ref_sequences;
934 
935  // initialise reference map and ref_dict if ref_ids are non-empty
936  for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
937  {
938  header_ptr->ref_id_info.emplace_back(std::ranges::distance(ref_sequences[idx]), "");
939 
940  if constexpr (std::ranges::contiguous_range<std::ranges::range_reference_t<
941  typename traits_type::ref_ids>> &&
942  std::ranges::sized_range<std::ranges::range_reference_t<typename traits_type::ref_ids>> &&
943  std::ranges::borrowed_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>)
944  {
945  auto && id = header_ptr->ref_ids()[idx];
946  header_ptr->ref_dict[std::span{std::ranges::data(id), std::ranges::size(id)}] = idx;
947  }
948  else
949  {
950  header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
951  }
952  }
953  }
955 
957  void read_next_record()
958  {
959  // clear the record
960  record_buffer.clear();
961  detail::get_or_ignore<field::header_ptr>(record_buffer) = header_ptr.get();
962 
963  // at end if we could not read further
964  if (std::istreambuf_iterator<stream_char_type>{*secondary_stream} ==
966  {
967  at_end = true;
968  return;
969  }
970 
971  auto call_read_func = [this] (auto & ref_seq_info)
972  {
973  std::visit([&] (auto & f)
974  {
975  f.read_alignment_record(*secondary_stream,
976  options,
977  ref_seq_info,
978  *header_ptr,
979  detail::get_or_ignore<field::seq>(record_buffer),
980  detail::get_or_ignore<field::qual>(record_buffer),
981  detail::get_or_ignore<field::id>(record_buffer),
982  detail::get_or_ignore<field::offset>(record_buffer),
983  detail::get_or_ignore<field::ref_seq>(record_buffer),
984  detail::get_or_ignore<field::ref_id>(record_buffer),
985  detail::get_or_ignore<field::ref_offset>(record_buffer),
986  detail::get_or_ignore<field::alignment>(record_buffer),
987  detail::get_or_ignore<field::cigar>(record_buffer),
988  detail::get_or_ignore<field::flag>(record_buffer),
989  detail::get_or_ignore<field::mapq>(record_buffer),
990  detail::get_or_ignore<field::mate>(record_buffer),
991  detail::get_or_ignore<field::tags>(record_buffer),
992  detail::get_or_ignore<field::evalue>(record_buffer),
993  detail::get_or_ignore<field::bit_score>(record_buffer));
994  }, format);
995  };
996 
997  assert(!format.valueless_by_exception());
998 
999  if constexpr (!std::same_as<typename traits_type::ref_sequences, ref_info_not_given>)
1000  call_read_func(*reference_sequences_ptr);
1001  else
1002  call_read_func(std::ignore);
1003  }
1004 
1006  friend iterator;
1007 };
1008 
1013 template <input_stream stream_type,
1015  alignment_file_input_format file_format,
1016  detail::fields_specialisation selected_field_ids>
1017 alignment_file_input(stream_type && stream,
1018  file_format const &,
1019  selected_field_ids const &)
1023 
1025 template <input_stream stream_type,
1026  alignment_file_input_format file_format,
1027  detail::fields_specialisation selected_field_ids>
1028 alignment_file_input(stream_type & stream,
1029  file_format const &,
1030  selected_field_ids const &)
1034 
1036 template <input_stream stream_type,
1037  alignment_file_input_format file_format>
1038 alignment_file_input(stream_type && stream,
1039  file_format const &)
1041  typename alignment_file_input<>::selected_field_ids, // actually use the default
1043 
1045 template <input_stream stream_type,
1046  alignment_file_input_format file_format>
1047 alignment_file_input(stream_type & stream,
1048  file_format const &)
1050  typename alignment_file_input<>::selected_field_ids, // actually use the default
1052 
1054 template <std::ranges::forward_range ref_ids_t,
1055  std::ranges::forward_range ref_sequences_t,
1056  detail::fields_specialisation selected_field_ids>
1058  ref_ids_t &,
1059  ref_sequences_t &,
1060  selected_field_ids const &)
1064  typename alignment_file_input<>::valid_formats>; // actually use the default
1065 
1067 template <std::ranges::forward_range ref_ids_t,
1068  std::ranges::forward_range ref_sequences_t>
1070  ref_ids_t &,
1071  ref_sequences_t &)
1074  typename alignment_file_input<>::selected_field_ids, // actually use the default
1075  typename alignment_file_input<>::valid_formats>; // actually use the default
1076 
1078 template <input_stream stream_type,
1079  std::ranges::forward_range ref_ids_t,
1080  std::ranges::forward_range ref_sequences_t,
1081  alignment_file_input_format file_format,
1082  detail::fields_specialisation selected_field_ids>
1083 alignment_file_input(stream_type && stream,
1084  ref_ids_t &,
1085  ref_sequences_t &,
1086  file_format const &,
1087  selected_field_ids const &)
1092 
1094 template <input_stream stream_type,
1095  std::ranges::forward_range ref_ids_t,
1096  std::ranges::forward_range ref_sequences_t,
1097  alignment_file_input_format file_format,
1098  detail::fields_specialisation selected_field_ids>
1099 alignment_file_input(stream_type & stream,
1100  ref_ids_t &,
1101  ref_sequences_t &,
1102  file_format const &,
1103  selected_field_ids const &)
1108 
1110 template <input_stream stream_type,
1111  std::ranges::forward_range ref_ids_t,
1112  std::ranges::forward_range ref_sequences_t,
1113  alignment_file_input_format file_format>
1114 alignment_file_input(stream_type && stream,
1115  ref_ids_t &,
1116  ref_sequences_t &,
1117  file_format const &)
1120  typename alignment_file_input<>::selected_field_ids, // actually use the default
1122 
1124 template <input_stream stream_type,
1125  std::ranges::forward_range ref_ids_t,
1126  std::ranges::forward_range ref_sequences_t,
1127  alignment_file_input_format file_format>
1128 alignment_file_input(stream_type & stream,
1129  ref_ids_t &,
1130  ref_sequences_t &,
1131  file_format const &)
1134  typename alignment_file_input<>::selected_field_ids, // actually use the default
1137 
1138 } // namespace seqan3
1139 
1140 // ------------------------------------------------------------------
1141 // std-overloads for the tuple-like interface
1142 // ------------------------------------------------------------------
1143 
1144 namespace std
1145 {
1146 
1152 template <seqan3::alignment_file_input_traits traits_type,
1153  seqan3::detail::fields_specialisation selected_field_ids,
1154  seqan3::detail::type_list_of_alignment_file_input_formats valid_formats>
1155 struct tuple_size<seqan3::alignment_file_input<traits_type, selected_field_ids, valid_formats>>
1156 {
1158  static constexpr size_t value = selected_field_ids::as_array.size();
1159 };
1160 
1166 template <size_t elem_no,
1168  seqan3::detail::fields_specialisation selected_field_ids,
1169  seqan3::detail::type_list_of_alignment_file_input_formats valid_formats>
1170 struct tuple_element<elem_no, seqan3::alignment_file_input<traits_type, selected_field_ids, valid_formats>>
1171  : tuple_element<elem_no, typename seqan3::alignment_file_input<traits_type,
1172  selected_field_ids,
1173  valid_formats>::file_as_tuple_type>
1174 {};
1175 
1176 } // namespace std
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &&stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &) -> alignment_file_input< alignment_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.
seqan3::alignment_file_input::mapq_type
uint8_t mapq_type
The type of field::mapq is fixed to uint8_t.
Definition: input.hpp:421
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(alignment_file_input &&)=default
Move construction is defaulted.
seqan3::alignment_file_input::begin
iterator begin()
Returns an iterator to current position in the file.
Definition: input.hpp:756
misc.hpp
Provides helper data structures for the seqan3::alignment_file_output.
seqan3::alignment_file_input::front
reference front() noexcept
Return the record we are currently at in the file.
Definition: input.hpp:809
qualified.hpp
Provides quality alphabet composites.
seqan3::alignment_file_input::bitscore_type
double bitscore_type
The type of field::bitscore is fixed to double.
Definition: input.hpp:434
std::span
fstream
std::basic_string
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &&stream, file_format const &) -> alignment_file_input< typename alignment_file_input<>::traits_type, typename alignment_file_input<>::selected_field_ids, type_list< file_format >>
Deduce file_format, and default the rest.
sequence_container
A more refined container concept than seqan3::container.
seqan3::alignment_file_input::size_type
size_t size_type
An unsigned integer type, usually std::size_t.
Definition: input.hpp:536
seqan3::alignment_file_input::alignment_type
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:449
seqan3::type_list
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:31
dna15.hpp
Provides seqan3::dna15, container aliases and string literals.
tuple.hpp
Provides seqan3::tuple_like.
seqan3::field::offset
@ offset
Sequence (SEQ) relative start position (0-based), unsigned value.
concept.hpp
Stream concepts.
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &stream, ref_ids_t &, ref_sequences_t &, file_format const &, selected_field_ids const &) -> alignment_file_input< alignment_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.
seqan3::alignment_file_input::alignment_file_input
alignment_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:623
seqan3::alignment_file_input::end
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition: input.hpp:781
seqan3::alignment_file_input::options
alignment_file_input_options< typename traits_type::sequence_legal_alphabet > options
The options are public and its members can be set directly.
Definition: input.hpp:816
gap_decorator.hpp
Provides seqan3::gap_decorator.
vector
std::vector::size
T size(T... args)
explicitly_convertible_to
Resolves to std::ranges::explicitly_convertible_to<type1, type2>().
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &&stream, file_format const &, selected_field_ids const &) -> alignment_file_input< typename alignment_file_input<>::traits_type, selected_field_ids, type_list< file_format >>
Deduce selected fields, file_format, and default the rest.
seqan3::alignment_file_input::const_reference
void const_reference
The const_reference type is void because files are not const-iterable.
Definition: input.hpp:534
seqan3::alignment_file_input::header_type
alignment_file_header< typename traits_type::ref_ids > header_type
The type of field::header_ptr (default: alignment_file_header<typename traits_type::ref_ids>).
Definition: input.hpp:436
seqan3::field::id
@ id
The identifier, usually a string.
std::unique_ptr::get
T get(T... args)
format_sam.hpp
Provides the seqan3::format_sam.
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition: input.hpp:580
seqan3::dna15
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition: dna15.hpp:49
seqan3::sam_flag
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition: misc.hpp:71
std::tuple
seqan3::alignment_file_input_options< typename traits_type::sequence_legal_alphabet >
seqan3::alignment_file_input::alignment_file_input
alignment_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:707
record.hpp
Provides the seqan3::record template and the seqan3::field enum.
std::function
seqan3::alignment_file_input::ref_offset_type
std::optional< int32_t > ref_offset_type
The type of field::ref_offset is fixed to an std::optional<int32_t>.
Definition: input.hpp:419
filesystem
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &, selected_field_ids const &) -> alignment_file_input< alignment_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t >>, selected_field_ids, typename alignment_file_input<>::valid_formats >
Deduce selected fields, ref_sequences_t and ref_ids_t, default the rest.
seqan3::alignment_file_input::quality_type
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:424
alignment_file_input_format
The generic concept for alignment file input formats.
std::filesystem::path
seqan3::pack_traits::contains
constexpr bool contains
Whether a type occurs in a pack or not.
Definition: traits.hpp:193
seqan3::alignment_file_input::header
header_type & header()
Access the file's header.
Definition: input.hpp:830
seqan3::alignment_file_input::field_types
type_list< sequence_type, id_type, offset_type, ref_sequence_type, ref_id_type, ref_offset_type, alignment_type, std::vector< cigar >, mapq_type, quality_type, flag_type, mate_type, sam_tag_dictionary, e_value_type, bitscore_type, header_type * > field_types
The previously defined types aggregated in a seqan3::type_list.
Definition: input.hpp:467
concepts
The Concepts library.
seqan3::fields
A class template that holds a choice of seqan3::field.
Definition: record.hpp:166
input_format_concept.hpp
Provides seqan3::alignment_file_input_format and auxiliary classes.
seqan3::alignment_file_input::e_value_type
double e_value_type
The type of field::evalue is fixed to double.
Definition: input.hpp:432
seqan3::alignment_file_input::~alignment_file_input
~alignment_file_input()=default
Destructor is defaulted.
seqan3::seq
constexpr sequenced_policy seq
Global execution policy object for sequenced execution policy.
Definition: execution.hpp:54
seqan3::alignment_file_input::operator=
alignment_file_input & operator=(alignment_file_input const &)=delete
Copy assignment is explicitly deleted because you cannot have multiple access to the same file.
seqan3::alphabet_variant
A combined alphabet that can hold values of either of its alternatives.
Definition: alphabet_variant.hpp:133
seqan3::alignment_file_input::valid_formats
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition: input.hpp:364
seqan3::alignment_file_input::offset_type
int32_t offset_type
The type of field::offset is fixed to int32_t.
Definition: input.hpp:395
seqan3::alignment_file_input::const_iterator
void const_iterator
The const iterator type is void because files are not const-iterable.
Definition: input.hpp:542
seqan3::alignment_file_input
A class for reading alignment files, e.g. SAM, BAM, BLAST ...
Definition: input.hpp:353
seqan3::alignment_file_input::ref_id_type
std::optional< int32_t > ref_id_type
The type of field::ref_id is fixed to std::optional<int32_t>.
Definition: input.hpp:412
slice.hpp
Provides seqan3::views::slice.
repeat_n.hpp
Provides seqan3::views::repeat_n.
aa27.hpp
Provides seqan3::aa27, container aliases and string literals.
seqan3::field::cigar
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
seqan3::alignment_file_input::alignment_file_input
alignment_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:610
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &&stream, ref_ids_t &, ref_sequences_t &, file_format const &) -> alignment_file_input< alignment_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t >>, typename alignment_file_input<>::selected_field_ids, type_list< file_format >>
Deduce ref_sequences_t and ref_ids_t, and file format.
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
seqan3::alignment_file_header
Stores the header information of alignment files.
Definition: header.hpp:33
seqan3::field::mapq
@ mapq
The mapping quality of the SEQ alignment, usually a ohred-scaled score.
seqan3::alignment_file_input::alignment_file_input
alignment_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:654
transformation_trait_or.hpp
Provides seqan3::detail::transformation_trait_or.
exception.hpp
Provides exceptions used in the I/O module.
dna5.hpp
Provides seqan3::dna5, container aliases and string literals.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &stream, file_format const &, selected_field_ids const &) -> alignment_file_input< typename alignment_file_input<>::traits_type, selected_field_ids, type_list< file_format >>
Deduce selected fields, file_format, and default the rest.
seqan3::alignment_file_input::iterator
detail::in_file_iterator< alignment_file_input > iterator
The iterator type of this view (an input iterator).
Definition: input.hpp:540
seqan3::alignment_file_input::operator=
alignment_file_input & operator=(alignment_file_input &&)=default
Move assignment is defaulted.
seqan3::alignment_file_input::sequence_type
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:391
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &stream, file_format const &) -> alignment_file_input< typename alignment_file_input<>::traits_type, typename alignment_file_input<>::selected_field_ids, type_list< file_format >>
Deduce file_format, and default the rest.
seqan3::alignment_file_input_default_traits::ref_ids
ref_ids_t ref_ids
The type of the reference identifiers is deduced on construction.
Definition: input.hpp:215
std::istreambuf_iterator
std::make_signed_t
seqan3::phred42
Quality type for traditional Sanger and modern Illumina Phred scores (typical range).
Definition: phred42.hpp:44
std::format
T format(T... args)
seqan3::alignment_file_input::selected_field_ids
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition: input.hpp:362
seqan3::pack_traits::size
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:116
misc_input.hpp
Provides various utility functions required only for input.
seqan3::alignment_file_input::traits_type
traits_type_ traits_type
A traits type that defines aliases and template for storage of the fields.
Definition: input.hpp:360
seqan3::alignment_file_input::stream_char_type
char stream_char_type
Character type of the stream(s).
Definition: input.hpp:366
char.hpp
Provides alphabet adaptations for standard char types.
ranges
Adaptations of concepts from the Ranges TS.
seqan3::sam_tag_dictionary
The SAM tag dictionary class that stores all optional SAM fields.
Definition: sam_tag_dictionary.hpp:325
seqan3::alignment_file_input_default_traits
The default traits for seqan3::alignment_file_input.
Definition: input.hpp:184
format_bam.hpp
Provides the seqan3::format_bam.
std::remove_reference_t
alphabet
The generic alphabet concept that covers most data types used in ranges.
std
SeqAn specific customisations in the standard namespace.
cassert
cigar.hpp
Provides the seqan3::cigar alphabet.
seqan3::field
field
An enumerator for the fields used in file formats.
Definition: record.hpp:65
alignment_file_input_traits
The requirements a traits_type for seqan3::alignment_file_input must meet.
seqan3::record< detail::select_types_with_ids_t< field_types, field_ids, selected_field_ids >, selected_field_ids >
seqan3::views::slice
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:141
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(stream_type &stream, ref_ids_t &, ref_sequences_t &, file_format const &) -> alignment_file_input< alignment_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t >>, typename alignment_file_input<>::selected_field_ids, type_list< file_format >>
Deduce selected fields, ref_sequences_t and ref_ids_t, and file format.
std::visit
T visit(T... args)
std::optional
seqan3::views::repeat_n
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:94
seqan3::gap_decorator
A gap decorator allows the annotation of sequences with gap symbols while leaving the underlying sequ...
Definition: gap_decorator.hpp:85
seqan3::dna5
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition: dna5.hpp:49
seqan3::alignment_file_input_default_traits::ref_sequences
ref_sequences_t ref_sequences
The type of the reference sequences is deduced on construction.
Definition: input.hpp:212
seqan3::pack_traits::transform
seqan3::type_list< trait_t< pack_t >... > transform
Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
Definition: traits.hpp:307
in_file_iterator.hpp
Provides the seqan3::detail::in_file_iterator class template.
std::conditional_t
seqan3::field::flag
@ flag
The alignment flag (bit information), uint16_t value.
seqan3::file_open_error
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem.
Definition: exception.hpp:40
traits.hpp
Provides traits for seqan3::type_list.
seqan3::alignment_file_input::id_type
typename traits_type::template id_container< char > id_type
The type of field::id (default std::string by default).
Definition: input.hpp:393
seqan3::alignment_file_input::alignment_file_input
alignment_file_input()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(std::filesystem::path path, ref_ids_t &, ref_sequences_t &) -> alignment_file_input< alignment_file_input_default_traits< std::remove_reference_t< ref_sequences_t >, std::remove_reference_t< ref_ids_t >>, typename alignment_file_input<>::selected_field_ids, typename alignment_file_input<>::valid_formats >
Deduce ref_sequences_t and ref_ids_t, default the rest.
seqan3::alignment_file_input::mate_type
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:430
std::basic_istream
writable_alphabet
Refines seqan3::alphabet and adds assignability.
std::unique_ptr
writable_quality_alphabet
A concept that indicates whether a writable alphabet represents quality scores.
seqan3::alignment_file_input::alignment_file_input
alignment_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:692
seqan3::alignment_file_input::record_type
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:522
phred42.hpp
Provides seqan3::phred42 quality scores.
seqan3::alignment_file_input::flag_type
sam_flag flag_type
The type of field::flag is fixed to seqan3::sam_flag.
Definition: input.hpp:426
std::vector::data
T data(T... args)
seqan3::alignment_file_input::alignment_file_input
alignment_file_input(alignment_file_input const &)=delete
Copy construction is explicitly deleted because you cannot have multiple access to the same file.
seqan3::alignment_file_input::ref_sequence_type
std::conditional_t< std::same_as< typename traits_type::ref_sequences, ref_info_not_given >, dummy_ref_type, ref_sequence_sliced_type > ref_sequence_type
The type of field::ref_seq (default depends on construction).
Definition: input.hpp:404
seqan3::field::header_ptr
@ header_ptr
A pointer to the seqan3::alignment_file_header object storing header information.
seqan3::alignment_file_input::sentinel
std::default_sentinel_t sentinel
The type returned by end().
Definition: input.hpp:544
seqan3::field::alignment
@ alignment
The (pairwise) alignment stored in an seqan3::alignment object.
variant
std::ifstream
string