SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
sam_file/record.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 <seqan3/io/record.hpp>
16 
17 namespace seqan3
18 {
27 template <typename field_types, typename field_ids>
28 class sam_record : public record<field_types, field_ids>
29 {
32 
34  using tuple_base_t = typename base_t::base_type;
35 
37  template <field f>
38  using field_constant = typename base_t::template field_constant<f>;
39 
40  using base_t::get_impl;
41 
42 public:
46  sam_record() = default;
47  sam_record(sam_record const &) = default;
48  sam_record & operator=(sam_record const &) = default;
49  sam_record(sam_record &&) = default;
50  sam_record & operator=(sam_record &&) = default;
51  ~sam_record() = default;
52 
54  using base_t::base_t;
56 
60  decltype(auto) id() &&
61  {
62  return get_impl(field_constant<seqan3::field::id>{}, static_cast<tuple_base_t &&>(*this));
63  }
65  decltype(auto) id() const &&
66  {
67  return get_impl(field_constant<seqan3::field::id>{}, static_cast<tuple_base_t const &&>(*this));
68  }
70  decltype(auto) id() &
71  {
72  return get_impl(field_constant<seqan3::field::id>{}, static_cast<tuple_base_t &>(*this));
73  }
75  decltype(auto) id() const &
76  {
77  return get_impl(field_constant<seqan3::field::id>{}, static_cast<tuple_base_t const &>(*this));
78  }
79 
83  decltype(auto) sequence() &&
84  {
85  return get_impl(field_constant<seqan3::field::seq>{}, static_cast<tuple_base_t &&>(*this));
86  }
88  decltype(auto) sequence() const &&
89  {
90  return get_impl(field_constant<seqan3::field::seq>{}, static_cast<tuple_base_t const &&>(*this));
91  }
93  decltype(auto) sequence() &
94  {
95  return get_impl(field_constant<seqan3::field::seq>{}, static_cast<tuple_base_t &>(*this));
96  }
98  decltype(auto) sequence() const &
99  {
100  return get_impl(field_constant<seqan3::field::seq>{}, static_cast<tuple_base_t const &>(*this));
101  }
102 
106  decltype(auto) base_qualities() &&
107  {
108  return get_impl(field_constant<seqan3::field::qual>{}, static_cast<tuple_base_t &&>(*this));
109  }
111  decltype(auto) base_qualities() const &&
112  {
113  return get_impl(field_constant<seqan3::field::qual>{}, static_cast<tuple_base_t const &&>(*this));
114  }
116  decltype(auto) base_qualities() &
117  {
118  return get_impl(field_constant<seqan3::field::qual>{}, static_cast<tuple_base_t &>(*this));
119  }
121  decltype(auto) base_qualities() const &
122  {
123  return get_impl(field_constant<seqan3::field::qual>{}, static_cast<tuple_base_t const &>(*this));
124  }
125 
135  decltype(auto) sequence_position() &&
136  {
137  return get_impl(field_constant<seqan3::field::offset>{}, static_cast<tuple_base_t &&>(*this));
138  }
140  decltype(auto) sequence_position() const &&
141  {
142  return get_impl(field_constant<seqan3::field::offset>{}, static_cast<tuple_base_t const &&>(*this));
143  }
145  decltype(auto) sequence_position() &
146  {
147  return get_impl(field_constant<seqan3::field::offset>{}, static_cast<tuple_base_t &>(*this));
148  }
150  decltype(auto) sequence_position() const &
151  {
152  return get_impl(field_constant<seqan3::field::offset>{}, static_cast<tuple_base_t const &>(*this));
153  }
154 
158  decltype(auto) alignment() &&
159  {
160  return get_impl(field_constant<seqan3::field::alignment>{}, static_cast<tuple_base_t &&>(*this));
161  }
163  decltype(auto) alignment() const &&
164  {
165  return get_impl(field_constant<seqan3::field::alignment>{}, static_cast<tuple_base_t const &&>(*this));
166  }
168  decltype(auto) alignment() &
169  {
170  return get_impl(field_constant<seqan3::field::alignment>{}, static_cast<tuple_base_t &>(*this));
171  }
173  decltype(auto) alignment() const &
174  {
175  return get_impl(field_constant<seqan3::field::alignment>{}, static_cast<tuple_base_t const &>(*this));
176  }
177 
182  decltype(auto) reference_id() &&
183  {
184  return get_impl(field_constant<seqan3::field::ref_id>{}, static_cast<tuple_base_t &&>(*this));
185  }
187  decltype(auto) reference_id() const &&
188  {
189  return get_impl(field_constant<seqan3::field::ref_id>{}, static_cast<tuple_base_t const &&>(*this));
190  }
192  decltype(auto) reference_id() &
193  {
194  return get_impl(field_constant<seqan3::field::ref_id>{}, static_cast<tuple_base_t &>(*this));
195  }
197  decltype(auto) reference_id() const &
198  {
199  return get_impl(field_constant<seqan3::field::ref_id>{}, static_cast<tuple_base_t const &>(*this));
200  }
201 
205  decltype(auto) reference_sequence() = delete;
206 
211  decltype(auto) reference_position() &&
212  {
213  return get_impl(field_constant<seqan3::field::ref_offset>{}, static_cast<tuple_base_t &&>(*this));
214  }
216  decltype(auto) reference_position() const &&
217  {
218  return get_impl(field_constant<seqan3::field::ref_offset>{}, static_cast<tuple_base_t const &&>(*this));
219  }
221  decltype(auto) reference_position() &
222  {
223  return get_impl(field_constant<seqan3::field::ref_offset>{}, static_cast<tuple_base_t &>(*this));
224  }
226  decltype(auto) reference_position() const &
227  {
228  return get_impl(field_constant<seqan3::field::ref_offset>{}, static_cast<tuple_base_t const &>(*this));
229  }
230 
236  decltype(auto) header_ptr() &&
237  {
238  return get_impl(field_constant<seqan3::field::header_ptr>{}, static_cast<tuple_base_t &&>(*this));
239  }
241  decltype(auto) header_ptr() const &&
242  {
243  return get_impl(field_constant<seqan3::field::header_ptr>{}, static_cast<tuple_base_t const &&>(*this));
244  }
246  decltype(auto) header_ptr() &
247  {
248  return get_impl(field_constant<seqan3::field::header_ptr>{}, static_cast<tuple_base_t &>(*this));
249  }
251  decltype(auto) header_ptr() const &
252  {
253  return get_impl(field_constant<seqan3::field::header_ptr>{}, static_cast<tuple_base_t const &>(*this));
254  }
255 
259  decltype(auto) flag() &&
260  {
261  return get_impl(field_constant<seqan3::field::flag>{}, static_cast<tuple_base_t &&>(*this));
262  }
264  decltype(auto) flag() const &&
265  {
266  return get_impl(field_constant<seqan3::field::flag>{}, static_cast<tuple_base_t const &&>(*this));
267  }
269  decltype(auto) flag() &
270  {
271  return get_impl(field_constant<seqan3::field::flag>{}, static_cast<tuple_base_t &>(*this));
272  }
274  decltype(auto) flag() const &
275  {
276  return get_impl(field_constant<seqan3::field::flag>{}, static_cast<tuple_base_t const &>(*this));
277  }
278 
286  decltype(auto) mate_reference_id() &&
287  {
288  return std::get<0>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t &&>(*this)));
289  }
291  decltype(auto) mate_reference_id() const &&
292  {
293  return std::get<0>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t const &&>(*this)));
294  }
296  decltype(auto) mate_reference_id() &
297  {
298  return std::get<0>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t &>(*this)));
299  }
301  decltype(auto) mate_reference_id() const &
302  {
303  return std::get<0>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t const &>(*this)));
304  }
305 
309  decltype(auto) mate_position() &&
310  {
311  return std::get<1>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t &&>(*this)));
312  }
314  decltype(auto) mate_position() const &&
315  {
316  return std::get<1>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t const &&>(*this)));
317  }
319  decltype(auto) mate_position() &
320  {
321  return std::get<1>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t &>(*this)));
322  }
324  decltype(auto) mate_position() const &
325  {
326  return std::get<1>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t const &>(*this)));
327  }
328 
332  decltype(auto) template_length() &&
333  {
334  return std::get<2>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t &&>(*this)));
335  }
337  decltype(auto) template_length() const &&
338  {
339  return std::get<2>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t const &&>(*this)));
340  }
342  decltype(auto) template_length() &
343  {
344  return std::get<2>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t &>(*this)));
345  }
347  decltype(auto) template_length() const &
348  {
349  return std::get<2>(get_impl(field_constant<seqan3::field::mate>{}, static_cast<tuple_base_t const &>(*this)));
350  }
351 
355  decltype(auto) mapping_quality() &&
356  {
357  return get_impl(field_constant<seqan3::field::mapq>{}, static_cast<tuple_base_t &&>(*this));
358  }
360  decltype(auto) mapping_quality() const &&
361  {
362  return get_impl(field_constant<seqan3::field::mapq>{}, static_cast<tuple_base_t const &&>(*this));
363  }
365  decltype(auto) mapping_quality() &
366  {
367  return get_impl(field_constant<seqan3::field::mapq>{}, static_cast<tuple_base_t &>(*this));
368  }
370  decltype(auto) mapping_quality() const &
371  {
372  return get_impl(field_constant<seqan3::field::mapq>{}, static_cast<tuple_base_t const &>(*this));
373  }
374 
378  decltype(auto) cigar_sequence() &&
379  {
380  return get_impl(field_constant<seqan3::field::cigar>{}, static_cast<tuple_base_t &&>(*this));
381  }
383  decltype(auto) cigar_sequence() const &&
384  {
385  return get_impl(field_constant<seqan3::field::cigar>{}, static_cast<tuple_base_t const &&>(*this));
386  }
388  decltype(auto) cigar_sequence() &
389  {
390  return get_impl(field_constant<seqan3::field::cigar>{}, static_cast<tuple_base_t &>(*this));
391  }
393  decltype(auto) cigar_sequence() const &
394  {
395  return get_impl(field_constant<seqan3::field::cigar>{}, static_cast<tuple_base_t const &>(*this));
396  }
397 
401  decltype(auto) tags() &&
402  {
403  return get_impl(field_constant<seqan3::field::tags>{}, static_cast<tuple_base_t &&>(*this));
404  }
406  decltype(auto) tags() const &&
407  {
408  return get_impl(field_constant<seqan3::field::tags>{}, static_cast<tuple_base_t const &&>(*this));
409  }
411  decltype(auto) tags() &
412  {
413  return get_impl(field_constant<seqan3::field::tags>{}, static_cast<tuple_base_t &>(*this));
414  }
416  decltype(auto) tags() const &
417  {
418  return get_impl(field_constant<seqan3::field::tags>{}, static_cast<tuple_base_t const &>(*this));
419  }
420 };
421 } // namespace seqan3
422 
423 namespace std
424 {
425 
431 template <typename field_types, typename field_ids>
432 struct tuple_size<seqan3::sam_record<field_types, field_ids>> :
433  tuple_size<typename seqan3::sam_record<field_types, field_ids>::base_type>
434 {};
435 
441 template <size_t elem_no, typename field_types, typename field_ids>
442 struct tuple_element<elem_no, seqan3::sam_record<field_types, field_ids>> :
443  tuple_element<elem_no, typename seqan3::sam_record<field_types, field_ids>::base_type>
444 {};
445 
446 } // namespace std
The record type of seqan3::sam_file_input.
Definition: sam_file/record.hpp:29
sam_record & operator=(sam_record &&)=default
Defaulted.
decltype(auto) mate_reference_id() &&
The identifier of the (reference) sequence of the mate. (SAM Column ID: RNEXT)
Definition: sam_file/record.hpp:286
decltype(auto) cigar_sequence() &&
The cigar vector representing the alignment. (SAM Column ID: CIGAR)
Definition: sam_file/record.hpp:378
decltype(auto) sequence_position() &&
Sequence (seqan3::sam_record::sequence) relative start position (0-based), unsigned value....
Definition: sam_file/record.hpp:135
decltype(auto) header_ptr() &&
A pointer to the seqan3::sam_file_header object storing header information.
Definition: sam_file/record.hpp:236
decltype(auto) mapping_quality() &&
The mapping quality of the alignment, usually a Phred-scaled score. (SAM Column ID: MAPQ)
Definition: sam_file/record.hpp:355
decltype(auto) reference_position() &&
(Reference) Sequence (seqan3::sam_record::reference_sequence) relative start position (0-based),...
Definition: sam_file/record.hpp:211
sam_record(sam_record const &)=default
Defaulted.
decltype(auto) reference_id() &&
The identifier of the (reference) sequence that seqan3::sam_record::sequence was aligned to....
Definition: sam_file/record.hpp:182
decltype(auto) flag() &&
The alignment flag (bit information), uint16_t value. (SAM Column ID: FLAG)
Definition: sam_file/record.hpp:259
sam_record & operator=(sam_record const &)=default
Defaulted.
decltype(auto) base_qualities() &&
The qualities, usually in Phred score notation. (SAM Column ID: QUAL)
Definition: sam_file/record.hpp:106
decltype(auto) tags() &&
The optional tags in the SAM format.
Definition: sam_file/record.hpp:401
sam_record()=default
Defaulted.
sam_record(sam_record &&)=default
Defaulted.
decltype(auto) mate_position() &&
(Reference) Sequence relative start position (0-based) of the mate. (SAM Column ID: PNEXT)
Definition: sam_file/record.hpp:309
decltype(auto) reference_sequence()=delete
The (reference) "sequence" information, usually a range of nucleotides or amino acids....
~sam_record()=default
Defaulted.
decltype(auto) alignment() &&
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
Definition: sam_file/record.hpp:158
decltype(auto) template_length() &&
The observed template length. (SAM Column ID: TLEN)
Definition: sam_file/record.hpp:332
decltype(auto) id() &&
The identifier, usually a string. (SAM Column ID: QNAME)
Definition: sam_file/record.hpp:60
The generic concept for a (biological) sequence.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Provides the seqan3::record template and the seqan3::field enum.
The class template that file records are based on; behaves like a std::tuple.
Definition: record.hpp:192
detail::transfer_template_args_onto_t< field_types, std::tuple > base_type
A specialisation of std::tuple.
Definition: record.hpp:217