SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
record.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 <tuple>
16 
17 #include <meta/meta.hpp>
18 
21 
22 namespace seqan3
23 {
24 
25 // ----------------------------------------------------------------------------
26 // enum field
27 // ----------------------------------------------------------------------------
28 
64 enum class field
65 {
66  // Fields used in multiple contexts ........................................
67  seq,
68  id,
69  qual,
70  seq_qual,
71  offset,
72 
73  // Fields unique to structure io ...........................................
74  bpp,
75  structure,
77  energy,
78  react,
79  react_err,
80  comment,
81 
82  // Fields unique to alignment io ...........................................
83  alignment,
84  ref_id,
85  ref_seq,
86  ref_offset,
87  header_ptr,
88 
89  flag,
90  mate,
91  mapq,
92  cigar,
93  tags,
94 
95  bit_score,
96  evalue,
97 
98  // User defined field aliases .. ...........................................
109 
110  // deprecated uppercase:
145 };
146 
147 // ----------------------------------------------------------------------------
148 // fields
149 // ----------------------------------------------------------------------------
150 
164 template <field ...fs>
165 struct fields
166 {
169  static constexpr std::array<field, sizeof...(fs)> as_array{fs...};
170 
172  static constexpr size_t npos = std::numeric_limits<size_t>::max();
173 
175  static constexpr size_t index_of(field f)
176  {
177  for (size_t i = 0; i < sizeof...(fs); ++i)
178  if (as_array[i] == f)
179  return i;
180  return npos;
181  }
182 
184  static constexpr bool contains(field f)
185  {
186  return index_of(f) != npos;
187  }
188 
189  static_assert([] () constexpr
190  {
191  for (size_t i = 0; i < as_array.size(); ++i)
192  for (size_t j = i + 1; j < as_array.size(); ++j)
193  if (as_array[i] == as_array[j])
194  return false;
195 
196  return true;
197  } (), "You may not include a field twice into fields<>.");
198 };
199 
200 // ----------------------------------------------------------------------------
201 // record
202 // ----------------------------------------------------------------------------
203 
224 template <typename field_types, typename field_ids>
225 struct record : detail::transfer_template_args_onto_t<field_types, std::tuple>
226 {
227 public:
229  using base_type = detail::transfer_template_args_onto_t<field_types, std::tuple>;
230 
234  record() = default;
235  record(record const &) = default;
236  record & operator=(record const &) = default;
237  record(record &&) = default;
238  record & operator=(record &&) = default;
239  ~record() = default;
240 
242  using base_type::base_type;
244 
245  static_assert(field_types::size() == field_ids::as_array.size(),
246  "You must give as many IDs as types to seqan3::record.");
247 
249  void clear()
250  {
251  clear_impl(*this, std::make_integer_sequence<size_t, field_types::size()>{});
252  }
253 private:
255  template <size_t ...Is>
256  constexpr void clear_impl(base_type & tup, std::integer_sequence<size_t, Is...> const &)
257  {
258  ((std::get<Is>(tup) = {}), ...);
259  }
260 };
261 
262 } // namespace seqan3
263 
264 namespace std
265 {
266 
272 template <typename field_types, typename field_ids>
273 struct tuple_size<seqan3::record<field_types, field_ids>>
274 {
276  static constexpr size_t value = tuple_size_v<typename seqan3::record<field_types, field_ids>::base_type>;
277 };
278 
284 template <size_t elem_no, typename field_types, typename field_ids>
285 struct tuple_element<elem_no, seqan3::record<field_types, field_ids>>
286 {
288  using type = std::tuple_element_t<elem_no, typename seqan3::record<field_types, field_ids>::base_type>;
289 };
290 
291 } // namespace std
292 
293 namespace seqan3
294 {
295 
302 template <field f, typename field_types, typename field_ids>
305 {
306  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
307  return std::get<field_ids::index_of(f)>(r);
308 }
309 
311 template <field f, typename field_types, typename field_ids>
312 auto const & get(record<field_types, field_ids> const & r)
313 {
314  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
315  return std::get<field_ids::index_of(f)>(r);
316 }
317 
319 template <field f, typename field_types, typename field_ids>
321 {
322  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
323  return std::get<field_ids::index_of(f)>(std::move(r));
324 }
325 
327 template <field f, typename field_types, typename field_ids>
328 auto const && get(record<field_types, field_ids> const && r)
329 {
330  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
331  return std::get<field_ids::index_of(f)>(std::move(r));
332 }
334 
335 } // namespace seqan3
std::tuple_element< elem_no, seqan3::record< field_types, field_ids > >::type
std::tuple_element_t< elem_no, typename seqan3::record< field_types, field_ids >::base_type > type
The member type. Delegates to same type on base_type.
Definition: record.hpp:288
seqan3::field::seq_qual
Sequence and qualities combined in one range.
seqan3::record::record
record()=default
Defaulted.
seqan3::record::get
const auto & get(record< field_types, field_ids > const &r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: record.hpp:312
seqan3::field::USER_DEFINED_7
Please use the field name in lower case.
seqan3::field::seq
The "sequence", usually a range of nucleotides or amino acids.
seqan3::field::SEQ
Please use the field name in lower case.
seqan3::field::USER_DEFINED_8
Please use the field name in lower case.
seqan3::field::user_defined_0
Identifier for user defined file formats and specialisations.
seqan3::field::HEADER_PTR
Please use the field name in lower case.
seqan3::field::user_defined_6
Identifier for user defined file formats and specialisations.
seqan3::field::offset
Sequence (SEQ) relative start position (0-based), unsigned value.
seqan3::field::MATE
Please use the field name in lower case.
seqan3::field::bpp
Base pair probability matrix of interactions, usually a matrix of float numbers.
std::make_integer_sequence
seqan3::field::user_defined_2
Identifier for user defined file formats and specialisations.
seqan3::field::REACT
Please use the field name in lower case.
seqan3::field::user_defined_8
Identifier for user defined file formats and specialisations.
std::array::size
T size(T... args)
seqan3::field::FLAG
Please use the field name in lower case.
seqan3::field::USER_DEFINED_5
Please use the field name in lower case.
seqan3::field::id
The identifier, usually a string.
seqan3::field::user_defined_5
Identifier for user defined file formats and specialisations.
seqan3::views::move
const auto move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
seqan3::field::USER_DEFINED_6
Please use the field name in lower case.
seqan3::field::user_defined_3
Identifier for user defined file formats and specialisations.
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
tuple
seqan3::field::structure
Fixed interactions, usually a string of structure alphabet characters.
seqan3::field::STRUCTURED_SEQ
Please use the field name in lower case.
seqan3::field::bit_score
The bit score (statistical significance indicator), unsigned value.
seqan3::field::EVALUE
Please use the field name in lower case.
seqan3::field::ref_seq
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
seqan3::field::ref_offset
Sequence (REF_SEQ) relative start position (0-based), unsigned value.
seqan3::pack_traits::contains
constexpr bool contains
Whether a type occurs in a pack or not.
Definition: traits.hpp:193
seqan3::field::USER_DEFINED_2
Please use the field name in lower case.
seqan3::field::REF_ID
Please use the field name in lower case.
seqan3::fields
A class template that holds a choice of seqan3::field.
Definition: record.hpp:165
SEQAN3_DEPRECATED_310
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:185
seqan3::field::energy
Energy of a folded sequence, represented by one float number.
seqan3::field::COMMENT
Please use the field name in lower case.
seqan3::field::MAPQ
Please use the field name in lower case.
seqan3::field::user_defined_1
Identifier for user defined file formats and specialisations.
seqan3::field::SEQ_QUAL
Please use the field name in lower case.
seqan3::field::cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
seqan3::field::REACT_ERR
Please use the field name in lower case.
seqan3::field::USER_DEFINED_9
Please use the field name in lower case.
seqan3::field::mapq
The mapping quality of the SEQ alignment, usually a ohred-scaled score.
seqan3::field::BPP
Please use the field name in lower case.
seqan3::field::comment
Comment field of arbitrary content, usually a string.
seqan3::field::OFFSET
Please use the field name in lower case.
seqan3::record::get
auto & get(record< field_types, field_ids > &r)
Free function get() for seqan3::record based on seqan3::field.
Definition: record.hpp:304
std::array
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::field::user_defined_7
Identifier for user defined file formats and specialisations.
seqan3::record::clear
void clear()
(Re-)Initialise all tuple elements with {}.
Definition: record.hpp:249
seqan3::record::operator=
record & operator=(record const &)=default
Defaulted.
seqan3::field::tags
The optional tags in the SAM format, stored in a dictionary.
seqan3::field::CIGAR
Please use the field name in lower case.
seqan3::record::get
auto && get(record< field_types, field_ids > &&r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: record.hpp:320
seqan3::field::structured_seq
Sequence and fixed interactions combined in one range.
seqan3::record::get
const auto && get(record< field_types, field_ids > const &&r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: record.hpp:328
seqan3::pack_traits::size
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:116
seqan3::field::ID
Please use the field name in lower case.
seqan3::field::ALIGNMENT
Please use the field name in lower case.
seqan3::field::react
Reactivity values of the sequence characters given in a vector of float numbers.
std
SeqAn specific customisations in the standard namespace.
seqan3::field::user_defined_9
Identifier for user defined file formats and specialisations.
seqan3::field::ref_id
The identifier of the (reference) sequence that SEQ was aligned to.
seqan3::field
field
An enumerator for the fields used in file formats.
Definition: record.hpp:64
seqan3::record
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:225
seqan3::field::USER_DEFINED_4
Please use the field name in lower case.
seqan3::record::base_type
detail::transfer_template_args_onto_t< field_types, std::tuple > base_type
A specialisation of std::tuple.
Definition: record.hpp:229
seqan3::field::REF_SEQ
Please use the field name in lower case.
seqan3::field::REF_OFFSET
Please use the field name in lower case.
seqan3::field::qual
The qualities, usually in phred-score notation.
seqan3::field::react_err
Reactivity error values given in a vector corresponding to REACT.
seqan3::field::STRUCTURE
Please use the field name in lower case.
seqan3::field::ENERGY
Please use the field name in lower case.
seqan3::field::TAGS
Please use the field name in lower case.
seqan3::field::USER_DEFINED_3
Please use the field name in lower case.
seqan3::field::QUAL
Please use the field name in lower case.
seqan3::field::flag
The alignment flag (bit information), uint16_t value.
std::numeric_limits::max
T max(T... args)
seqan3::field::user_defined_4
Identifier for user defined file formats and specialisations.
seqan3::record::~record
~record()=default
Defaulted.
seqan3::field::USER_DEFINED_0
Please use the field name in lower case.
seqan3::field::USER_DEFINED_1
Please use the field name in lower case.
seqan3::field::BIT_SCORE
Please use the field name in lower case.
seqan3::field::header_ptr
A pointer to the seqan3::alignment_file_header object storing header information.
seqan3::field::evalue
The e-value (length normalized bit score), double value.
seqan3::field::alignment
The (pairwise) alignment stored in an seqan3::alignment object.
type_list.hpp
Provides seqan3::type_list.
seqan3::field::mate
The mate pair information given as a std::tuple of reference name, offset and template length.