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:
112  ID SEQAN3_DEPRECATED_310 = id,
113  QUAL SEQAN3_DEPRECATED_310 = qual,
114  SEQ_QUAL SEQAN3_DEPRECATED_310 = seq_qual,
115  OFFSET SEQAN3_DEPRECATED_310 = offset,
116  BPP SEQAN3_DEPRECATED_310 = bpp,
117  STRUCTURE SEQAN3_DEPRECATED_310 = structure,
118  STRUCTURED_SEQ SEQAN3_DEPRECATED_310 = structured_seq,
119  ENERGY SEQAN3_DEPRECATED_310 = energy,
120  REACT SEQAN3_DEPRECATED_310 = react,
121  REACT_ERR SEQAN3_DEPRECATED_310 = react_err,
122  COMMENT SEQAN3_DEPRECATED_310 = comment,
123  ALIGNMENT SEQAN3_DEPRECATED_310 = alignment,
124  REF_ID SEQAN3_DEPRECATED_310 = ref_id,
125  REF_SEQ SEQAN3_DEPRECATED_310 = ref_seq,
126  REF_OFFSET SEQAN3_DEPRECATED_310 = ref_offset,
127  HEADER_PTR SEQAN3_DEPRECATED_310 = header_ptr,
128  FLAG SEQAN3_DEPRECATED_310 = flag,
129  MATE SEQAN3_DEPRECATED_310 = mate,
130  MAPQ SEQAN3_DEPRECATED_310 = mapq,
131  CIGAR SEQAN3_DEPRECATED_310 = cigar,
132  TAGS SEQAN3_DEPRECATED_310 = tags,
133  BIT_SCORE SEQAN3_DEPRECATED_310 = bit_score,
134  EVALUE SEQAN3_DEPRECATED_310 = evalue,
135  USER_DEFINED_0 SEQAN3_DEPRECATED_310 = user_defined_0,
136  USER_DEFINED_1 SEQAN3_DEPRECATED_310 = user_defined_1,
137  USER_DEFINED_2 SEQAN3_DEPRECATED_310 = user_defined_2,
138  USER_DEFINED_3 SEQAN3_DEPRECATED_310 = user_defined_3,
139  USER_DEFINED_4 SEQAN3_DEPRECATED_310 = user_defined_4,
140  USER_DEFINED_5 SEQAN3_DEPRECATED_310 = user_defined_5,
141  USER_DEFINED_6 SEQAN3_DEPRECATED_310 = user_defined_6,
142  USER_DEFINED_7 SEQAN3_DEPRECATED_310 = user_defined_7,
143  USER_DEFINED_8 SEQAN3_DEPRECATED_310 = user_defined_8,
144  USER_DEFINED_9 SEQAN3_DEPRECATED_310 = user_defined_9,
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
Sequence and qualities combined in one range.
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
Identifier for user defined file formats and specialisations.
Base pair probability matrix of interactions, usually a matrix of float numbers.
Sequence (REF_SEQ) relative start position (0-based), unsigned value.
Please use the field name in lower case.
Please use the field name in lower case.
The mate pair information given as a std::tuple of reference name, offset and template length...
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:225
Provides seqan3::type_list and auxiliary type traits.
The identifier, usually a string.
Please use the field name in lower case.
Please use the field name in lower case.
Identifier for user defined file formats and specialisations.
SeqAn specific customisations in the standard namespace.
Please use the field name in lower case.
Identifier for user defined file formats and specialisations.
The main SeqAn3 namespace.
The "sequence", usually a range of nucleotides or amino acids.
Please use the field name in lower case.
Please use the field name in lower case.
The alignment flag (bit information), uint16_t value.
Please use the field name in lower case.
Please use the field name in lower case.
Identifier for user defined file formats and specialisations.
The optional tags in the SAM format, stored in a dictionary.
Please use the field name in lower case.
The qualities, usually in phred-score notation.
Energy of a folded sequence, represented by one float number.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:165
Identifier for user defined file formats and specialisations.
Please use the field name in lower case.
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
Provides seqan3::type_list.
Please use the field name in lower case.
Comment field of arbitrary content, usually a string.
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
void clear()
(Re-)Initialise all tuple elements with {}.
Definition: record.hpp:249
constexpr bool contains
Whether a type occurs in a pack or not.
Definition: traits.hpp:193
Reactivity error values given in a vector corresponding to REACT.
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
Sequence and fixed interactions combined in one range.
Identifier for user defined file formats and specialisations.
T max(T... args)
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:116
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format...
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
Sequence (SEQ) relative start position (0-based), unsigned value.
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
Fixed interactions, usually a string of structure alphabet characters.
The e-value (length normalized bit score), double value.
The (pairwise) alignment stored in an seqan3::alignment object.
The bit score (statistical significance indicator), unsigned value.
Reactivity values of the sequence characters given in a vector of float numbers.
Identifier for user defined file formats and specialisations.
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
Please use the field name in lower case.
Identifier for user defined file formats and specialisations.
field
An enumerator for the fields used in file formats.Some of the fields are shared between formats...
Definition: record.hpp:64
Identifier for user defined file formats and specialisations.
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:185
Please use the field name in lower case.
detail::transfer_template_args_onto_t< field_types, std::tuple > base_type
A specialisation of std::tuple.
Definition: record.hpp:229
Please use the field name in lower case.
Please use the field name in lower case.
Please use the field name in lower case.
The mapping quality of the SEQ alignment, usually a ohred-scaled score.
The identifier of the (reference) sequence that SEQ was aligned to.
Please use the field name in lower case.
A pointer to the seqan3::alignment_file_header object storing header information. ...
Please use the field name in lower case.
Please use the field name in lower case.
Identifier for user defined file formats and specialisations.