SeqAn3
align_result.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 <functional>
43 #include <optional>
44 #include <tuple>
45 
47 
48 namespace seqan3
49 {
50 
54 enum struct align_result_key : uint8_t
55 {
56  id, // cannot be set by the config
57  score, // report the score
58  end, // report the end position and score
59  begin, // report the begin and end position and score
60  trace // report the full trace and begin and end and score
61 };
62 
68 template <typename output_type_list_t>
69 struct align_result
70  : public detail::transfer_template_args_onto_t<output_type_list_t, std::tuple>
72 {
73 
74  static_assert(meta::size<output_type_list_t>::value >= 2,
75  "Logic error: This class requires at least a type list with two template arguments "
76  "for the id and the alignment score");
77 
79  using base_type = detail::transfer_template_args_onto_t<output_type_list_t, std::tuple>;
80 
82  using base_type::base_type;
83 
89  constexpr std::tuple_element_t<0, base_type> id() const noexcept
91  {
92  return std::get<0>(*this);
93  }
94 
96  constexpr std::tuple_element_t<1, base_type> score() const noexcept
97  {
98  return std::get<1>(*this);
99  }
100 
104  constexpr decltype(auto) end_coordinate() const & noexcept
105  {
106  if constexpr (std::tuple_size_v<base_type> < 3)
107  return std::ignore;
108  else
109  return std::get<2>(*this);
110  }
111 
113  constexpr decltype(auto) end_coordinate() const && noexcept
114  {
115  if constexpr (std::tuple_size_v<base_type> < 3)
116  return std::ignore;
117  else //TODO Fix outer move after gcc-7
118  return std::move(std::get<2>(std::move(*this)));
119  }
120 
124  constexpr decltype(auto) begin_coordinate() const & noexcept
125  {
126  if constexpr (std::tuple_size_v<base_type> < 4)
127  return std::ignore;
128  else
129  return std::get<3>(*this);
130  }
131 
133  constexpr decltype(auto) begin_coordinate() const && noexcept
134  {
135  if constexpr (std::tuple_size_v<base_type> < 4)
136  return std::ignore;
137  else //TODO Fix outer move after gcc-7 fix
138  return std::move(std::get<3>(std::move(*this)));
139  }
140 
144  constexpr decltype(auto) trace() const & noexcept
145  {
146  if constexpr (std::tuple_size_v<base_type> < 5)
147  return std::ignore;
148  else
149  return std::get<4>(*this);
150  }
151 
153  constexpr decltype(auto) trace() const && noexcept
154  {
155  if constexpr (std::tuple_size_v<base_type> < 5)
156  return std::ignore;
157  else //TODO Fix outer move after gcc-7 fix
158  return std::move(std::get<4>(std::move(*this)));
159  }
161 };
162 
174 template <align_result_key e, typename output_type_list_t>
175 constexpr auto & get(align_result<output_type_list_t> & align_res) noexcept
176 {
177  constexpr size_t index = static_cast<uint8_t>(e);
178 
179  static_assert(index < std::tuple_size_v<align_result<output_type_list_t>>,
180  "Element access error: index out of range.");
181  return std::get<index>(align_res);
182 }
183 
185 template <align_result_key e, typename output_type_list_t>
186 constexpr auto const & get(align_result<output_type_list_t> const & align_res) noexcept
187 {
188  constexpr size_t index = static_cast<uint8_t>(e);
189 
190  static_assert(index < std::tuple_size_v<align_result<output_type_list_t>>,
191  "Element access error: index out of range.");
192  return std::get<index>(align_res);
193 }
194 
196 template <align_result_key e, typename output_type_list_t>
197 constexpr auto && get(align_result<output_type_list_t> && align_res) noexcept
198 {
199  constexpr size_t index = static_cast<uint8_t>(e);
200 
201  static_assert(index < std::tuple_size_v<align_result<output_type_list_t>>,
202  "Element access error: index out of range.");
203  return std::get<index>(std::move(align_res));
204 }
205 
207 template <align_result_key e, typename output_type_list_t>
208 constexpr auto const && get(align_result<output_type_list_t> const && align_res) noexcept
209 {
210  constexpr size_t index = static_cast<uint8_t>(e);
211 
212  static_assert(index < std::tuple_size_v<align_result<output_type_list_t>>,
213  "Element access error: index of range.");
214 
215  // TODO Remove superfluous outer move after fixed in gcc-7
216  return std::move(std::get<index>(std::move(align_res)));
217 }
219 } // namespace seqan3
220 
221 namespace std
222 {
223 
227 template <size_t idx, typename output_type_list_t>
228 struct tuple_element<idx, seqan3::align_result<output_type_list_t>>
229 {
231  using type = std::tuple_element_t<idx, typename seqan3::align_result<output_type_list_t>::base_type>;
232 };
233 
237 template <typename output_type_list_t>
238 struct tuple_size<seqan3::align_result<output_type_list_t>>
239 {
241  static constexpr size_t value = std::tuple_size_v<typename seqan3::align_result<output_type_list_t>::base_type>;
242 };
243 } // namespace std
constexpr std::tuple_element_t< 1, base_type > score() const noexcept
Returns the score.
Definition: align_result.hpp:96
Provides seqan3::type_list and auxiliary metafunctions.
SeqAn specific customisations in the standard namespace.
Definition: align_result.hpp:221
std::tuple_element_t< idx, typename seqan3::align_result< output_type_list_t >::base_type > type
The element type at the given position.
Definition: align_result.hpp:231
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Stores the alignment results and offers a tuple-like interface.
Definition: align_result.hpp:69
detail::transfer_template_args_onto_t< output_type_list_t, std::tuple > base_type
The base tuple type.
Definition: align_result.hpp:79
align_result_key
Keys for different alignment results.
Definition: align_result.hpp:54