31 #include <seqan3/io/detail/record.hpp>
143 template <
typename _sequence_alphabet>
150 template <
typename _
id_alphabet>
157 template <
typename _quality_alphabet>
330 static_assert([] () constexpr
332 for (
field f : selected_field_ids::as_array)
333 if (!field_ids::contains(f))
337 "You selected a field that is not valid for sequence files, please refer to the documentation "
338 "of sequence_file_input::field_ids for the accepted values.");
347 typename traits_type::sequence_alphabet>;
349 using id_type =
typename traits_type::template id_container<
350 typename traits_type::id_alphabet>;
353 typename traits_type::quality_alphabet>;
379 using iterator = detail::in_file_iterator<sequence_file_input>;
420 primary_stream{
new std::ifstream{}, stream_deleter_default}
422 primary_stream->rdbuf()->pubsetbuf(stream_buffer.data(), stream_buffer.size());
423 static_cast<std::basic_ifstream<char> *
>(primary_stream.get())->open(filename,
424 std::ios_base::in | std::ios::binary);
426 if (!primary_stream->good())
427 throw file_open_error{
"Could not open file " + filename.string() +
" for reading."};
430 secondary_stream = detail::make_secondary_istream(*primary_stream, filename);
433 using format_variant_t =
typename detail::variant_from_tags<
valid_formats,
434 detail::sequence_file_input_format_exposer>::type;
435 format_variant_t format_variant{};
436 detail::set_format(format_variant, filename);
438 std::visit([&] (
auto && selected_format)
441 format = std::make_unique<selected_sequence_format<format_t>>();
465 template <input_stream stream_t,
468 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type,
stream_char_type>
471 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
473 primary_stream{&stream, stream_deleter_noop},
474 format{std::make_unique<selected_sequence_format<file_format>>()}
476 static_assert(list_traits::contains<file_format, valid_formats>,
477 "You selected a format that is not in the valid_formats of this file.");
480 secondary_stream = detail::make_secondary_istream(*primary_stream);
484 template <input_stream stream_t,
487 requires std::same_as<typename std::remove_reference_t<stream_t>::char_type,
stream_char_type>
490 file_format
const & SEQAN3_DOXYGEN_ONLY(format_tag),
492 primary_stream{
new stream_t{std::move(stream)}, stream_deleter_default},
493 format{std::make_unique<selected_sequence_format<file_format>>()}
495 static_assert(list_traits::contains<file_format, valid_formats>,
496 "You selected a format that is not in the valid_formats of this file.");
499 secondary_stream = detail::make_secondary_istream(*primary_stream);
524 if (!first_record_was_read)
527 first_record_was_read =
true;
593 std::vector<char> stream_buffer{std::vector<char>(1'000'000)};
600 using stream_ptr_t = std::unique_ptr<std::basic_istream<stream_char_type>,
601 std::function<void(std::basic_istream<stream_char_type>*)>>;
603 static void stream_deleter_noop(std::basic_istream<stream_char_type> *) {}
605 static void stream_deleter_default(std::basic_istream<stream_char_type> * ptr) {
delete ptr; }
608 stream_ptr_t primary_stream{
nullptr, stream_deleter_noop};
610 stream_ptr_t secondary_stream{
nullptr, stream_deleter_noop};
613 bool first_record_was_read{
false};
620 void read_next_record()
623 record_buffer.
clear();
626 if ((std::istreambuf_iterator<stream_char_type>{*secondary_stream} ==
627 std::istreambuf_iterator<stream_char_type>{}))
633 format->read_sequence_record(*secondary_stream, record_buffer,
options);
646 struct sequence_format_base
651 sequence_format_base() =
default;
652 sequence_format_base(sequence_format_base
const &) =
default;
653 sequence_format_base(sequence_format_base &&) =
default;
654 sequence_format_base &
operator=(sequence_format_base
const &) =
default;
655 sequence_format_base &
operator=(sequence_format_base &&) =
default;
656 virtual ~sequence_format_base() =
default;
669 virtual void read_sequence_record(std::istream & instream,
685 template <
typename format_t>
686 struct selected_sequence_format final :
public sequence_format_base
691 selected_sequence_format() =
default;
692 selected_sequence_format(selected_sequence_format
const &) =
default;
693 selected_sequence_format(selected_sequence_format &&) =
default;
694 selected_sequence_format &
operator=(selected_sequence_format
const &) =
default;
695 selected_sequence_format &
operator=(selected_sequence_format &&) =
default;
696 ~selected_sequence_format() =
default;
700 void read_sequence_record(std::istream & instream,
706 _format.read_sequence_record(instream,
708 detail::get_or_ignore<field::seq>(record_buffer),
709 detail::get_or_ignore<field::id>(record_buffer),
710 detail::get_or_ignore<field::qual>(record_buffer));
715 detail::sequence_file_input_format_exposer<format_t> _format{};
719 std::unique_ptr<sequence_format_base> format{};
731 template <input_stream stream_type,
740 template <input_stream stream_type,
749 template <input_stream stream_type,
760 template <input_stream stream_type,
Provides seqan3::aa27, container aliases and string literals.
Provides alphabet adaptations for standard char types.
The twenty-seven letter amino acid alphabet.
Definition: aa27.hpp:46
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
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...
field
An enumerator for the fields used in file formats.
Definition: record.hpp:63
Provides the seqan3::detail::in_file_iterator class template.
Resolves to std::ranges::explicitly_convertible_to<type1, type2>(). <dl class="no-api">This entity i...
A more refined container concept than seqan3::container.
Refines seqan3::alphabet and adds assignability.
A concept that indicates whether a writable alphabet represents quality scores.
Provides exceptions used in the I/O module.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
typename remove_cvref< t >::type remove_cvref_t
Return the input type with const, volatile and references removed (transformation_trait shortcut).
Definition: type_traits:54
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
Provides seqan3::phred42 quality scores.
Provides quality alphabet composites.
Provides seqan3::sequence_record.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:128
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
Type that contains multiple types.
Definition: type_list.hpp:29
Provides traits for seqan3::type_list.