SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
policy_alignment_result_builder.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 
21 namespace seqan3::detail
22 {
23 
34 template <typename alignment_configuration_t>
35  requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
36 class policy_alignment_result_builder
37 {
38 protected:
40  using traits_type = alignment_configuration_traits<alignment_configuration_t>;
42  using result_type = typename traits_type::alignment_result_type;
43 
44  static_assert(!std::same_as<result_type, empty_type>, "The alignment result type was not configured.");
45 
49  policy_alignment_result_builder() = default;
50  policy_alignment_result_builder(policy_alignment_result_builder const &) = default;
51  policy_alignment_result_builder(policy_alignment_result_builder &&) = default;
52  policy_alignment_result_builder & operator=(policy_alignment_result_builder const &) = default;
53  policy_alignment_result_builder & operator=(policy_alignment_result_builder &&) = default;
54  ~policy_alignment_result_builder() = default;
55 
59  policy_alignment_result_builder(alignment_configuration_t const & SEQAN3_DOXYGEN_ONLY(config))
60  {}
62 
87  template <typename sequence_pair_t,
88  typename index_t,
89  typename score_t,
90  typename matrix_coordinate_t,
91  typename alignment_matrix_t,
92  typename callback_t>
93  requires std::invocable<callback_t, result_type>
94  void make_result_and_invoke([[maybe_unused]] sequence_pair_t && sequence_pair,
95  [[maybe_unused]] index_t && id,
96  [[maybe_unused]] score_t score,
97  [[maybe_unused]] matrix_coordinate_t end_positions,
98  [[maybe_unused]] alignment_matrix_t const & alignment_matrix,
99  callback_t && callback)
100  {
101  using std::get;
102  using invalid_t = std::nullopt_t *;
103 
104  result_type result{};
105 
106  if constexpr (traits_type::output_sequence1_id)
107  result.data.sequence1_id = id;
108 
109  if constexpr (traits_type::output_sequence2_id)
110  result.data.sequence2_id = id;
111 
112  if constexpr (traits_type::compute_score)
113  {
114  static_assert(!std::same_as<decltype(result.data.score), invalid_t>,
115  "Invalid configuration. Expected result with score!");
116  result.data.score = std::move(score);
117  }
118 
119  if constexpr (traits_type::compute_end_positions)
120  {
121  static_assert(!std::same_as<decltype(result.data.end_positions), invalid_t>,
122  "Invalid configuration. Expected result with end positions!");
123 
124  result.data.end_positions.first = end_positions.col;
125  result.data.end_positions.second = end_positions.row;
126  }
127 
128  if constexpr (traits_type::requires_trace_information)
129  {
130  aligned_sequence_builder builder{get<0>(sequence_pair), get<1>(sequence_pair)};
131  auto aligned_sequence_result = builder(alignment_matrix.trace_path(end_positions));
132 
133  if constexpr (traits_type::compute_begin_positions)
134  {
135  result.data.begin_positions.first = aligned_sequence_result.first_sequence_slice_positions.first;
136  result.data.begin_positions.second = aligned_sequence_result.second_sequence_slice_positions.first;
137  }
138  }
139 
140  callback(std::move(result));
141  }
142 };
143 } // 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.
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
@ 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:415
Provides type traits for working with templates.