SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
align_pairwise.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
15 #include <functional>
16 #include <iostream>
17 #include <tuple>
18 #include <type_traits>
19 
20 #include <meta/meta.hpp>
21 
34 #include <seqan3/std/concepts>
35 #include <seqan3/std/ranges>
36 
37 namespace seqan3
38 {
39 
133 template <typename sequence_t, typename alignment_config_t>
135  requires detail::align_pairwise_single_input<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)
140 {
142  "Alignment configuration error: Expects exactly two sequences for pairwise alignments.");
143 
144  static_assert(std::ranges::viewable_range<std::tuple_element_t<0, std::remove_reference_t<sequence_t>>> &&
145  std::ranges::viewable_range<std::tuple_element_t<1, std::remove_reference_t<sequence_t>>>,
146  "Alignment configuration error: The tuple elements must model std::ranges::viewable_range.");
147 
148  return align_pairwise(std::views::single(std::forward<sequence_t>(seq)), config);
149 }
150 
152 template <typename sequence_t, typename alignment_config_t>
153  requires detail::align_pairwise_range_input<sequence_t> &&
154  detail::is_type_specialisation_of_v<alignment_config_t, configuration>
155 constexpr auto align_pairwise(sequence_t && sequences,
156  alignment_config_t const & config)
157 {
158  using first_seq_t = std::tuple_element_t<0, std::ranges::range_value_t<sequence_t>>;
159  using second_seq_t = std::tuple_element_t<1, std::ranges::range_value_t<sequence_t>>;
160 
161  static_assert(std::ranges::random_access_range<first_seq_t> && std::ranges::sized_range<first_seq_t>,
162  "Alignment configuration error: The sequence must model random_access_range and sized_range.");
163  static_assert(std::ranges::random_access_range<second_seq_t> && std::ranges::sized_range<second_seq_t>,
164  "Alignment configuration error: The sequence must model random_access_range and sized_range.");
165 
166  // Pipe with views::persist to allow rvalue non-view ranges.
167  auto seq_view = std::forward<sequence_t>(sequences) | views::persist;
168  // Configure the alignment algorithm.
169  auto && [algorithm, adapted_config] = detail::alignment_configurator::configure<decltype(seq_view)>(config);
170 
171  using traits_t = detail::alignment_configuration_traits<remove_cvref_t<decltype(adapted_config)>>;
173  constexpr auto get_execution_rule = [] ()
174  {
175  if constexpr (traits_t::is_parallel)
176  return seqan3::par;
177  else
178  return seqan3::seq;
179  };
180 
181  // Create a two-way executor for the alignment.
182  detail::alignment_executor_two_way executor{std::move(seq_view),
183  std::move(algorithm),
184  traits_t::alignments_per_vector,
185  get_execution_rule()};
186  // Return the range over the alignments.
187  return alignment_range{std::move(executor)};
188 }
190 
191 } // namespace seqan3
seqan3::single
The text is a single range.
Definition: concept.hpp:84
seqan3::remove_cvref_t
std::remove_cv_t< std::remove_reference_t< t > > remove_cvref_t
Return the input type with const, volatile and references removed (type trait).
Definition: basic.hpp:35
type_traits.hpp
Provides helper type traits for the configuration and execution of the alignment algorithm.
functional
basic.hpp
Provides various type traits on generic types.
seqan3::views::move
const auto move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
tuple
seqan3::align_pairwise
constexpr auto align_pairwise(sequence_t &&seq, alignment_config_t const &config)
Computes the pairwise alignment for a pair of sequences or a range over sequence pairs.
Definition: align_pairwise.hpp:139
all.hpp
Meta-header for the pairwise execution submodule .
iostream
all.hpp
Meta-Header for components of the algorithm submodule.
execution.hpp
Provides execution policies.
concepts
The Concepts library.
seqan3::views::persist
constexpr auto persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist.hpp:248
seqan3::seq
constexpr sequenced_policy seq
Global execution policy object for sequenced execution policy.
Definition: execution.hpp:54
simd.hpp
Provides seqan3::simd::simd_type.
simd_traits.hpp
Provides seqan3::simd::simd_traits.
seqan3::par
constexpr parallel_policy par
Global execution policy object for parallel execution policy.
Definition: execution.hpp:59
concept.hpp
Provides concepts needed internally for the alignment algorithms.
alignment_configurator.hpp
Provides seqan3::detail::alignment_selector.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
persist.hpp
Provides seqan3::views::persist.
alignment_result.hpp
Provides seqan3::alignment_result.
all.hpp
Meta-header for the alignment configuration module .
ranges
Adaptations of concepts from the Ranges TS.
copy_constructible
The concept std::copy_constructible is satisfied if T is an lvalue reference type,...
std::remove_reference_t
std::tuple_size_v
T tuple_size_v