18 #include <type_traits>
20 #include <meta/meta.hpp>
133 template <
typename sequence_t,
typename alignment_config_t>
135 requires detail::align_pairwise_single_input<sequence_t> &&
136 std::copy_constructible<std::remove_reference_t<sequence_t>> &&
137 detail::is_type_specialisation_of_v<alignment_config_t, configuration>
139 constexpr
auto align_pairwise(sequence_t &&
seq, alignment_config_t
const & config)
143 if constexpr (std::is_lvalue_reference_v<sequence_t>)
150 "Alignment configuration error: Expects exactly two sequences for pairwise alignments.");
154 "Alignment configuration error: The tuple elements must model std::ranges::viewable_range.");
161 template <
typename sequence_t,
typename alignment_config_t>
162 requires detail::align_pairwise_range_input<sequence_t> &&
163 detail::is_type_specialisation_of_v<alignment_config_t, configuration>
165 alignment_config_t
const & config)
167 using first_seq_t = std::tuple_element_t<0, std::ranges::range_value_t<sequence_t>>;
168 using second_seq_t = std::tuple_element_t<1, std::ranges::range_value_t<sequence_t>>;
170 static_assert(std::ranges::random_access_range<first_seq_t> && std::ranges::sized_range<first_seq_t>,
171 "Alignment configuration error: The sequence must model random_access_range and sized_range.");
172 static_assert(std::ranges::random_access_range<second_seq_t> && std::ranges::sized_range<second_seq_t>,
173 "Alignment configuration error: The sequence must model random_access_range and sized_range.");
176 auto seq_view = std::forward<sequence_t>(sequences) |
views::persist;
178 auto && [algorithm, complete_config] = detail::alignment_configurator::configure<decltype(seq_view)>(config);
181 using traits_t = detail::alignment_configuration_traits<complete_config_t>;
183 auto indexed_sequence_chunk_view = views::zip(seq_view, std::views::iota(0))
184 | views::chunk(traits_t::alignments_per_vector);
186 using indexed_sequences_t = decltype(indexed_sequence_chunk_view);
187 using alignment_result_t =
typename traits_t::alignment_result_type;
189 detail::execution_handler_parallel,
190 detail::execution_handler_sequential>;
191 using executor_t = detail::algorithm_executor_blocking<indexed_sequences_t,
194 execution_handler_t>;
197 auto select_execution_handler = [&] ()
199 if constexpr (std::same_as<execution_handler_t, detail::execution_handler_parallel>)
201 auto thread_count = get<align_cfg::parallel>(complete_config).thread_count;
203 throw std::runtime_error{
"You must configure the number of threads in seqan3::align_cfg::parallel."};
205 return execution_handler_t{*thread_count};
209 return execution_handler_t{};
213 if constexpr (traits_t::is_one_way_execution)
214 select_execution_handler().bulk_execute(algorithm,
215 indexed_sequence_chunk_view,
216 get<align_cfg::on_result>(complete_config).callback);
218 return algorithm_result_generator_range{executor_t{
std::move(indexed_sequence_chunk_view),
220 alignment_result_t{},
221 select_execution_handler()}};