SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
alignment_result.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2023, 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
22namespace seqan3::detail
23{
24
25// forward declaration for friend declaration in alignment_result.
26template <typename configuration_t>
27 requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
28class policy_alignment_result_builder;
29
42template <typename sequence1_id_t,
43 typename sequence2_id_t,
44 typename score_t,
45 typename end_positions_t = std::nullopt_t *,
46 typename begin_positions_t = std::nullopt_t *,
47 typename alignment_t = std::nullopt_t *,
48 typename score_debug_matrix_t = std::nullopt_t *,
49 typename trace_debug_matrix_t = std::nullopt_t *>
50struct alignment_result_value_type
51{
53 sequence1_id_t sequence1_id{};
55 sequence2_id_t sequence2_id{};
57 score_t score{};
59 end_positions_t end_positions{};
61 begin_positions_t begin_positions{};
63 alignment_t alignment{};
64
66 score_debug_matrix_t score_debug_matrix{};
68 trace_debug_matrix_t trace_debug_matrix{};
69};
70
76alignment_result_value_type()->alignment_result_value_type<std::nullopt_t *, std::nullopt_t *, std::nullopt_t *>;
77
79template <typename sequence1_id_t, typename sequence2_id_t, typename score_t>
80alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t)
81 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t>;
82
84template <typename sequence1_id_t, typename sequence2_id_t, typename score_t, typename end_positions_t>
85alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t)
86 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t>;
87
89template <typename sequence1_id_t,
90 typename sequence2_id_t,
91 typename score_t,
92 typename end_positions_t,
93 typename begin_positions_t>
94alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t)
95 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t>;
96
98template <typename sequence1_id_t,
99 typename sequence2_id_t,
100 typename score_t,
101 typename end_positions_t,
102 typename begin_positions_t,
103 typename alignment_t>
104alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t, alignment_t)
105 -> alignment_result_value_type<sequence1_id_t,
106 sequence2_id_t,
107 score_t,
108 end_positions_t,
109 begin_positions_t,
110 alignment_t>;
112
114template <typename result_t>
115struct alignment_result_value_type_accessor;
117} // namespace seqan3::detail
118
119namespace seqan3
120{
121
145template <typename alignment_result_value_t>
146 requires detail::is_type_specialisation_of_v<alignment_result_value_t, detail::alignment_result_value_type>
148{
149private:
151 alignment_result_value_t data{};
152
158 using sequence1_id_t = decltype(data.sequence1_id);
160 using sequence2_id_t = decltype(data.sequence2_id);
162 using score_t = decltype(data.score);
164 using end_positions_t = decltype(data.end_positions);
166 using begin_positions_t = decltype(data.begin_positions);
168 using alignment_t = decltype(data.alignment);
170
172 template <typename configuration_t>
173 requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
175
176public:
182
185 alignment_result(alignment_result_value_t value) : data(std::move(value))
186 {}
187
189 alignment_result() = default;
194 ~alignment_result() = default;
195
197
206 constexpr sequence1_id_t sequence1_id() const noexcept
207 {
208 static_assert(!std::is_same_v<sequence1_id_t, std::nullopt_t *>,
209 "Trying to access the id of the first sequence, although it was not requested in the"
210 " alignment configuration.");
211 return data.sequence1_id;
212 }
213
217 constexpr sequence2_id_t sequence2_id() const noexcept
218 {
219 static_assert(!std::is_same_v<sequence2_id_t, std::nullopt_t *>,
220 "Trying to access the id of the second sequence, although it was not requested in the"
221 " alignment configuration.");
222 return data.sequence2_id;
223 }
224
228 constexpr score_t score() const noexcept
229 {
230 static_assert(!std::is_same_v<score_t, std::nullopt_t *>,
231 "Trying to access the score, although it was not requested in the alignment configuration.");
232 return data.score;
233 }
234
249 constexpr auto sequence1_end_position() const noexcept
250 {
251 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
252 "Trying to access the end position of the first sequence, although it was not requested in the"
253 " alignment configuration.");
254 return data.end_positions.first;
255 }
256
271 constexpr auto sequence2_end_position() const noexcept
272 {
273 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
274 "Trying to access the end position of the second sequence, although it was not requested in the"
275 " alignment configuration.");
276 return data.end_positions.second;
277 }
278
295 constexpr auto sequence1_begin_position() const noexcept
296 {
297 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
298 "Trying to access the begin position of the first sequence, although it was not requested in the"
299 " alignment configuration.");
300 return data.begin_positions.first;
301 }
302
319 constexpr auto sequence2_begin_position() const noexcept
320 {
321 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
322 "Trying to access the begin position of the second sequence, although it was not requested in the"
323 " alignment configuration.");
324 return data.begin_positions.second;
325 }
326
333 constexpr alignment_t const & alignment() const noexcept
334 {
335 static_assert(!std::is_same_v<alignment_t, std::nullopt_t *>,
336 "Trying to access the alignment, although it was not requested in the alignment configuration.");
337 return data.alignment;
338 }
340
342
353 constexpr auto const & score_matrix() const noexcept
354 {
355 static_assert(
356 !std::is_same_v<decltype(data.score_debug_matrix), std::nullopt_t *>,
357 "Trying to access the score matrix, although it was not requested in the alignment configuration.");
358 return data.score_debug_matrix;
359 }
360
372 constexpr auto const & trace_matrix() const noexcept
373 {
374 static_assert(
375 !std::is_same_v<decltype(data.trace_debug_matrix), std::nullopt_t *>,
376 "Trying to access the trace matrix, although it was not requested in the alignment configuration.");
377 return data.trace_debug_matrix;
378 }
380};
381} // namespace seqan3
382
383namespace seqan3::detail
384{
395template <typename result_value_t>
396struct alignment_result_value_type_accessor<alignment_result<result_value_t>>
397{
399 using type = result_value_t;
400};
401
402} // namespace seqan3::detail
403
404namespace seqan3
405{
415template <typename char_t, typename alignment_result_t>
416 requires detail::is_type_specialisation_of_v<std::remove_cvref_t<alignment_result_t>, alignment_result>
417inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, alignment_result_t && result)
418{
419 using disabled_t = std::nullopt_t *;
420 using result_data_t =
421 typename detail::alignment_result_value_type_accessor<std::remove_cvref_t<alignment_result_t>>::type;
422
423 constexpr bool has_sequence1_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence1_id), disabled_t>;
424 constexpr bool has_sequence2_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence2_id), disabled_t>;
425 constexpr bool has_score = !std::is_same_v<decltype(std::declval<result_data_t>().score), disabled_t>;
426 constexpr bool has_end_positions =
427 !std::is_same_v<decltype(std::declval<result_data_t>().end_positions), disabled_t>;
428 constexpr bool has_begin_positions =
429 !std::is_same_v<decltype(std::declval<result_data_t>().begin_positions), disabled_t>;
430 constexpr bool has_alignment = !std::is_same_v<decltype(std::declval<result_data_t>().alignment), disabled_t>;
431
432 bool prepend_comma = false;
433 auto append_to_stream = [&](auto &&... args)
434 {
435 ((stream << (prepend_comma ? std::string{", "} : std::string{})) << ... << std::forward<decltype(args)>(args));
436 prepend_comma = true;
437 };
438
439 stream << '{';
440 if constexpr (has_sequence1_id)
441 append_to_stream("sequence1 id: ", result.sequence1_id());
442 if constexpr (has_sequence2_id)
443 append_to_stream("sequence2 id: ", result.sequence2_id());
444 if constexpr (has_score)
445 append_to_stream("score: ", result.score());
446 if constexpr (has_begin_positions)
447 append_to_stream("begin: (", result.sequence1_begin_position(), ",", result.sequence2_begin_position(), ")");
448 if constexpr (has_end_positions)
449 append_to_stream("end: (", result.sequence1_end_position(), ",", result.sequence2_end_position(), ")");
450 if constexpr (has_alignment)
451 append_to_stream("\nalignment:\n", result.alignment());
452 stream << '}';
453
454 return stream;
455}
456} // namespace seqan3
Stores the alignment results and gives access to score, alignment and the front and end positions.
Definition alignment_result.hpp:148
constexpr sequence2_id_t sequence2_id() const noexcept
Returns the alignment identifier of the second sequence.
Definition alignment_result.hpp:217
alignment_result & operator=(alignment_result &&)=default
Defaulted.
alignment_result & operator=(alignment_result const &)=default
Defaulted.
constexpr sequence1_id_t sequence1_id() const noexcept
Returns the alignment identifier of the first sequence.
Definition alignment_result.hpp:206
constexpr auto sequence2_end_position() const noexcept
Returns the end position of the second sequence of the alignment.
Definition alignment_result.hpp:271
constexpr auto sequence1_begin_position() const noexcept
Returns the begin position of the first sequence of the alignment.
Definition alignment_result.hpp:295
alignment_result(alignment_result const &)=default
Defaulted.
constexpr alignment_t const & alignment() const noexcept
Returns the actual alignment, i.e. the base pair matching.
Definition alignment_result.hpp:333
friend class detail::policy_alignment_result_builder
Befriend alignment result builder.
Definition alignment_result.hpp:174
constexpr auto sequence2_begin_position() const noexcept
Returns the begin position of the second sequence of the alignment.
Definition alignment_result.hpp:319
~alignment_result()=default
Defaulted.
constexpr score_t score() const noexcept
Returns the alignment score.
Definition alignment_result.hpp:228
constexpr auto sequence1_end_position() const noexcept
Returns the end position of the first sequence of the alignment.
Definition alignment_result.hpp:249
alignment_result(alignment_result &&)=default
Defaulted.
Provides seqan3::configuration and utility functions.
Provides seqan3::debug_stream and related types.
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:110
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
T is_same_v
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Provides type traits for working with templates.