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// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
11#pragma once
12
13#include <optional>
14
18
19namespace seqan3::detail
20{
21
22// forward declaration for friend declaration in alignment_result.
23template <typename configuration_t>
24 requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
25class policy_alignment_result_builder;
26
39template <typename sequence1_id_t,
40 typename sequence2_id_t,
41 typename score_t,
42 typename end_positions_t = std::nullopt_t *,
43 typename begin_positions_t = std::nullopt_t *,
44 typename alignment_t = std::nullopt_t *,
45 typename score_debug_matrix_t = std::nullopt_t *,
46 typename trace_debug_matrix_t = std::nullopt_t *>
47struct alignment_result_value_type
48{
50 sequence1_id_t sequence1_id{};
52 sequence2_id_t sequence2_id{};
54 score_t score{};
56 end_positions_t end_positions{};
58 begin_positions_t begin_positions{};
60 alignment_t alignment{};
61
63 score_debug_matrix_t score_debug_matrix{};
65 trace_debug_matrix_t trace_debug_matrix{};
66};
67
73alignment_result_value_type()->alignment_result_value_type<std::nullopt_t *, std::nullopt_t *, std::nullopt_t *>;
74
76template <typename sequence1_id_t, typename sequence2_id_t, typename score_t>
77alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t)
78 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t>;
79
81template <typename sequence1_id_t, typename sequence2_id_t, typename score_t, typename end_positions_t>
82alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t)
83 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t>;
84
86template <typename sequence1_id_t,
87 typename sequence2_id_t,
88 typename score_t,
89 typename end_positions_t,
90 typename begin_positions_t>
91alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t)
92 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t>;
93
95template <typename sequence1_id_t,
96 typename sequence2_id_t,
97 typename score_t,
98 typename end_positions_t,
99 typename begin_positions_t,
100 typename alignment_t>
101alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t, alignment_t)
102 -> alignment_result_value_type<sequence1_id_t,
103 sequence2_id_t,
104 score_t,
105 end_positions_t,
106 begin_positions_t,
107 alignment_t>;
109
111template <typename result_t>
112struct alignment_result_value_type_accessor;
114} // namespace seqan3::detail
115
116namespace seqan3
117{
118
142template <typename alignment_result_value_t>
143 requires detail::is_type_specialisation_of_v<alignment_result_value_t, detail::alignment_result_value_type>
145{
146private:
148 alignment_result_value_t data{};
149
155 using sequence1_id_t = decltype(data.sequence1_id);
157 using sequence2_id_t = decltype(data.sequence2_id);
159 using score_t = decltype(data.score);
161 using end_positions_t = decltype(data.end_positions);
163 using begin_positions_t = decltype(data.begin_positions);
165 using alignment_t = decltype(data.alignment);
167
169 template <typename configuration_t>
170 requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
172
173public:
179
182 alignment_result(alignment_result_value_t value) : data(std::move(value))
183 {}
184
186 alignment_result() = default;
191 ~alignment_result() = default;
192
194
203 constexpr sequence1_id_t sequence1_id() const noexcept
204 {
205 static_assert(!std::is_same_v<sequence1_id_t, std::nullopt_t *>,
206 "Trying to access the id of the first sequence, although it was not requested in the"
207 " alignment configuration.");
208 return data.sequence1_id;
209 }
210
214 constexpr sequence2_id_t sequence2_id() const noexcept
215 {
216 static_assert(!std::is_same_v<sequence2_id_t, std::nullopt_t *>,
217 "Trying to access the id of the second sequence, although it was not requested in the"
218 " alignment configuration.");
219 return data.sequence2_id;
220 }
221
225 constexpr score_t score() const noexcept
226 {
227 static_assert(!std::is_same_v<score_t, std::nullopt_t *>,
228 "Trying to access the score, although it was not requested in the alignment configuration.");
229 return data.score;
230 }
231
246 constexpr auto sequence1_end_position() const noexcept
247 {
248 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
249 "Trying to access the end position of the first sequence, although it was not requested in the"
250 " alignment configuration.");
251 return data.end_positions.first;
252 }
253
268 constexpr auto sequence2_end_position() const noexcept
269 {
270 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
271 "Trying to access the end position of the second sequence, although it was not requested in the"
272 " alignment configuration.");
273 return data.end_positions.second;
274 }
275
292 constexpr auto sequence1_begin_position() const noexcept
293 {
294 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
295 "Trying to access the begin position of the first sequence, although it was not requested in the"
296 " alignment configuration.");
297 return data.begin_positions.first;
298 }
299
316 constexpr auto sequence2_begin_position() const noexcept
317 {
318 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
319 "Trying to access the begin position of the second sequence, although it was not requested in the"
320 " alignment configuration.");
321 return data.begin_positions.second;
322 }
323
330 constexpr alignment_t const & alignment() const noexcept
331 {
332 static_assert(!std::is_same_v<alignment_t, std::nullopt_t *>,
333 "Trying to access the alignment, although it was not requested in the alignment configuration.");
334 return data.alignment;
335 }
337
339
350 constexpr auto const & score_matrix() const noexcept
351 {
352 static_assert(
353 !std::is_same_v<decltype(data.score_debug_matrix), std::nullopt_t *>,
354 "Trying to access the score matrix, although it was not requested in the alignment configuration.");
355 return data.score_debug_matrix;
356 }
357
369 constexpr auto const & trace_matrix() const noexcept
370 {
371 static_assert(
372 !std::is_same_v<decltype(data.trace_debug_matrix), std::nullopt_t *>,
373 "Trying to access the trace matrix, although it was not requested in the alignment configuration.");
374 return data.trace_debug_matrix;
375 }
377};
378} // namespace seqan3
379
380namespace seqan3::detail
381{
392template <typename result_value_t>
393struct alignment_result_value_type_accessor<alignment_result<result_value_t>>
394{
396 using type = result_value_t;
397};
398
399} // namespace seqan3::detail
400
401namespace seqan3
402{
412template <typename char_t, typename alignment_result_t>
413 requires detail::is_type_specialisation_of_v<std::remove_cvref_t<alignment_result_t>, alignment_result>
414inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, alignment_result_t && result)
415{
416 using disabled_t = std::nullopt_t *;
417 using result_data_t =
418 typename detail::alignment_result_value_type_accessor<std::remove_cvref_t<alignment_result_t>>::type;
419
420 constexpr bool has_sequence1_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence1_id), disabled_t>;
421 constexpr bool has_sequence2_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence2_id), disabled_t>;
422 constexpr bool has_score = !std::is_same_v<decltype(std::declval<result_data_t>().score), disabled_t>;
423 constexpr bool has_end_positions =
424 !std::is_same_v<decltype(std::declval<result_data_t>().end_positions), disabled_t>;
425 constexpr bool has_begin_positions =
426 !std::is_same_v<decltype(std::declval<result_data_t>().begin_positions), disabled_t>;
427 constexpr bool has_alignment = !std::is_same_v<decltype(std::declval<result_data_t>().alignment), disabled_t>;
428
429 bool prepend_comma = false;
430 auto append_to_stream = [&](auto &&... args)
431 {
432 ((stream << (prepend_comma ? std::string{", "} : std::string{})) << ... << std::forward<decltype(args)>(args));
433 prepend_comma = true;
434 };
435
436 stream << '{';
437 if constexpr (has_sequence1_id)
438 append_to_stream("sequence1 id: ", result.sequence1_id());
439 if constexpr (has_sequence2_id)
440 append_to_stream("sequence2 id: ", result.sequence2_id());
441 if constexpr (has_score)
442 append_to_stream("score: ", result.score());
443 if constexpr (has_begin_positions)
444 append_to_stream("begin: (", result.sequence1_begin_position(), ",", result.sequence2_begin_position(), ")");
445 if constexpr (has_end_positions)
446 append_to_stream("end: (", result.sequence1_end_position(), ",", result.sequence2_end_position(), ")");
447 if constexpr (has_alignment)
448 append_to_stream("\nalignment:\n", result.alignment());
449 stream << '}';
450
451 return stream;
452}
453} // namespace seqan3
Stores the alignment results and gives access to score, alignment and the front and end positions.
Definition alignment_result.hpp:145
constexpr sequence2_id_t sequence2_id() const noexcept
Returns the alignment identifier of the second sequence.
Definition alignment_result.hpp:214
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:203
constexpr auto sequence2_end_position() const noexcept
Returns the end position of the second sequence of the alignment.
Definition alignment_result.hpp:268
constexpr auto sequence1_begin_position() const noexcept
Returns the begin position of the first sequence of the alignment.
Definition alignment_result.hpp:292
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:330
friend class detail::policy_alignment_result_builder
Befriend alignment result builder.
Definition alignment_result.hpp:171
constexpr auto sequence2_begin_position() const noexcept
Returns the begin position of the second sequence of the alignment.
Definition alignment_result.hpp:316
~alignment_result()=default
Defaulted.
constexpr score_t score() const noexcept
Returns the alignment score.
Definition alignment_result.hpp:225
constexpr auto sequence1_end_position() const noexcept
Returns the end position of the first sequence of the alignment.
Definition alignment_result.hpp:246
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:107
@ 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:26
SeqAn specific customisations in the standard namespace.
Provides type traits for working with templates.
Hide me