SeqAn3 3.2.0-rc.1
The Modern C++ library for sequence analysis.
alignment_result.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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#if !SEQAN3_WORKAROUND_GCC_93467
28 requires is_type_specialisation_of_v<configuration_t, configuration>
29#endif // !SEQAN3_WORKAROUND_GCC_93467
30class policy_alignment_result_builder;
31
44template <typename sequence1_id_t,
45 typename sequence2_id_t,
46 typename score_t,
47 typename end_positions_t = std::nullopt_t *,
48 typename begin_positions_t = std::nullopt_t *,
49 typename alignment_t = std::nullopt_t *,
50 typename score_debug_matrix_t = std::nullopt_t *,
51 typename trace_debug_matrix_t = std::nullopt_t *>
53{
55 sequence1_id_t sequence1_id{};
57 sequence2_id_t sequence2_id{};
59 score_t score{};
61 end_positions_t end_positions{};
63 begin_positions_t begin_positions{};
65 alignment_t alignment{};
66
68 score_debug_matrix_t score_debug_matrix{};
70 trace_debug_matrix_t trace_debug_matrix{};
71};
72
79
81template <typename sequence1_id_t, typename sequence2_id_t, typename score_t>
82alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t)
84
86template <typename sequence1_id_t, typename sequence2_id_t, typename score_t, typename end_positions_t>
87alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t)
89
91template <typename sequence1_id_t,
92 typename sequence2_id_t,
93 typename score_t,
94 typename end_positions_t,
95 typename begin_positions_t>
96alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t)
98
100template <typename sequence1_id_t,
101 typename sequence2_id_t,
102 typename score_t,
103 typename end_positions_t,
104 typename begin_positions_t,
105 typename alignment_t>
106alignment_result_value_type(sequence1_id_t, sequence2_id_t, score_t, end_positions_t, begin_positions_t, alignment_t)
107 -> alignment_result_value_type<sequence1_id_t,
108 sequence2_id_t,
109 score_t,
110 end_positions_t,
111 begin_positions_t,
112 alignment_t>;
114
116template <typename result_t>
117struct alignment_result_value_type_accessor;
119} // namespace seqan3::detail
120
121namespace seqan3
122{
123
147template <typename alignment_result_value_t>
148 requires detail::is_type_specialisation_of_v<alignment_result_value_t, detail::alignment_result_value_type>
150{
151private:
153 alignment_result_value_t data{};
154
160 using sequence1_id_t = decltype(data.sequence1_id);
162 using sequence2_id_t = decltype(data.sequence2_id);
164 using score_t = decltype(data.score);
166 using end_positions_t = decltype(data.end_positions);
168 using begin_positions_t = decltype(data.begin_positions);
170 using alignment_t = decltype(data.alignment);
172
174 template <typename configuration_t>
175#if !SEQAN3_WORKAROUND_GCC_93467
176 requires detail::is_type_specialisation_of_v<configuration_t, configuration>
177#endif // !SEQAN3_WORKAROUND_GCC_93467
179
180public:
186
189 alignment_result(alignment_result_value_t value) : data(std::move(value))
190 {}
191
193 alignment_result() = default;
198 ~alignment_result() = default;
199
201
210 constexpr sequence1_id_t sequence1_id() const noexcept
211 {
212 static_assert(!std::is_same_v<sequence1_id_t, std::nullopt_t *>,
213 "Trying to access the id of the first sequence, although it was not requested in the"
214 " alignment configuration.");
215 return data.sequence1_id;
216 }
217
221 constexpr sequence2_id_t sequence2_id() const noexcept
222 {
223 static_assert(!std::is_same_v<sequence2_id_t, std::nullopt_t *>,
224 "Trying to access the id of the second sequence, although it was not requested in the"
225 " alignment configuration.");
226 return data.sequence2_id;
227 }
228
232 constexpr score_t score() const noexcept
233 {
234 static_assert(!std::is_same_v<score_t, std::nullopt_t *>,
235 "Trying to access the score, although it was not requested in the alignment configuration.");
236 return data.score;
237 }
238
245 constexpr auto sequence1_end_position() const noexcept
246 {
247 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
248 "Trying to access the end position of the first sequence, although it was not requested in the"
249 " alignment configuration.");
250 return data.end_positions.first;
251 }
252
259 constexpr auto sequence2_end_position() const noexcept
260 {
261 static_assert(!std::is_same_v<end_positions_t, std::nullopt_t *>,
262 "Trying to access the end position of the second sequence, although it was not requested in the"
263 " alignment configuration.");
264 return data.end_positions.second;
265 }
266
277 constexpr auto sequence1_begin_position() const noexcept
278 {
279 static_assert(!std::is_same_v<begin_positions_t, std::nullopt_t *>,
280 "Trying to access the begin position of the first sequence, although it was not requested in the"
281 " alignment configuration.");
282 return data.begin_positions.first;
283 }
284
295 constexpr auto sequence2_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 second sequence, although it was not requested in the"
299 " alignment configuration.");
300 return data.begin_positions.second;
301 }
302
309 constexpr alignment_t const & alignment() const noexcept
310 {
311 static_assert(!std::is_same_v<alignment_t, std::nullopt_t *>,
312 "Trying to access the alignment, although it was not requested in the alignment configuration.");
313 return data.alignment;
314 }
316
318
329 constexpr auto const & score_matrix() const noexcept
330 {
331 static_assert(
332 !std::is_same_v<decltype(data.score_debug_matrix), std::nullopt_t *>,
333 "Trying to access the score matrix, although it was not requested in the alignment configuration.");
334 return data.score_debug_matrix;
335 }
336
348 constexpr auto const & trace_matrix() const noexcept
349 {
350 static_assert(
351 !std::is_same_v<decltype(data.trace_debug_matrix), std::nullopt_t *>,
352 "Trying to access the trace matrix, although it was not requested in the alignment configuration.");
353 return data.trace_debug_matrix;
354 }
356};
357} // namespace seqan3
358
359namespace seqan3::detail
360{
371template <typename result_value_t>
372struct alignment_result_value_type_accessor<alignment_result<result_value_t>>
373{
375 using type = result_value_t;
376};
377
378} // namespace seqan3::detail
379
380namespace seqan3
381{
391template <typename char_t, typename alignment_result_t>
392 requires detail::is_type_specialisation_of_v<std::remove_cvref_t<alignment_result_t>, alignment_result>
393inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, alignment_result_t && result)
394{
395 using disabled_t = std::nullopt_t *;
396 using result_data_t =
397 typename detail::alignment_result_value_type_accessor<std::remove_cvref_t<alignment_result_t>>::type;
398
399 constexpr bool has_sequence1_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence1_id), disabled_t>;
400 constexpr bool has_sequence2_id = !std::is_same_v<decltype(std::declval<result_data_t>().sequence2_id), disabled_t>;
401 constexpr bool has_score = !std::is_same_v<decltype(std::declval<result_data_t>().score), disabled_t>;
402 constexpr bool has_end_positions =
403 !std::is_same_v<decltype(std::declval<result_data_t>().end_positions), disabled_t>;
404 constexpr bool has_begin_positions =
405 !std::is_same_v<decltype(std::declval<result_data_t>().begin_positions), disabled_t>;
406 constexpr bool has_alignment = !std::is_same_v<decltype(std::declval<result_data_t>().alignment), disabled_t>;
407
408 bool prepend_comma = false;
409 auto append_to_stream = [&](auto &&... args)
410 {
411 ((stream << (prepend_comma ? std::string{", "} : std::string{})) << ... << std::forward<decltype(args)>(args));
412 prepend_comma = true;
413 };
414
415 stream << '{';
416 if constexpr (has_sequence1_id)
417 append_to_stream("sequence1 id: ", result.sequence1_id());
418 if constexpr (has_sequence2_id)
419 append_to_stream("sequence2 id: ", result.sequence2_id());
420 if constexpr (has_score)
421 append_to_stream("score: ", result.score());
422 if constexpr (has_begin_positions)
423 append_to_stream("begin: (", result.sequence1_begin_position(), ",", result.sequence2_begin_position(), ")");
424 if constexpr (has_end_positions)
425 append_to_stream("end: (", result.sequence1_end_position(), ",", result.sequence2_end_position(), ")");
426 if constexpr (has_alignment)
427 append_to_stream("\nalignment:\n", result.alignment());
428 stream << '}';
429
430 return stream;
431}
432} // namespace seqan3
Stores the alignment results and gives access to score, alignment and the front and end positionss.
Definition: alignment_result.hpp:150
constexpr sequence2_id_t sequence2_id() const noexcept
Returns the alignment identifier of the second sequence.
Definition: alignment_result.hpp:221
alignment_result & operator=(alignment_result &&)=default
Defaulted.
alignment_result & operator=(alignment_result const &)=default
Defaulted.
decltype(data.sequence1_id) sequence1_id_t
The type for the alignment identifier for the first sequence.
Definition: alignment_result.hpp:160
constexpr sequence1_id_t sequence1_id() const noexcept
Returns the alignment identifier of the first sequence.
Definition: alignment_result.hpp:210
alignment_result_value_t data
Object that stores the computed alignment results.
Definition: alignment_result.hpp:153
constexpr auto sequence2_end_position() const noexcept
Returns the end position of the second sequence of the alignment.
Definition: alignment_result.hpp:259
constexpr auto sequence1_begin_position() const noexcept
Returns the begin position of the first sequence of the alignment.
Definition: alignment_result.hpp:277
alignment_result(alignment_result const &)=default
Defaulted.
decltype(data.sequence2_id) sequence2_id_t
The type for the alignment identifier for the second sequence.
Definition: alignment_result.hpp:162
constexpr alignment_t const & alignment() const noexcept
Returns the actual alignment, i.e. the base pair matching.
Definition: alignment_result.hpp:309
constexpr auto sequence2_begin_position() const noexcept
Returns the begin position of the second sequence of the alignment.
Definition: alignment_result.hpp:295
~alignment_result()=default
Defaulted.
constexpr score_t score() const noexcept
Returns the alignment score.
Definition: alignment_result.hpp:232
constexpr auto sequence1_end_position() const noexcept
Returns the end position of the first sequence of the alignment.
Definition: alignment_result.hpp:245
decltype(data.score) score_t
The type for the resulting score.
Definition: alignment_result.hpp:164
decltype(data.end_positions) end_positions_t
The type for the end positions.
Definition: alignment_result.hpp:166
constexpr auto const & score_matrix() const noexcept
Returns the score matrix used to compute the alignment.
Definition: alignment_result.hpp:329
constexpr auto const & trace_matrix() const noexcept
Returns the trace matrix used to compute the alignment.
Definition: alignment_result.hpp:348
alignment_result(alignment_result_value_t value)
Constructs a seqan3::alignment_result from an value_type object.
Definition: alignment_result.hpp:189
alignment_result(alignment_result &&)=default
Defaulted.
decltype(data.alignment) alignment_t
The type for the alignment.
Definition: alignment_result.hpp:170
decltype(data.begin_positions) begin_positions_t
The type for the begin positions.
Definition: alignment_result.hpp:168
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:78
Implements the alignment result builder.
Definition: policy_alignment_result_builder.hpp:39
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
T is_same_v
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
alignment_result_value_type() -> alignment_result_value_type< std::nullopt_t *, std::nullopt_t *, std::nullopt_t * >
Type deduction for an empty object. It will always fail the compilation, if any field is accessed.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
result_value_t type
The underlying value type used for the given alignment result type.
Definition: alignment_result.hpp:375
A struct that contains the actual alignment result data.
Definition: alignment_result.hpp:53
alignment_t alignment
The alignment, i.e. the actual base pair matching.
Definition: alignment_result.hpp:65
begin_positions_t begin_positions
The begin positions of the alignment.
Definition: alignment_result.hpp:63
sequence1_id_t sequence1_id
The alignment identifier for the first sequence.
Definition: alignment_result.hpp:55
trace_debug_matrix_t trace_debug_matrix
The trace matrix. Only accessible with seqan3::align_cfg::detail::debug.
Definition: alignment_result.hpp:70
end_positions_t end_positions
The end positions of the alignment.
Definition: alignment_result.hpp:61
sequence2_id_t sequence2_id
The alignment identifier for the second sequence.
Definition: alignment_result.hpp:57
score_debug_matrix_t score_debug_matrix
The score matrix. Only accessible with seqan3::align_cfg::detail::debug.
Definition: alignment_result.hpp:68
score_t score
The alignment score.
Definition: alignment_result.hpp:59
Provides type traits for working with templates.