SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
alignment_result.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 
14 #pragma once
15 
16 #include <optional>
17 
21 
22 namespace seqan3::detail
23 {
24 
25 // forward declaration for friend declaration in alignment_result.
26 template <typename configuration_t>
27 #if !SEQAN3_WORKAROUND_GCC_93467
28  requires is_type_specialisation_of_v<configuration_t, configuration>
31 #endif // !SEQAN3_WORKAROUND_GCC_93467
32 class policy_alignment_result_builder;
33 
46 template <typename sequence1_id_t,
47  typename sequence2_id_t,
48  typename score_t,
49  typename end_positions_t = std::nullopt_t *,
50  typename begin_positions_t = std::nullopt_t *,
51  typename alignment_t = std::nullopt_t *,
52  typename score_debug_matrix_t = std::nullopt_t *,
53  typename trace_debug_matrix_t = std::nullopt_t *>
54 struct alignment_result_value_type
55 {
57  sequence1_id_t sequence1_id{};
59  sequence2_id_t sequence2_id{};
61  score_t score{};
63  end_positions_t end_positions{};
65  begin_positions_t begin_positions{};
67  alignment_t alignment{};
68 
70  score_debug_matrix_t score_debug_matrix{};
72  trace_debug_matrix_t trace_debug_matrix{};
73 };
74 
79 alignment_result_value_type()
81  -> alignment_result_value_type<std::nullopt_t *, std::nullopt_t *, std::nullopt_t *>;
82 
84 template <typename sequence1_id_t, typename sequence2_id_t, typename score_t>
85 alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t)
86  -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t>;
87 
89 template <typename sequence1_id_t, typename sequence2_id_t, typename score_t, typename end_positions_t>
90 alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t)
91  -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t>;
92 
94 template <typename sequence1_id_t,
95  typename sequence2_id_t,
96  typename score_t,
97  typename end_positions_t,
98  typename begin_positions_t>
99 alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t)
100  -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t>;
101 
103 template <typename sequence1_id_t,
104  typename sequence2_id_t,
105  typename score_t,
106  typename end_positions_t,
107  typename begin_positions_t,
108  typename alignment_t>
109 alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t, alignment_t)
110  -> alignment_result_value_type<sequence1_id_t,
111  sequence2_id_t,
112  score_t,
113  end_positions_t,
114  begin_positions_t,
115  alignment_t>;
117 
119 template <typename result_t>
120 struct alignment_result_value_type_accessor;
122 } // namespace seqan3::detail
123 
124 namespace seqan3
125 {
126 
150 template <typename alignment_result_value_t>
152  requires detail::is_type_specialisation_of_v<alignment_result_value_t, detail::alignment_result_value_type>
155 {
156 private:
158  alignment_result_value_t data{};
159 
164  using sequence1_id_t = decltype(data.sequence1_id);
167  using sequence2_id_t = decltype(data.sequence2_id);
169  using score_t = decltype(data.score);
171  using end_positions_t = decltype(data.end_positions);
173  using begin_positions_t = decltype(data.begin_positions);
175  using alignment_t = decltype(data.alignment);
177 
179  template <typename configuration_t>
180  #if !SEQAN3_WORKAROUND_GCC_93467
181  requires detail::is_type_specialisation_of_v<configuration_t, configuration>
184  #endif // !SEQAN3_WORKAROUND_GCC_93467
185  friend class detail::policy_alignment_result_builder;
186 
187 public:
192 
196  alignment_result(alignment_result_value_t value) : data(std::move(value))
197  {}
198 
200  alignment_result() = default;
201  alignment_result(alignment_result const &) = default;
205  ~alignment_result() = default;
206 
216  constexpr sequence1_id_t sequence1_id() const noexcept
217  {
218  static_assert(!std::is_same_v<sequence1_id_t, std::nullopt_t *>,
219  "Trying to access the id of the first sequence, although it was not requested in the"
220  " alignment configuration.");
221  return data.sequence1_id;
222  }
223 
227  constexpr sequence2_id_t sequence2_id() const noexcept
228  {
229  static_assert(!std::is_same_v<sequence2_id_t, std::nullopt_t *>,
230  "Trying to access the id of the second sequence, although it was not requested in the"
231  " alignment configuration.");
232  return data.sequence2_id;
233  }
234 
238  constexpr score_t score() const noexcept
239  {
240  static_assert(!std::is_same_v<score_t, std::nullopt_t *>,
241  "Trying to access the score, although it was not requested in the alignment configuration.");
242  return data.score;
243  }
244 
251  constexpr auto sequence1_end_position() const noexcept
252  {
253  static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
254  "Trying to access the end position of the first sequence, although it was not requested in the"
255  " alignment configuration.");
256  return data.end_positions.first;
257  }
258 
265  constexpr auto sequence2_end_position() const noexcept
266  {
267  static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
268  "Trying to access the end position of the second sequence, although it was not requested in the"
269  " alignment configuration.");
270  return data.end_positions.second;
271  }
272 
283  constexpr auto sequence1_begin_position() const noexcept
284  {
285  static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
286  "Trying to access the begin position of the first sequence, although it was not requested in the"
287  " alignment configuration.");
288  return data.begin_positions.first;
289  }
290 
301  constexpr auto sequence2_begin_position() const noexcept
302  {
303  static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
304  "Trying to access the begin position of the second sequence, although it was not requested in the"
305  " alignment configuration.");
306  return data.begin_positions.second;
307  }
308 
315  constexpr alignment_t const & alignment() const noexcept
316  {
317  static_assert(!std::is_same_v<alignment_t, std::nullopt_t *>,
318  "Trying to access the alignment, although it was not requested in the alignment configuration.");
319  return data.alignment;
320  }
322 
324 
335  constexpr auto const & score_matrix() const noexcept
336  {
337  static_assert(!std::is_same_v<decltype(data.score_debug_matrix), std::nullopt_t *>,
338  "Trying to access the score matrix, although it was not requested in the alignment configuration.");
339  return data.score_debug_matrix;
340  }
341 
353  constexpr auto const & trace_matrix() const noexcept
354  {
355  static_assert(!std::is_same_v<decltype(data.trace_debug_matrix), std::nullopt_t *>,
356  "Trying to access the trace matrix, although it was not requested in the alignment configuration.");
357  return data.trace_debug_matrix;
358  }
360 };
361 } // namespace seqan3
362 
363 namespace seqan3::detail
364 {
375 template <typename result_value_t>
376 struct alignment_result_value_type_accessor<alignment_result<result_value_t>>
377 {
379  using type = result_value_t;
380 };
381 
382 } // namespace seqan3::detail
383 
384 namespace seqan3
385 {
395 template <typename char_t, typename alignment_result_t>
397  requires detail::is_type_specialisation_of_v<std::remove_cvref_t<alignment_result_t>, alignment_result>
399 inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, alignment_result_t && result)
400 {
401  using disabled_t = std::nullopt_t *;
402  using result_data_t =
403  typename detail::alignment_result_value_type_accessor<std::remove_cvref_t<alignment_result_t>>::type;
404 
405  constexpr bool has_sequence1_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence1_id), disabled_t>;
406  constexpr bool has_sequence2_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence2_id), disabled_t>;
407  constexpr bool has_score = !std::is_same_v<decltype(std::declval<result_data_t>().score), disabled_t>;
408  constexpr bool has_end_positions = !std::is_same_v<decltype(std::declval<result_data_t>().end_positions),
409  disabled_t>;
410  constexpr bool has_begin_positions = !std::is_same_v<decltype(std::declval<result_data_t>().begin_positions),
411  disabled_t>;
412  constexpr bool has_alignment = !std::is_same_v<decltype(std::declval<result_data_t>().alignment), disabled_t>;
413 
414  bool prepend_comma = false;
415  auto append_to_stream = [&] (auto && ...args)
416  {
417  ((stream << (prepend_comma ? std::string{", "} : std::string{})) << ... << std::forward<decltype(args)>(args));
418  prepend_comma = true;
419  };
420 
421  stream << '{';
422  if constexpr (has_sequence1_id)
423  append_to_stream("sequence1 id: ", result.sequence1_id());
424  if constexpr (has_sequence2_id)
425  append_to_stream("sequence2 id: ", result.sequence2_id());
426  if constexpr (has_score)
427  append_to_stream("score: ", result.score());
428  if constexpr (has_begin_positions)
429  append_to_stream("begin: (", result.sequence1_begin_position(), ",", result.sequence2_begin_position(), ")");
430  if constexpr (has_end_positions)
431  append_to_stream("end: (", result.sequence1_end_position(), ",", result.sequence2_end_position(), ")");
432  if constexpr (has_alignment)
433  append_to_stream("\nalignment:\n", result.alignment());
434  stream << '}';
435 
436  return stream;
437 }
438 } // namespace seqan3
seqan3::alignment_result::~alignment_result
~alignment_result()=default
seqan3::alignment_result::alignment_result
alignment_result()=default
std::is_same_v
T is_same_v
seqan3::alignment_result::operator=
alignment_result & operator=(alignment_result const &)=default
Defaulted.
std::string
seqan3::alignment_result::alignment_result
alignment_result(alignment_result const &)=default
Defaulted.
seqan3::alignment_result::sequence2_begin_position
constexpr auto sequence2_begin_position() const noexcept
Returns the begin position of the second sequence of the alignment.
Definition: alignment_result.hpp:301
seqan3::alignment_result::alignment_result
alignment_result(alignment_result &&)=default
Defaulted.
configuration.hpp
Provides seqan3::detail::configuration and utility functions.
seqan3::alignment_result::score
constexpr score_t score() const noexcept
Returns the alignment score.
Definition: alignment_result.hpp:238
seqan3::alignment_result::sequence2_id
constexpr sequence2_id_t sequence2_id() const noexcept
Returns the alignment identifier of the second sequence.
Definition: alignment_result.hpp:227
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
seqan3::alignment_result::operator=
alignment_result & operator=(alignment_result &&)=default
Defaulted.
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
seqan3::alignment_result::sequence1_end_position
constexpr auto sequence1_end_position() const noexcept
Returns the end position of the first sequence of the alignment.
Definition: alignment_result.hpp:251
seqan3::alignment_result
Stores the alignment results and gives access to score, alignment and the front and end positionss.
Definition: alignment_result.hpp:155
seqan3::alignment_result::alignment
constexpr alignment_t const & alignment() const noexcept
Returns the actual alignment, i.e. the base pair matching.
Definition: alignment_result.hpp:315
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
std::nullopt_t
seqan3::alignment_result::sequence1_begin_position
constexpr auto sequence1_begin_position() const noexcept
Returns the begin position of the first sequence of the alignment.
Definition: alignment_result.hpp:283
seqan3::operator<<
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition: debug_stream_alignment.hpp:103
seqan3::alignment_result::sequence2_end_position
constexpr auto sequence2_end_position() const noexcept
Returns the end position of the second sequence of the alignment.
Definition: alignment_result.hpp:265
optional
seqan3::alignment_result::sequence1_id
constexpr sequence1_id_t sequence1_id() const noexcept
Returns the alignment identifier of the first sequence.
Definition: alignment_result.hpp:216