SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
record.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 
63 enum class field
64 {
65  // Fields used in multiple contexts ........................................
66  SEQ,
67  ID,
68  QUAL,
69  SEQ_QUAL,
70  OFFSET,
71 
72  // Fields unique to structure io ...........................................
73  BPP,
74  STRUCTURE,
76  ENERGY,
77  REACT,
78  REACT_ERR,
79  COMMENT,
80 
81  // Fields unique to alignment io ...........................................
82  ALIGNMENT,
83  REF_ID,
84  REF_SEQ,
85  REF_OFFSET,
86  HEADER_PTR,
87 
88  FLAG,
89  MATE,
90  MAPQ,
91  TAGS,
92 
93  BIT_SCORE,
94  EVALUE,
95 
96  // User defined field aliases .. ...........................................
107 };
108 
109 // ----------------------------------------------------------------------------
110 // fields
111 // ----------------------------------------------------------------------------
112 
126 template <field ...fs>
127 struct fields
128 {
131  static constexpr std::array<field, sizeof...(fs)> as_array{fs...};
132 
134  static constexpr size_t npos = std::numeric_limits<size_t>::max();
135 
137  static constexpr size_t index_of(field f)
138  {
139  for (size_t i = 0; i < sizeof...(fs); ++i)
140  if (as_array[i] == f)
141  return i;
142  return npos;
143  }
144 
146  static constexpr bool contains(field f)
147  {
148  return index_of(f) != npos;
149  }
150 
151  static_assert([] () constexpr
152  {
153  for (size_t i = 0; i < as_array.size(); ++i)
154  for (size_t j = i + 1; j < as_array.size(); ++j)
155  if (as_array[i] == as_array[j])
156  return false;
157 
158  return true;
159  } (), "You may not include a field twice into fields<>.");
160 };
161 
162 // ----------------------------------------------------------------------------
163 // record
164 // ----------------------------------------------------------------------------
165 
186 template <typename field_types, typename field_ids>
187 struct record : detail::transfer_template_args_onto_t<field_types, std::tuple>
188 {
189 public:
191  using base_type = detail::transfer_template_args_onto_t<field_types, std::tuple>;
192 
196  record() = default;
197  record(record const &) = default;
198  record & operator=(record const &) = default;
199  record(record &&) = default;
200  record & operator=(record &&) = default;
201  ~record() = default;
202 
204  using base_type::base_type;
206 
207  static_assert(field_types::size() == field_ids::as_array.size(),
208  "You must give as many IDs as types to seqan3::record.");
209 
211  void clear()
212  {
213  clear_impl(*this, std::make_integer_sequence<size_t, field_types::size()>{});
214  }
215 private:
217  template <size_t ...Is>
218  constexpr void clear_impl(base_type & tup, std::integer_sequence<size_t, Is...> const &)
219  {
220  ((std::get<Is>(tup) = {}), ...);
221  }
222 };
223 
224 } // namespace seqan3
225 
226 namespace std
227 {
228 
234 template <typename field_types, typename field_ids>
235 struct tuple_size<seqan3::record<field_types, field_ids>>
236 {
238  static constexpr size_t value = tuple_size_v<typename seqan3::record<field_types, field_ids>::base_type>;
239 };
240 
246 template <size_t elem_no, typename field_types, typename field_ids>
247 struct tuple_element<elem_no, seqan3::record<field_types, field_ids>>
248 {
250  using type = std::tuple_element_t<elem_no, typename seqan3::record<field_types, field_ids>::base_type>;
251 };
252 
253 } // namespace std
254 
255 namespace seqan3
256 {
257 
264 template <field f, typename field_types, typename field_ids>
267 {
268  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
269  return std::get<field_ids::index_of(f)>(r);
270 }
271 
273 template <field f, typename field_types, typename field_ids>
274 auto const & get(record<field_types, field_ids> const & r)
275 {
276  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
277  return std::get<field_ids::index_of(f)>(r);
278 }
279 
281 template <field f, typename field_types, typename field_ids>
283 {
284  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
285  return std::get<field_ids::index_of(f)>(std::move(r));
286 }
287 
289 template <field f, typename field_types, typename field_ids>
290 auto const && get(record<field_types, field_ids> const && r)
291 {
292  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
293  return std::get<field_ids::index_of(f)>(std::move(r));
294 }
296 
297 } // namespace seqan3
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
~record()=default
Defaulted.
The "sequence", usually a range of nucleotides or amino acids.
Sequence and fixed interactions combined in one range.
Energy of a folded sequence, represented by one float number.
The (pairwise) alignment stored in an seqan3::alignment object.
The alignment flag (bit information), uint16_t value.
record()=default
Defaulted.
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:187
Provides seqan3::type_list and auxiliary type traits.
Comment field of arbitrary content, usually a string.
Identifier for user defined file formats and specialisations.
SeqAn specific customisations in the standard namespace.
Identifier for user defined file formats and specialisations.
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
Identifier for user defined file formats and specialisations.
The qualities, usually in phred-score notation.
The e-value (length normalized bit score), double value.
Base pair probability matrix of interactions, usually a matrix of float numbers.
Sequence (REF_SEQ) relative start position (0-based), unsigned value.
A class template that holds a choice of seqan3::field.
Definition: record.hpp:127
Sequence and qualities combined in one range.
record & operator=(record const &)=default
Defaulted.
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:250
Provides seqan3::type_list and auxiliary type traits.
Reactivity error values given in a vector corresponding to REACT.
Identifier for user defined file formats and specialisations.
Sequence (SEQ) relative start position (0-based), unsigned value.
The identifier, usually a string.
void clear()
(Re-)Initialise all tuple elements with {}.
Definition: record.hpp:211
The mate pair information given as a std::tuple of reference name, offset and template length...
Fixed interactions, usually a string of structure alphabet characters.
The identifier of the (reference) sequence that SEQ was aligned to.
T max(T... args)
A pointer to the seqan3::alignment_file_header object storing header information. ...
Identifier for user defined file formats and specialisations.
Identifier for user defined file formats and specialisations.
T size(T... args)
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:63
The optional tags in the SAM format, stored in a dictionary.
detail::transfer_template_args_onto_t< field_types, std::tuple > base_type
A specialisation of std::tuple.
Definition: record.hpp:191
Identifier for user defined file formats and specialisations.
Identifier for user defined file formats and specialisations.
Reactivity values of the sequence characters given in a vector of float numbers.
The bit score (statistical significance indicator), unsigned value.
The mapping quality of the SEQ alignment, usually a ohred-scaled score.
Identifier for user defined file formats and specialisations.