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 <concepts>
14#include <optional>
15
19
20namespace seqan3::detail
21{
22
23// forward declaration for friend declaration in alignment_result.
24template <typename configuration_t>
25 requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
26class policy_alignment_result_builder;
27
40template <typename sequence1_id_t,
41 typename sequence2_id_t,
42 typename score_t,
43 typename end_positions_t = std::nullopt_t *,
44 typename begin_positions_t = std::nullopt_t *,
45 typename alignment_t = std::nullopt_t *,
46 typename score_debug_matrix_t = std::nullopt_t *,
47 typename trace_debug_matrix_t = std::nullopt_t *>
48struct alignment_result_value_type
49{
51 sequence1_id_t sequence1_id{};
53 sequence2_id_t sequence2_id{};
55 score_t score{};
57 end_positions_t end_positions{};
59 begin_positions_t begin_positions{};
61 alignment_t alignment{};
62
64 score_debug_matrix_t score_debug_matrix{};
66 trace_debug_matrix_t trace_debug_matrix{};
67};
68
74alignment_result_value_type() -> alignment_result_value_type<std::nullopt_t *, std::nullopt_t *, std::nullopt_t *>;
75
77template <typename sequence1_id_t, typename sequence2_id_t, typename score_t>
78alignment_result_value_type(sequence1_id_t,
79 sequence2_id_t,
80 score_t) -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t>;
81
83template <typename sequence1_id_t, typename sequence2_id_t, typename score_t, typename end_positions_t>
84alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t)
85 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t>;
86
88template <typename sequence1_id_t,
89 typename sequence2_id_t,
90 typename score_t,
91 typename end_positions_t,
92 typename begin_positions_t>
93alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t)
94 -> alignment_result_value_type<sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t>;
95
97template <typename sequence1_id_t,
98 typename sequence2_id_t,
99 typename score_t,
100 typename end_positions_t,
101 typename begin_positions_t,
102 typename alignment_t>
103alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t, alignment_t)
104 -> alignment_result_value_type<sequence1_id_t,
105 sequence2_id_t,
106 score_t,
107 end_positions_t,
108 begin_positions_t,
109 alignment_t>;
111
113template <typename result_t>
114struct alignment_result_value_type_accessor;
116} // namespace seqan3::detail
117
118namespace seqan3
119{
120
144template <typename alignment_result_value_t>
145 requires detail::is_type_specialisation_of_v<alignment_result_value_t, detail::alignment_result_value_type>
147{
148private:
150 alignment_result_value_t data{};
151
157 using sequence1_id_t = decltype(data.sequence1_id);
159 using sequence2_id_t = decltype(data.sequence2_id);
161 using score_t = decltype(data.score);
163 using end_positions_t = decltype(data.end_positions);
165 using begin_positions_t = decltype(data.begin_positions);
167 using alignment_t = decltype(data.alignment);
169
171 template <typename configuration_t>
172 requires seqan3::detail::is_type_specialisation_of_v<configuration_t, configuration>
174
175 template <typename>
176 friend struct alignment_result_printer;
177
178public:
184
187 alignment_result(alignment_result_value_t value) : data(std::move(value))
188 {}
189
191 alignment_result() = default;
196 ~alignment_result() = default;
197
199
208 constexpr sequence1_id_t sequence1_id() const noexcept
209 {
210 static_assert(!std::is_same_v<sequence1_id_t, std::nullopt_t *>,
211 "Trying to access the id of the first sequence, although it was not requested in the"
212 " alignment configuration.");
213 return data.sequence1_id;
214 }
215
219 constexpr sequence2_id_t sequence2_id() const noexcept
220 {
221 static_assert(!std::is_same_v<sequence2_id_t, std::nullopt_t *>,
222 "Trying to access the id of the second sequence, although it was not requested in the"
223 " alignment configuration.");
224 return data.sequence2_id;
225 }
226
230 constexpr score_t score() const noexcept
231 {
232 static_assert(!std::is_same_v<score_t, std::nullopt_t *>,
233 "Trying to access the score, although it was not requested in the alignment configuration.");
234 return data.score;
235 }
236
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
273 constexpr auto sequence2_end_position() const noexcept
274 {
275 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
276 "Trying to access the end position of the second sequence, although it was not requested in the"
277 " alignment configuration.");
278 return data.end_positions.second;
279 }
280
297 constexpr auto sequence1_begin_position() const noexcept
298 {
299 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
300 "Trying to access the begin position of the first sequence, although it was not requested in the"
301 " alignment configuration.");
302 return data.begin_positions.first;
303 }
304
321 constexpr auto sequence2_begin_position() const noexcept
322 {
323 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
324 "Trying to access the begin position of the second sequence, although it was not requested in the"
325 " alignment configuration.");
326 return data.begin_positions.second;
327 }
328
335 constexpr alignment_t const & alignment() const noexcept
336 {
337 static_assert(!std::is_same_v<alignment_t, std::nullopt_t *>,
338 "Trying to access the alignment, although it was not requested in the alignment configuration.");
339 return data.alignment;
340 }
342
344
355 constexpr auto const & score_matrix() const noexcept
356 {
357 static_assert(
358 !std::is_same_v<decltype(data.score_debug_matrix), std::nullopt_t *>,
359 "Trying to access the score matrix, although it was not requested in the alignment configuration.");
360 return data.score_debug_matrix;
361 }
362
374 constexpr auto const & trace_matrix() const noexcept
375 {
376 static_assert(
377 !std::is_same_v<decltype(data.trace_debug_matrix), std::nullopt_t *>,
378 "Trying to access the trace matrix, although it was not requested in the alignment configuration.");
379 return data.trace_debug_matrix;
380 }
382};
383} // namespace seqan3
384
385namespace seqan3::detail
386{
397template <typename result_value_t>
398struct alignment_result_value_type_accessor<alignment_result<result_value_t>>
399{
401 using type = result_value_t;
402};
403
404} // namespace seqan3::detail
405
406namespace seqan3
407{
408
416template <typename result_value_t>
418{
425 template <typename stream_t, typename arg_t>
426 constexpr void operator()(stream_t & stream, arg_t && arg) const noexcept
427 {
428 using disabled_t = std::nullopt_t *;
429 using result_t = std::remove_cvref_t<arg_t>;
430 constexpr bool has_sequence1_id = !std::is_same_v<typename result_t::sequence1_id_t, disabled_t>;
431 constexpr bool has_sequence2_id = !std::is_same_v<typename result_t::sequence2_id_t, disabled_t>;
432 constexpr bool has_score = !std::is_same_v<typename result_t::score_t, disabled_t>;
433 constexpr bool has_end_positions = !std::is_same_v<typename result_t::end_positions_t, disabled_t>;
434 constexpr bool has_begin_positions = !std::is_same_v<typename result_t::begin_positions_t, disabled_t>;
435 constexpr bool has_alignment = !std::is_same_v<typename result_t::alignment_t, disabled_t>;
436
437 bool prepend_comma = false;
438 auto append_to_stream = [&](auto &&... args)
439 {
440 ((stream << (prepend_comma ? std::string{", "} : std::string{}))
441 << ... << std::forward<decltype(args)>(args));
442 prepend_comma = true;
443 };
444
445 stream << '{';
446 if constexpr (has_sequence1_id)
447 append_to_stream("sequence1 id: ", arg.sequence1_id());
448 if constexpr (has_sequence2_id)
449 append_to_stream("sequence2 id: ", arg.sequence2_id());
450 if constexpr (has_score)
451 append_to_stream("score: ", arg.score());
452 if constexpr (has_begin_positions)
453 append_to_stream("begin: (", arg.sequence1_begin_position(), ",", arg.sequence2_begin_position(), ")");
454 if constexpr (has_end_positions)
455 append_to_stream("end: (", arg.sequence1_end_position(), ",", arg.sequence2_end_position(), ")");
456 if constexpr (has_alignment)
457 append_to_stream("\nalignment:\n", arg.alignment());
458 stream << '}';
459 }
460};
461
462} // namespace seqan3
Stores the alignment results and gives access to score, alignment and the front and end positions.
Definition alignment_result.hpp:147
constexpr sequence2_id_t sequence2_id() const noexcept
Returns the alignment identifier of the second sequence.
Definition alignment_result.hpp:219
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:208
constexpr auto sequence2_end_position() const noexcept
Returns the end position of the second sequence of the alignment.
Definition alignment_result.hpp:273
constexpr auto sequence1_begin_position() const noexcept
Returns the begin position of the first sequence of the alignment.
Definition alignment_result.hpp:297
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:335
friend class detail::policy_alignment_result_builder
Befriend alignment result builder.
Definition alignment_result.hpp:173
constexpr auto sequence2_begin_position() const noexcept
Returns the begin position of the second sequence of the alignment.
Definition alignment_result.hpp:321
~alignment_result()=default
Defaulted.
constexpr score_t score() const noexcept
Returns the alignment score.
Definition alignment_result.hpp:230
constexpr auto sequence1_end_position() const noexcept
Returns the end position of the first sequence of the alignment.
Definition alignment_result.hpp:251
alignment_result(alignment_result &&)=default
Defaulted.
Provides seqan3::configuration and utility functions.
Provides seqan3::debug_stream and related types.
@ 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.
constexpr void operator()(stream_t &stream, arg_t &&arg) const noexcept
Prints the formatted output of the alignment result to the stream.
Definition alignment_result.hpp:426
Definition default_printer.hpp:30
Provides type traits for working with templates.
Hide me