SeqAn3 3.1.0
The Modern C++ library for sequence analysis.
policy_alignment_result_builder.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
13#pragma once
14
20
21namespace seqan3::detail
22{
23
34template <typename alignment_configuration_t>
35#if !SEQAN3_WORKAROUND_GCC_93467
37 requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
39#endif // !SEQAN3_WORKAROUND_GCC_93467
40class policy_alignment_result_builder
41{
42protected:
44 using traits_type = alignment_configuration_traits<alignment_configuration_t>;
46 using result_type = typename traits_type::alignment_result_type;
47
48 static_assert(!std::same_as<result_type, empty_type>, "The alignment result type was not configured.");
49
53 policy_alignment_result_builder() = default;
54 policy_alignment_result_builder(policy_alignment_result_builder const &) = default;
55 policy_alignment_result_builder(policy_alignment_result_builder &&) = default;
56 policy_alignment_result_builder & operator=(policy_alignment_result_builder const &) = default;
57 policy_alignment_result_builder & operator=(policy_alignment_result_builder &&) = default;
58 ~policy_alignment_result_builder() = default;
59
63 policy_alignment_result_builder(alignment_configuration_t const & SEQAN3_DOXYGEN_ONLY(config))
64 {}
66
91 template <typename sequence_pair_t,
92 typename index_t,
93 typename score_t,
94 typename matrix_coordinate_t,
95 typename alignment_matrix_t,
96 typename callback_t>
98 requires std::invocable<callback_t, result_type>
100 void make_result_and_invoke([[maybe_unused]] sequence_pair_t && sequence_pair,
101 [[maybe_unused]] index_t && id,
102 [[maybe_unused]] score_t score,
103 [[maybe_unused]] matrix_coordinate_t end_positions,
104 [[maybe_unused]] alignment_matrix_t const & alignment_matrix,
105 callback_t && callback)
106 {
107 using std::get;
108 using invalid_t = std::nullopt_t *;
109
110 result_type result{};
111
112 if constexpr (traits_type::output_sequence1_id)
113 result.data.sequence1_id = id;
114
115 if constexpr (traits_type::output_sequence2_id)
116 result.data.sequence2_id = id;
117
118 if constexpr (traits_type::compute_score)
119 {
120 static_assert(!std::same_as<decltype(result.data.score), invalid_t>,
121 "Invalid configuration. Expected result with score!");
122 result.data.score = std::move(score);
123 }
124
125 if constexpr (traits_type::compute_end_positions)
126 {
127 static_assert(!std::same_as<decltype(result.data.end_positions), invalid_t>,
128 "Invalid configuration. Expected result with end positions!");
129
130 result.data.end_positions.first = end_positions.col;
131 result.data.end_positions.second = end_positions.row;
132 }
133
134 if constexpr (traits_type::requires_trace_information)
135 {
136 aligned_sequence_builder builder{get<0>(sequence_pair), get<1>(sequence_pair)};
137 auto aligned_sequence_result = builder(alignment_matrix.trace_path(end_positions));
138
139 if constexpr (traits_type::compute_begin_positions)
140 {
141 result.data.begin_positions.first = aligned_sequence_result.first_sequence_slice_positions.first;
142 result.data.begin_positions.second = aligned_sequence_result.second_sequence_slice_positions.first;
143 }
144 }
145
146 callback(std::move(result));
147 }
148};
149} // namespace seqan3::detail
Provides seqan3::detail::aligned_sequence_builder.
Provides helper type traits for the configuration and execution of the alignment algorithm.
Provides seqan3::configuration and utility functions.
Provides seqan3::detail::empty_type.
@ id
The identifier, usually a string.
constexpr auto const & get(configuration< configs_t... > const &config) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: configuration.hpp:429
Provides type traits for working with templates.