Loading...
Searching...
No Matches
sam_file/input.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <cassert>
#include <concepts>
#include <filesystem>
#include <fstream>
#include <ranges>
#include <string>
#include <variant>
#include <vector>
#include <seqan3/alphabet/adaptation/char.hpp>
#include <seqan3/alphabet/aminoacid/aa27.hpp>
#include <seqan3/alphabet/cigar/cigar.hpp>
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/io/detail/in_file_iterator.hpp>
#include <seqan3/io/detail/misc_input.hpp>
#include <seqan3/io/detail/record.hpp>
#include <seqan3/io/exception.hpp>
#include <seqan3/io/sam_file/format_bam.hpp>
#include <seqan3/io/sam_file/format_sam.hpp>
#include <seqan3/io/sam_file/input_format_concept.hpp>
#include <seqan3/io/sam_file/record.hpp>
#include <seqan3/io/sam_file/sam_flag.hpp>
#include <seqan3/io/stream/concept.hpp>
#include <seqan3/utility/tuple/concept.hpp>
#include <seqan3/utility/type_list/traits.hpp>
#include <seqan3/utility/type_traits/detail/transformation_trait_or.hpp>
#include <seqan3/utility/views/repeat_n.hpp>
#include <seqan3/utility/views/slice.hpp>
namespace seqan3
{
// ---------------------------------------------------------------------------------------------------------------------
// sam_file_input_traits
// ---------------------------------------------------------------------------------------------------------------------
template <typename t>
concept sam_file_input_traits = requires (t v) {
// field::seq
requires writable_alphabet<typename t::sequence_alphabet>;
requires writable_alphabet<typename t::sequence_legal_alphabet>;
requires explicitly_convertible_to<typename t::sequence_legal_alphabet, typename t::sequence_alphabet>;
requires sequence_container<typename t::template sequence_container<typename t::sequence_alphabet>>;
// field::id
requires sequence_container<typename t::template id_container<char>>;
// field::qual
requires writable_quality_alphabet<typename t::quality_alphabet>;
requires sequence_container<typename t::template quality_container<typename t::quality_alphabet>>;
// field::ref_seq
// either ref_info_not_given or a range over ranges over alphabet (e.g. std::vector<dna4_vector>)
requires std::same_as<typename t::ref_sequences, ref_info_not_given> || requires () {
requires alphabet<std::ranges::range_reference_t<std::ranges::range_reference_t<typename t::ref_sequences>>>;
};
// field::ref_id
requires alphabet<std::ranges::range_reference_t<std::ranges::range_reference_t<typename t::ref_ids>>>
&& (!std::same_as<typename t::ref_sequences, ref_info_not_given>
|| writable_alphabet<
std::ranges::range_reference_t<std::ranges::range_reference_t<typename t::ref_ids>>>);
requires std::ranges::forward_range<std::ranges::range_reference_t<typename t::ref_ids>>;
requires std::ranges::forward_range<typename t::ref_ids>;
// field::ref_offset is fixed to std::optional<int32_t>
// field::flag is fixed to seqan3::sam_flag
// field::mapq is fixed to uint8_t
// field::evalue is fixed to double
// field::bitscore is fixed to double
// field::mate is fixed to std::tuple<ref_id_container<ref_id_alphabet>, ref_offset_type, int32_t>
};
// ---------------------------------------------------------------------------------------------------------------------
// sam_file_input_default_traits
// ---------------------------------------------------------------------------------------------------------------------
template <typename ref_sequences_t = ref_info_not_given, typename ref_ids_t = std::deque<std::string>>
struct sam_file_input_default_traits
{
using sequence_alphabet = dna5;
using sequence_legal_alphabet = dna15;
template <typename _sequence_alphabet>
using sequence_container = std::vector<_sequence_alphabet>;
template <typename _id_alphabet>
using id_container = std::basic_string<_id_alphabet>;
using quality_alphabet = phred42;
template <typename _quality_alphabet>
using quality_container = std::vector<_quality_alphabet>;
using ref_sequences = ref_sequences_t;
using ref_ids = ref_ids_t;
};
// ---------------------------------------------------------------------------------------------------------------------
// sam_file_input
// ---------------------------------------------------------------------------------------------------------------------
template <sam_file_input_traits traits_type_ = sam_file_input_default_traits<>,
detail::fields_specialisation selected_field_ids_ = fields<field::seq,
field::id,
field::ref_id,
field::ref_offset,
field::cigar,
field::mapq,
field::qual,
field::flag,
field::mate,
field::tags,
field::header_ptr>,
detail::type_list_of_sam_file_input_formats valid_formats_ = type_list<format_sam, format_bam>>
class sam_file_input
{
public:
using traits_type = traits_type_;
using selected_field_ids = selected_field_ids_;
using valid_formats = valid_formats_;
using stream_char_type = char;
private:
using dummy_ref_type = decltype(views::repeat_n(typename traits_type::sequence_alphabet{}, size_t{})
| std::views::transform(detail::access_restrictor_fn{}));
using ref_sequence_unsliced_type = 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>;
using ref_sequence_sliced_type = decltype(std::declval<ref_sequence_unsliced_type>() | views::slice(0, 0));
public:
using sequence_type = typename traits_type::template sequence_container<typename traits_type::sequence_alphabet>;
using id_type = typename traits_type::template id_container<char>;
using 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>;
using ref_id_type = std::optional<int32_t>;
using ref_offset_type = std::optional<int32_t>;
using mapq_type = uint8_t;
using quality_type = typename traits_type::template quality_container<typename traits_type::quality_alphabet>;
using flag_type = sam_flag;
using cigar_type = std::vector<cigar>;
using mate_type = std::tuple<ref_id_type, ref_offset_type, int32_t>;
using header_type = sam_file_header<typename traits_type::ref_ids>;
using field_types = type_list<sequence_type,
id_type,
ref_id_type,
ref_offset_type,
std::vector<cigar>,
mapq_type,
quality_type,
flag_type,
mate_type,
sam_tag_dictionary,
header_type *>;
using field_ids = fields<field::seq,
field::id,
field::ref_id,
field::ref_offset,
field::cigar,
field::mapq,
field::qual,
field::flag,
field::mate,
field::tags,
field::header_ptr>;
static_assert(!selected_field_ids::contains(field::alignment),
"The seqan3::field::alignment was removed from the allowed fields for seqan3::sam_file_input. "
"Only seqan3::field::cigar is supported. Please see seqan3::alignment_from_cigar on how to get an "
"alignment from the cigar information.");
static_assert(!selected_field_ids::contains(field::offset),
"The field::offset is deprecated. Please access field::cigar and retrieve the soft clipping (S) "
"value at the front of the CIGAR string (offset = 0 if there is no soft clipping at the front).");
static_assert(
[]() constexpr
{
for (field f : selected_field_ids::as_array)
if (!field_ids::contains(f))
return false;
return true;
}(),
"You selected a field that is not valid for SAM files, please refer to the documentation "
"of sam_file_input::field_ids for the accepted values.");
using record_type =
sam_record<detail::select_types_with_ids_t<field_types, field_ids, selected_field_ids>, selected_field_ids>;
using value_type = record_type;
using reference = record_type &;
using const_reference = void;
using size_type = size_t;
using difference_type = std::make_signed_t<size_t>;
using iterator = detail::in_file_iterator<sam_file_input>;
using const_iterator = void;
using sentinel = std::default_sentinel_t;
sam_file_input() = delete;
sam_file_input(sam_file_input const &) = delete;
sam_file_input & operator=(sam_file_input const &) = delete;
sam_file_input(sam_file_input &&) = default;
sam_file_input & operator=(sam_file_input &&) = default;
~sam_file_input() = default;
sam_file_input(std::filesystem::path filename,
selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
primary_stream{new std::ifstream{}, stream_deleter_default}
{
init_by_filename(std::move(filename));
}
template <input_stream stream_t, sam_file_input_format file_format>
requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
sam_file_input(stream_t & stream,
file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
primary_stream{&stream, stream_deleter_noop}
{
init_by_format<file_format>();
}
template <input_stream stream_t, sam_file_input_format file_format>
requires std::same_as<typename std::remove_reference_t<stream_t>::char_type, stream_char_type>
sam_file_input(stream_t && stream,
file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
{
init_by_format<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 & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
primary_stream{new std::ifstream{}, stream_deleter_default}
{
// initialize reference information
set_references(ref_ids, ref_sequences);
init_by_filename(std::move(filename));
}
template <input_stream stream_t, sam_file_input_format file_format>
sam_file_input(stream_t & stream,
typename traits_type::ref_ids & ref_ids,
typename traits_type::ref_sequences & ref_sequences,
file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
primary_stream{&stream, stream_deleter_noop}
{
// initialize reference information
set_references(ref_ids, ref_sequences);
init_by_format<file_format>();
}
template <input_stream stream_t, sam_file_input_format file_format>
sam_file_input(stream_t && stream,
typename traits_type::ref_ids & ref_ids,
typename traits_type::ref_sequences & ref_sequences,
file_format const & SEQAN3_DOXYGEN_ONLY(format_tag),
selected_field_ids const & SEQAN3_DOXYGEN_ONLY(fields_tag) = selected_field_ids{}) :
primary_stream{new stream_t{std::move(stream)}, stream_deleter_default}
{
// initialize reference information
set_references(ref_ids, ref_sequences);
init_by_format<file_format>();
}
// explicitly delete rvalues for reference information
sam_file_input(std::filesystem::path,
typename traits_type::ref_ids &&,
typename traits_type::ref_sequences &&,
selected_field_ids const &) = delete;
template <input_stream stream_t, sam_file_input_format file_format>
sam_file_input(stream_t &&,
typename traits_type::ref_ids &&,
typename traits_type::ref_sequences &&,
file_format const &,
selected_field_ids const &) = delete;
iterator begin()
{
// buffer first record
if (!first_record_was_read)
{
read_next_record();
first_record_was_read = true;
}
return {*this};
}
sentinel end() noexcept
{
return {};
}
reference front() noexcept
{
return *begin();
}
sam_file_input_options<typename traits_type::sequence_legal_alphabet> options;
header_type & header()
{
// make sure header is read
if (!first_record_was_read)
{
read_next_record();
first_record_was_read = true;
}
return *header_ptr;
}
protected:
void init_by_filename(std::filesystem::path filename)
{
primary_stream->rdbuf()->pubsetbuf(stream_buffer.data(), stream_buffer.size());
static_cast<std::basic_ifstream<char> *>(primary_stream.get())
->open(filename, std::ios_base::in | std::ios::binary);
// open stream
if (!primary_stream->good())
throw file_open_error{"Could not open file " + filename.string() + " for reading."};
secondary_stream = detail::make_secondary_istream(*primary_stream, filename);
detail::set_format(format, filename);
}
template <typename format_type>
void init_by_format()
{
static_assert(list_traits::contains<format_type, valid_formats>,
"You selected a format that is not in the valid_formats of this file.");
format = detail::sam_file_input_format_exposer<format_type>{};
secondary_stream = detail::make_secondary_istream(*primary_stream);
}
std::unique_ptr<header_type> header_ptr{new header_type{}};
record_type record_buffer;
std::vector<char> stream_buffer{std::vector<char>(1'000'000)};
std::streampos position_buffer{};
using stream_ptr_t = std::unique_ptr<std::basic_istream<stream_char_type>,
std::function<void(std::basic_istream<stream_char_type> *)>>;
static void stream_deleter_noop(std::basic_istream<stream_char_type> *)
{}
static void stream_deleter_default(std::basic_istream<stream_char_type> * ptr)
{
delete ptr;
}
stream_ptr_t primary_stream{nullptr, stream_deleter_noop};
stream_ptr_t secondary_stream{nullptr, stream_deleter_noop};
bool first_record_was_read{false};
bool at_end{false};
using format_type = typename detail::variant_from_tags<valid_formats, detail::sam_file_input_format_exposer>::type;
format_type format;
typename traits_type::ref_sequences const * reference_sequences_ptr{nullptr};
template <std::ranges::forward_range ref_sequences_t>
void set_references(typename traits_type::ref_ids & ref_ids, ref_sequences_t && ref_sequences)
{
assert(std::ranges::distance(ref_ids) == std::ranges::distance(ref_sequences));
header_ptr = std::unique_ptr<header_type>{std::make_unique<header_type>(ref_ids)};
reference_sequences_ptr = &ref_sequences;
// initialise reference map and ref_dict if ref_ids are non-empty
for (int32_t idx = 0; idx < std::ranges::distance(ref_ids); ++idx)
{
header_ptr->ref_id_info.emplace_back(std::ranges::distance(ref_sequences[idx]), "");
if constexpr (std::ranges::contiguous_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>
&& std::ranges::sized_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>
&& std::ranges::borrowed_range<std::ranges::range_reference_t<typename traits_type::ref_ids>>)
{
auto && id = header_ptr->ref_ids()[idx];
header_ptr->ref_dict[std::span{std::ranges::data(id), std::ranges::size(id)}] = idx;
}
else
{
header_ptr->ref_dict[header_ptr->ref_ids()[idx]] = idx;
}
}
}
void read_next_record()
{
// clear the record
record_buffer.clear();
detail::get_or_ignore<field::header_ptr>(record_buffer) = header_ptr.get();
// at end if we could not read further
if (std::istreambuf_iterator<stream_char_type>{*secondary_stream}
== std::istreambuf_iterator<stream_char_type>{})
{
at_end = true;
return;
}
auto call_read_func = [this](auto & ref_seq_info)
{
std::visit(
[&](auto & f)
{
f.read_alignment_record(*secondary_stream,
options,
ref_seq_info,
*header_ptr,
position_buffer,
detail::get_or_ignore<field::seq>(record_buffer),
detail::get_or_ignore<field::qual>(record_buffer),
detail::get_or_ignore<field::id>(record_buffer),
detail::get_or_ignore<field::ref_seq>(record_buffer),
detail::get_or_ignore<field::ref_id>(record_buffer),
detail::get_or_ignore<field::ref_offset>(record_buffer),
detail::get_or_ignore<field::cigar>(record_buffer),
detail::get_or_ignore<field::flag>(record_buffer),
detail::get_or_ignore<field::mapq>(record_buffer),
detail::get_or_ignore<field::mate>(record_buffer),
detail::get_or_ignore<field::tags>(record_buffer),
detail::get_or_ignore<field::evalue>(record_buffer),
detail::get_or_ignore<field::bit_score>(record_buffer));
},
format);
};
assert(!format.valueless_by_exception());
if constexpr (!std::same_as<typename traits_type::ref_sequences, ref_info_not_given>)
call_read_func(*reference_sequences_ptr);
else
call_read_func(std::ignore);
}
friend iterator;
};
template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_ids>
sam_file_input(stream_type && stream, file_format const &, selected_field_ids const &)
-> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
selected_field_ids,
type_list<file_format>>;
template <input_stream stream_type, sam_file_input_format file_format, detail::fields_specialisation selected_field_ids>
sam_file_input(stream_type & stream, file_format const &, selected_field_ids const &)
-> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
selected_field_ids,
type_list<file_format>>;
template <input_stream stream_type, sam_file_input_format file_format>
sam_file_input(stream_type && stream, file_format const &)
-> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
typename sam_file_input<>::selected_field_ids, // actually use the default
type_list<file_format>>;
template <input_stream stream_type, sam_file_input_format file_format>
sam_file_input(stream_type & stream, file_format const &)
-> sam_file_input<typename sam_file_input<>::traits_type, // actually use the default
typename sam_file_input<>::selected_field_ids, // actually use the default
type_list<file_format>>;
template <std::ranges::forward_range ref_ids_t,
std::ranges::forward_range ref_sequences_t,
detail::fields_specialisation selected_field_ids>
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>; // actually use the default
template <std::ranges::forward_range ref_ids_t, std::ranges::forward_range ref_sequences_t>
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, // actually use the default
typename sam_file_input<>::valid_formats>; // actually use the default
template <input_stream stream_type,
std::ranges::forward_range ref_ids_t,
std::ranges::forward_range ref_sequences_t,
sam_file_input_format file_format,
detail::fields_specialisation selected_field_ids>
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>>;
template <input_stream stream_type,
std::ranges::forward_range ref_ids_t,
std::ranges::forward_range ref_sequences_t,
sam_file_input_format file_format,
detail::fields_specialisation selected_field_ids>
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>>;
template <input_stream stream_type,
std::ranges::forward_range ref_ids_t,
std::ranges::forward_range ref_sequences_t,
sam_file_input_format file_format>
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, // actually use the default
type_list<file_format>>;
template <input_stream stream_type,
std::ranges::forward_range ref_ids_t,
std::ranges::forward_range ref_sequences_t,
sam_file_input_format file_format>
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, // actually use the default
type_list<file_format>>;
} // namespace seqan3
aa27.hpp
Provides seqan3::aa27, container aliases and string literals.
cigar.hpp
Provides the seqan3::cigar alphabet.
std::basic_ifstream
std::basic_string
cassert
char.hpp
Provides alphabet adaptations for standard char types.
seqan3::dna15
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition dna15.hpp:48
seqan3::dna5
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition dna5.hpp:48
seqan3::phred42
Quality type for traditional Sanger and modern Illumina Phred scores.
Definition phred42.hpp:44
seqan3::sam_file_header
Stores the header information of SAM/BAM files.
Definition header.hpp:47
seqan3::sam_file_input_format
The generic concept for alignment file input formats.
Definition sam_file/input_format_concept.hpp:146
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::end
sentinel end() noexcept
Returns a sentinel for comparison with iterator.
Definition sam_file/input.hpp:644
seqan3::sam_file_input::size_type
size_t size_type
An unsigned integer type, usually std::size_t.
Definition sam_file/input.hpp:393
seqan3::sam_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 sam_file/input.hpp:292
seqan3::sam_file_input::const_reference
void const_reference
The const_reference type is void because files are not const-iterable.
Definition sam_file/input.hpp:391
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::valid_formats
valid_formats_ valid_formats
A seqan3::type_list with the possible formats.
Definition sam_file/input.hpp:247
seqan3::sam_file_input::stream_char_type
char stream_char_type
Character type of the stream(s).
Definition sam_file/input.hpp:249
seqan3::sam_file_input::iterator
detail::in_file_iterator< sam_file_input > iterator
The iterator type of this view (an input iterator).
Definition sam_file/input.hpp:397
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::sam_file_input
sam_file_input(std::filesystem::path filename, selected_field_ids const &fields_tag=selected_field_ids{})
Construct from filename.
Definition sam_file/input.hpp:437
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::sentinel
std::default_sentinel_t sentinel
The type returned by end().
Definition sam_file/input.hpp:401
seqan3::sam_file_input::sam_file_input
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:555
seqan3::sam_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 sam_file/input.hpp:273
seqan3::sam_file_input::ref_offset_type
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:299
seqan3::sam_file_input::traits_type
traits_type_ traits_type
A traits type that defines aliases and template for storage of the fields.
Definition sam_file/input.hpp:243
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::options
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:679
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::sam_file_input
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:465
seqan3::sam_file_input::header_type
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:311
seqan3::sam_file_input::id_type
typename traits_type::template id_container< char > id_type
The type of field::id (default std::string by default).
Definition sam_file/input.hpp:275
seqan3::sam_file_input::operator=
sam_file_input & operator=(sam_file_input &&)=default
Move assignment is defaulted.
seqan3::sam_file_input::field_ids
fields< field::seq, field::id, field::ref_id, field::ref_offset, field::cigar, field::mapq, field::qual, field::flag, field::mate, field::tags, field::header_ptr > field_ids
The subset of seqan3::field tags valid for this file; order corresponds to the types in field_types.
Definition sam_file/input.hpp:345
seqan3::sam_file_input::sam_file_input
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:570
seqan3::sam_file_input::sam_file_input
sam_file_input()=delete
Default constructor is explicitly deleted, you need to give a stream or file name.
seqan3::sam_file_input::begin
iterator begin()
Returns an iterator to current position in the file.
Definition sam_file/input.hpp:619
seqan3::sam_file_input::field_types
type_list< sequence_type, id_type, ref_id_type, ref_offset_type, std::vector< cigar >, mapq_type, quality_type, flag_type, mate_type, sam_tag_dictionary, header_type * > field_types
The previously defined types aggregated in a seqan3::type_list.
Definition sam_file/input.hpp:314
seqan3::sam_file_input::selected_field_ids
selected_field_ids_ selected_field_ids
A seqan3::fields list with the fields selected for the record.
Definition sam_file/input.hpp:245
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::record_type
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:378
seqan3::sam_file_input::reference
record_type & reference
The reference type.
Definition sam_file/input.hpp:389
seqan3::sam_file_input::sam_file_input
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:512
seqan3::sam_file_input::operator=
sam_file_input & operator=(sam_file_input const &)=delete
Copy assignment is explicitly deleted because you cannot have multiple access to the same file.
seqan3::sam_file_input::sam_file_input
sam_file_input(sam_file_input &&)=default
Move construction is defaulted.
seqan3::sam_file_input::cigar_type
std::vector< cigar > cigar_type
The type of field::cigar is fixed to std::vector<cigar>.
Definition sam_file/input.hpp:307
seqan3::sam_file_input::const_iterator
void const_iterator
The const iterator type is void because files are not const-iterable.
Definition sam_file/input.hpp:399
seqan3::sam_file_input::value_type
record_type value_type
The value_type is the record_type.
Definition sam_file/input.hpp:387
seqan3::sam_file_input::difference_type
std::make_signed_t< size_t > difference_type
A signed integer type, usually std::ptrdiff_t.
Definition sam_file/input.hpp:395
seqan3::sam_file_input::header
header_type & header()
Access the file's header.
Definition sam_file/input.hpp:693
seqan3::sam_file_input::sam_file_input
sam_file_input(sam_file_input const &)=delete
Copy construction is explicitly deleted because you cannot have multiple access to the same file.
seqan3::sam_file_input::mapq_type
uint8_t mapq_type
The type of field::mapq is fixed to uint8_t.
Definition sam_file/input.hpp:301
seqan3::sam_file_input::flag_type
sam_flag flag_type
The type of field::flag is fixed to seqan3::sam_flag.
Definition sam_file/input.hpp:305
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::sam_file_input
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:476
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_file_input::~sam_file_input
~sam_file_input()=default
Destructor is defaulted.
seqan3::sam_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 sam_file/input.hpp:309
seqan3::sam_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 sam_file/input.hpp:282
seqan3::sam_file_input::front
reference front() noexcept
Return the record we are currently at in the file.
Definition sam_file/input.hpp:672
seqan3::sam_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 sam_file/input.hpp:303
seqan3::sam_file_input::sam_file_input
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.
seqan3::sam_record
The record type of seqan3::sam_file_input.
Definition sam_file/record.hpp:26
seqan3::sam_tag_dictionary
The SAM tag dictionary class that stores all optional SAM fields.
Definition sam_tag_dictionary.hpp:327
std::conditional_t
std::vector::data
T data(T... args)
std::declval
T declval(T... args)
dna15.hpp
Provides seqan3::dna15, container aliases and string literals.
dna5.hpp
Provides seqan3::dna5, container aliases and string literals.
filesystem
format_bam.hpp
Provides the seqan3::format_bam.
format_sam.hpp
Provides the seqan3::format_sam.
fstream
std::unique_ptr::get
T get(T... args)
seqan3::sam_flag
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition sam_flag.hpp:73
seqan3::field
field
An enumerator for the fields used in file formats.
Definition record.hpp:60
seqan3::field::flag
@ flag
The alignment flag (bit information), uint16_t value.
Definition record.hpp:84
seqan3::field::ref_offset
@ ref_offset
Sequence (seqan3::field::ref_seq) relative start position (0-based), unsigned value.
Definition record.hpp:81
seqan3::field::alignment
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
Definition record.hpp:78
seqan3::field::cigar
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
Definition record.hpp:87
seqan3::field::mapq
@ mapq
The mapping quality of the seqan3::field::seq alignment, usually a Phred-scaled score.
Definition record.hpp:86
seqan3::field::offset
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
Definition record.hpp:66
seqan3::field::mate
@ mate
The mate pair information given as a std::tuple of reference name, offset and template length.
Definition record.hpp:85
seqan3::field::header_ptr
@ header_ptr
A pointer to the seqan3::sam_file_header object storing header information.
Definition record.hpp:82
seqan3::field::ref_id
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
Definition record.hpp:79
seqan3::field::id
@ id
The identifier, usually a string.
Definition record.hpp:63
seqan3::field::tags
@ tags
The optional tags in the SAM format, stored in a dictionary.
Definition record.hpp:88
seqan3::field::seq
@ seq
The "sequence", usually a range of nucleotides or amino acids.
Definition record.hpp:62
seqan3::field::qual
@ qual
The qualities, usually in Phred score notation.
Definition record.hpp:64
seqan3::list_traits::contains
constexpr bool contains
Whether a type occurs in a type list or not.
Definition type_list/traits.hpp:249
seqan3::views::slice
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:137
seqan3::views::repeat_n
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
in_file_iterator.hpp
Provides the seqan3::detail::in_file_iterator class template.
alphabet
The generic alphabet concept that covers most data types used in ranges.
explicitly_convertible_to
Checks whether from can be explicitly converted to to.
sam_file_input_traits
The requirements a traits_type for seqan3::sam_file_input must meet.
sam_file_input_traits::sequence_container
using sequence_container
Type template of the seqan3::field::seq, a container template over sequence_alphabet; must model seqa...
sequence_container
A more refined container concept than seqan3::container.
writable_alphabet
Refines seqan3::alphabet and adds assignability.
writable_quality_alphabet
A concept that indicates whether a writable alphabet represents quality scores.
exception.hpp
Provides exceptions used in the I/O module.
concept.hpp
Stream concepts.
std::make_signed_t
std::make_unique
T make_unique(T... args)
misc_input.hpp
Provides various utility functions required only for input.
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std
SeqAn specific customisations in the standard namespace.
std::basic_ifstream::open
T open(T... args)
std::optional
std::filesystem::path
phred42.hpp
Provides seqan3::phred42 quality scores.
qualified.hpp
Provides quality alphabet composites.
std::remove_reference_t
repeat_n.hpp
Provides seqan3::views::repeat_n.
input_format_concept.hpp
Provides seqan3::sam_file_input_format and auxiliary classes.
record.hpp
Provides seqan3::sam_record.
sam_flag.hpp
Provides helper data structures for the seqan3::sam_file_output.
std::vector::size
T size(T... args)
slice.hpp
Provides seqan3::views::slice.
string
seqan3::fields
A class template that holds a choice of seqan3::field.
Definition record.hpp:125
seqan3::file_open_error
Thrown if there is an unspecified filesystem or stream error while opening, e.g. permission problem.
Definition io/exception.hpp:36
seqan3::sam_file_input_default_traits
The default traits for seqan3::sam_file_input.
Definition sam_file/input.hpp:168
seqan3::sam_file_input_default_traits::quality_container
std::vector< _quality_alphabet > quality_container
The string type for a quality annotation is std::vector.
Definition sam_file/input.hpp:193
seqan3::sam_file_input_default_traits::id_container
std::basic_string< _id_alphabet > id_container
The string type for an identifier is std::basic_string.
Definition sam_file/input.hpp:186
seqan3::sam_file_input_default_traits::ref_ids
ref_ids_t ref_ids
The type of the reference identifiers is deduced on construction.
Definition sam_file/input.hpp:199
seqan3::sam_file_input_default_traits::sequence_alphabet
dna5 sequence_alphabet
The sequence alphabet is seqan3::dna5.
Definition sam_file/input.hpp:175
seqan3::sam_file_input_default_traits::sequence_container
std::vector< _sequence_alphabet > sequence_container
The container for a sequence is std::vector.
Definition sam_file/input.hpp:182
seqan3::sam_file_input_default_traits::sequence_legal_alphabet
dna15 sequence_legal_alphabet
The legal sequence alphabet for parsing is seqan3::dna15.
Definition sam_file/input.hpp:178
seqan3::sam_file_input_default_traits::ref_sequences
ref_sequences_t ref_sequences
The type of the reference sequences is deduced on construction.
Definition sam_file/input.hpp:196
seqan3::sam_file_input_default_traits::quality_alphabet
phred42 quality_alphabet
The alphabet for a quality annotation is seqan3::phred42.
Definition sam_file/input.hpp:189
seqan3::sam_file_input_options
The options type defines various option members that influence the behaviour of all or some formats.
Definition sam_file/input_options.hpp:26
seqan3::type_list
Type that contains multiple types.
Definition type_list.hpp:26
transformation_trait_or.hpp
Provides seqan3::detail::transformation_trait_or.
std::tuple
traits.hpp
Provides traits for seqan3::type_list.
concept.hpp
Provides seqan3::tuple_like.
variant
vector
std::visit
T visit(T... args)
Hide me