SeqAn3
record.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <tuple>
43 
44 #include <meta/meta.hpp>
45 
48 
49 namespace seqan3
50 {
51 
52 // ----------------------------------------------------------------------------
53 // enum field
54 // ----------------------------------------------------------------------------
55 
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 
135 template <field ...fs>
136 struct fields
137 {
140  static constexpr std::array<field, sizeof...(fs)> as_array{fs...};
141 
143  static constexpr size_t npos = std::numeric_limits<size_t>::max();
144 
146  static constexpr size_t index_of(field f)
147  {
148  for (size_t i = 0; i < sizeof...(fs); ++i)
149  if (as_array[i] == f)
150  return i;
151  return npos;
152  }
153 
155  static constexpr bool contains(field f)
156  {
157  return index_of(f) != npos;
158  }
159 
160  static_assert([] () constexpr
161  {
162  for (size_t i = 0; i < as_array.size(); ++i)
163  for (size_t j = i + 1; j < as_array.size(); ++j)
164  if (as_array[i] == as_array[j])
165  return false;
166 
167  return true;
168  } (), "You may not include a field twice into fields<>.");
169 };
170 
171 // ----------------------------------------------------------------------------
172 // record
173 // ----------------------------------------------------------------------------
174 
207 template <typename field_types, typename field_ids>
208 struct record : detail::transfer_template_args_onto_t<field_types, std::tuple>
209 {
210 public:
212  using base_type = detail::transfer_template_args_onto_t<field_types, std::tuple>;
213 
218  record() = default;
219  record(record const &) = default;
220  record & operator=(record const &) = default;
221  record(record &&) = default;
222  record & operator=(record &&) = default;
223 
225  using base_type::base_type;
227 
228  static_assert(field_types::size() == field_ids::as_array.size(),
229  "You must give as many IDs as types to seqan3::record.");
230 
232  void clear()
233  {
234  clear_impl(*this, std::make_integer_sequence<size_t, field_types::size()>{});
235  }
236 private:
238  template <size_t ...Is>
239  constexpr void clear_impl(base_type & tup, std::integer_sequence<size_t, Is...> const &)
240  {
241  ((std::get<Is>(tup) = {}), ...);
242  }
243 };
244 
245 } // namespace seqan3
246 
247 namespace std
248 {
249 
253 template <typename field_types, typename field_ids>
254 struct tuple_size<seqan3::record<field_types, field_ids>>
255 {
257  static constexpr size_t value = tuple_size_v<typename seqan3::record<field_types, field_ids>::base_type>;
258 };
259 
263 template <size_t elem_no, typename field_types, typename field_ids>
264 struct tuple_element<elem_no, seqan3::record<field_types, field_ids>>
265 {
267  using type = std::tuple_element_t<elem_no, typename seqan3::record<field_types, field_ids>::base_type>;
268 };
269 
270 } // namespace std
271 
272 namespace seqan3
273 {
274 
280 template <field f, typename field_types, typename field_ids>
281 auto & get(record<field_types, field_ids> & r)
282 {
283  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
284  return std::get<field_ids::index_of(f)>(r);
285 }
286 
287 template <field f, typename field_types, typename field_ids>
288 auto const & get(record<field_types, field_ids> const & r)
289 {
290  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
291  return std::get<field_ids::index_of(f)>(r);
292 }
293 
294 template <field f, typename field_types, typename field_ids>
295 auto && get(record<field_types, field_ids> && r)
296 {
297  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
298  return std::get<field_ids::index_of(f)>(std::move(r));
299 }
300 
301 template <field f, typename field_types, typename field_ids>
302 auto const && get(record<field_types, field_ids> const && r)
303 {
304  static_assert(field_ids::contains(f), "The record does not contain the field you wish to retrieve.");
305  return std::get<field_ids::index_of(f)>(std::move(r));
306 }
308 
309 } // namespace seqan3
The (reference) "sequence" information, usually a range of nucleotides or amino acids.
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.
The class template that file records are based on; behaves like an std::tuple.
Definition: record.hpp:208
Provides seqan3::type_list and auxiliary metafunctions.
Comment field of arbitrary content, usually a string.
Identifier for user defined file formats and specialisations.
SeqAn specific customisations in the standard namespace.
Definition: align_result.hpp:221
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:195
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
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:136
Sequence and qualities combined in one range.
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:267
Provides seqan3::type_list and auxiliary metafunctions.
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:232
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.
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.
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:212
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.