Loading...
Searching...
No Matches
record.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 <limits>
#include <tuple>
#include <seqan3/core/detail/template_inspection.hpp>
namespace seqan3
{
// ----------------------------------------------------------------------------
// enum field
// ----------------------------------------------------------------------------
enum class field
{
// Fields used in multiple contexts ........................................
seq,
id,
qual,
offset,
// Fields unique to structure io ...........................................
bpp,
structure,
structured_seq,
energy,
react,
react_err,
comment,
// Fields unique to alignment io ...........................................
alignment,
ref_id,
ref_seq,
ref_offset,
header_ptr,
flag,
mate,
mapq,
cigar,
tags,
bit_score,
evalue,
// User defined field aliases .. ...........................................
user_defined_0,
user_defined_1,
user_defined_2,
user_defined_3,
user_defined_4,
user_defined_5,
user_defined_6,
user_defined_7,
user_defined_8,
user_defined_9
};
// ----------------------------------------------------------------------------
// fields
// ----------------------------------------------------------------------------
template <field... fs>
struct fields
{
static constexpr std::array<field, sizeof...(fs)> as_array{fs...};
static constexpr size_t npos = std::numeric_limits<size_t>::max();
static constexpr size_t size = sizeof...(fs);
static constexpr size_t index_of(field f)
{
for (size_t i = 0; i < sizeof...(fs); ++i)
if (as_array[i] == f)
return i;
return npos;
}
static constexpr bool contains(field f)
{
return index_of(f) != npos;
}
static_assert(
[]() constexpr
{
for (size_t i = 0; i < as_array.size(); ++i)
for (size_t j = i + 1; j < as_array.size(); ++j)
if (as_array[i] == as_array[j])
return false;
return true;
}(),
"You may not include a field twice into fields<>.");
};
// ----------------------------------------------------------------------------
// record
// ----------------------------------------------------------------------------
template <typename field_types, typename field_ids>
struct record : detail::transfer_template_args_onto_t<field_types, std::tuple>
{
public:
using base_type = detail::transfer_template_args_onto_t<field_types, std::tuple>;
private:
template <typename t>
requires requires (t & v) { v.clear(); }
static constexpr void clear_element(t & v) noexcept(noexcept(v.clear()))
{
v.clear();
}
template <typename t>
static constexpr void clear_element(t & v) noexcept(noexcept(std::declval<t &>() = t{}))
{
v = {};
}
static constexpr auto expander = [](auto &... args)
{
(clear_element(args), ...);
};
base_type & as_base() noexcept
{
return *this;
}
public:
record() = default;
record(record const &) = default;
record & operator=(record const &) = default;
record(record &&) = default;
record & operator=(record &&) = default;
~record() = default;
using base_type::base_type;
static_assert(field_types::size() == field_ids::as_array.size(),
"You must give as many IDs as types to seqan3::record.");
void clear() noexcept(noexcept(std::apply(expander, std::declval<record &>().as_base())))
{
// PR2165 / __cpp_lib_tuple_like (C++23): std::apply requires tuple-like.
// In C++23, this means std::array, std::pair, std::tuple, and std::ranges::subranges. Nothing else.
// https://en.cppreference.com/w/cpp/utility/tuple/tuple-like
std::apply(expander, as_base());
}
protected:
template <field f>
using field_constant = std::integral_constant<field, f>;
template <field f, typename tuple_t>
static decltype(auto) get_impl(field_constant<f>, tuple_t && record_as_tuple)
{
static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
return std::get<field_ids::index_of(f)>(std::forward<tuple_t>(record_as_tuple));
}
};
} // namespace seqan3
namespace std
{
template <typename field_types, typename field_ids>
struct tuple_size<seqan3::record<field_types, field_ids>> :
tuple_size<typename seqan3::record<field_types, field_ids>::base_type>
{};
template <size_t elem_no, typename field_types, typename field_ids>
struct tuple_element<elem_no, seqan3::record<field_types, field_ids>> :
tuple_element<elem_no, typename seqan3::record<field_types, field_ids>::base_type>
{};
} // namespace std
std::apply
T apply(T... args)
std::array
seqan3::cigar
The seqan3::cigar semialphabet pairs a counter with a seqan3::cigar::operation letter.
Definition alphabet/cigar/cigar.hpp:57
std::declval
T declval(T... args)
std::forward
T forward(T... args)
seqan3::field
field
An enumerator for the fields used in file formats.
Definition record.hpp:60
seqan3::field::energy
@ energy
Energy of a folded sequence, represented by one float number.
Definition record.hpp:72
seqan3::field::comment
@ comment
Comment field of arbitrary content, usually a string.
Definition record.hpp:75
seqan3::field::structure
@ structure
Fixed interactions, usually a string of structure alphabet characters.
Definition record.hpp:70
seqan3::field::bpp
@ bpp
Base pair probability matrix of interactions, usually a matrix of float numbers.
Definition record.hpp:69
seqan3::field::react
@ react
Reactivity values of the sequence characters given in a vector of float numbers.
Definition record.hpp:73
seqan3::field::flag
@ flag
The alignment flag (bit information), uint16_t value.
Definition record.hpp:84
seqan3::field::react_err
@ react_err
Reactivity error values given in a vector corresponding to seqan3::field::react.
Definition record.hpp:74
seqan3::field::ref_offset
@ ref_offset
Sequence (seqan3::field::ref_seq) relative start position (0-based), unsigned value.
Definition record.hpp:81
seqan3::field::ref_seq
@ ref_seq
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
Definition record.hpp:80
seqan3::field::alignment
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
Definition record.hpp:78
seqan3::field::mapq
@ mapq
The mapping quality of the seqan3::field::seq alignment, usually a Phred-scaled score.
Definition record.hpp:86
seqan3::field::user_defined_2
@ user_defined_2
Identifier for user defined file formats and specialisations.
Definition record.hpp:96
seqan3::field::user_defined_5
@ user_defined_5
Identifier for user defined file formats and specialisations.
Definition record.hpp:99
seqan3::field::bit_score
@ bit_score
The bit score (statistical significance indicator), unsigned value.
Definition record.hpp:90
seqan3::field::user_defined_0
@ user_defined_0
Identifier for user defined file formats and specialisations.
Definition record.hpp:94
seqan3::field::user_defined_8
@ user_defined_8
Identifier for user defined file formats and specialisations.
Definition record.hpp:102
seqan3::field::user_defined_3
@ user_defined_3
Identifier for user defined file formats and specialisations.
Definition record.hpp:97
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::user_defined_7
@ user_defined_7
Identifier for user defined file formats and specialisations.
Definition record.hpp:101
seqan3::field::user_defined_4
@ user_defined_4
Identifier for user defined file formats and specialisations.
Definition record.hpp:98
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::structured_seq
@ structured_seq
Sequence and fixed interactions combined in one range.
Definition record.hpp:71
seqan3::field::evalue
@ evalue
The e-value (length normalized bit score), double value.
Definition record.hpp:91
seqan3::field::id
@ id
The identifier, usually a string.
Definition record.hpp:63
seqan3::field::user_defined_6
@ user_defined_6
Identifier for user defined file formats and specialisations.
Definition record.hpp:100
seqan3::field::tags
@ tags
The optional tags in the SAM format, stored in a dictionary.
Definition record.hpp:88
seqan3::field::user_defined_1
@ user_defined_1
Identifier for user defined file formats and specialisations.
Definition record.hpp:95
seqan3::field::user_defined_9
@ user_defined_9
Identifier for user defined file formats and specialisations.
Definition record.hpp:103
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
std::integral_constant
limits
std::numeric_limits::max
T max(T... args)
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std
SeqAn specific customisations in the standard namespace.
seqan3::fields
A class template that holds a choice of seqan3::field.
Definition record.hpp:125
seqan3::record::clear
void clear() noexcept(noexcept(std::apply(expander, std::declval< record & >().as_base())))
Clears containers that provide .clear() and (re-)initialises all other elements with = {}...
Definition record.hpp:242
seqan3::record::record
record(record &&)=default
Defaulted.
seqan3::record::~record
~record()=default
Defaulted.
seqan3::record::base_type
detail::transfer_template_args_onto_t< field_types, std::tuple > base_type
A specialisation of std::tuple.
Definition record.hpp:193
seqan3::record::operator=
record & operator=(record const &)=default
Defaulted.
seqan3::record::record
record()=default
Defaulted.
seqan3::record::operator=
record & operator=(record &&)=default
Defaulted.
seqan3::record::record
record(record const &)=default
Defaulted.
template_inspection.hpp
Provides type traits for working with templates.
tuple
Hide me