SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
align_pairwise.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 
30 #include <seqan3/std/concepts>
31 #include <seqan3/std/ranges>
32 
33 namespace seqan3
34 {
35 
132 template <typename exec_policy_t, typename sequence_t, typename alignment_config_t>
134  requires is_execution_policy_v<exec_policy_t> &&
135  detail::AlignPairwiseSingleInput<std::remove_reference_t<sequence_t>> &&
137  detail::is_type_specialisation_of_v<alignment_config_t, configuration>
139 constexpr auto align_pairwise(exec_policy_t const & exec,
140  sequence_t && seq,
141  alignment_config_t const & config)
142 {
144  "Alignment configuration error: Expects exactly two sequences for pairwise alignments.");
145 
146  static_assert(std::ranges::ViewableRange<std::tuple_element_t<0, std::remove_reference_t<sequence_t>>> &&
148  "Alignment configuration error: The tuple elements must model std::ranges::ViewableRange.");
149 
150  return align_pairwise(exec, std::view::single(std::forward<sequence_t>(seq)), config);
151 }
152 
156 template <typename sequence_t, typename alignment_config_t>
158  requires detail::AlignPairwiseSingleInput<std::remove_reference_t<sequence_t>> &&
160  detail::is_type_specialisation_of_v<alignment_config_t, configuration>
162 constexpr auto align_pairwise(sequence_t && seq, alignment_config_t const & config)
163 {
165  "Alignment configuration error: Expects exactly two sequences for pairwise alignments.");
166 
167  static_assert(std::ranges::ViewableRange<std::tuple_element_t<0, std::remove_reference_t<sequence_t>>> &&
169  "Alignment configuration error: The tuple elements must model std::ranges::ViewableRange.");
170 
171  return align_pairwise(seqan3::seq, std::forward<sequence_t>(seq), config);
172 }
173 
175 template <typename sequence_t, typename alignment_config_t>
176  requires detail::AlignPairwiseRangeInputConcept<sequence_t> &&
177  detail::is_type_specialisation_of_v<alignment_config_t, configuration>
178 constexpr auto align_pairwise(sequence_t && seq, alignment_config_t const & config)
179 {
180  return align_pairwise(seqan3::seq, std::forward<sequence_t>(seq), config);
181 }
182 
183 template <typename exec_policy_t, typename sequence_t, typename alignment_config_t>
184  requires is_execution_policy_v<exec_policy_t> &&
185  detail::AlignPairwiseRangeInputConcept<sequence_t> &&
186  detail::is_type_specialisation_of_v<alignment_config_t, configuration>
187 constexpr auto align_pairwise(exec_policy_t const & exec,
188  sequence_t && seq,
189  alignment_config_t const & config)
190 {
191  using first_seq_t = std::tuple_element_t<0, value_type_t<sequence_t>>;
192  using second_seq_t = std::tuple_element_t<1, value_type_t<sequence_t>>;
193 
195  "Alignment configuration error: The sequence must model RandomAccessRange and SizedRange.");
197  "Alignment configuration error: The sequence must model RandomAccessRange and SizedRange.");
198 
199  // Pipe with view::persist to allow rvalue non-view ranges.
200  auto seq_view = std::forward<sequence_t>(seq) | view::persist;
201  // Configure the alignment algorithm.
202  auto kernel = detail::alignment_configurator::configure<decltype(seq_view)>(config);
203  // Create a two-way executor for the alignment.
204  detail::alignment_executor_two_way executor{std::move(seq_view), kernel, exec};
205  // Return the range over the alignments.
206  return alignment_range{std::move(executor)};
207 }
209 
210 } // namespace seqan3
Meta-header for the pairwise execution submodule .
Specifies the requirements of a Range type that is either a std::ranges::View or an lvalue-reference...
constexpr sequenced_policy seq
Global execution policy object for sequenced execution policy.
Definition: execution.hpp:54
Meta-header for the alignment configuration module .
constexpr auto align_pairwise(exec_policy_t const &exec, 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
Provides execution policies.
Specifies requirements of a Range type for which begin returns a type that models std::RandomAccessIt...
The main SeqAn3 namespace.
The concept std::CopyConstructible is satisfied if T is an lvalue reference type, or if it is a MoveC...
constexpr auto single
Given a value, produces a view that contains exactly one element.
Definition: ranges:756
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
Provides seqan3::alignment_result.
The Concepts library.
Adaptations of concepts from the Ranges TS.
Provides seqan3::detail::alignment_selector.
auto constexpr persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist.hpp:251
T tuple_size_v
Provides various type traits on generic types.
Meta-Header for components of the algorithm submodule.
Provides seqan3::view::persist.