SeqAn3
align_pairwise.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <functional>
43 #include <iostream>
44 #include <tuple>
45 #include <type_traits>
46 
47 #include <meta/meta.hpp>
48 
49 #include <range/v3/view/bounded.hpp>
50 #include <range/v3/view/transform.hpp>
51 #include <range/v3/view/single.hpp>
52 
57 
59 
63 
64 #include <seqan3/std/concepts>
65 #include <seqan3/std/ranges>
66 
67 namespace seqan3
68 {
69 
71 template <std::ranges::InputRange sequence_t, typename alignment_config_t>
72  requires detail::is_algorithm_configuration_v<remove_cvref_t<alignment_config_t>> &&
73  tuple_like_concept<value_type_t<std::ranges::iterator_t<std::remove_reference_t<sequence_t>>>>
74 constexpr auto align_pairwise(sequence_t && seq, alignment_config_t && config)
75 {
76  static_assert(std::tuple_size_v<value_type_t<std::ranges::iterator_t<std::remove_reference_t<sequence_t>>>> == 2,
77  "Expects exactly two sequences for pairwise alignments.");
78 
79  auto dispatch_execution = [tpl = std::forward_as_tuple(std::forward<sequence_t>(seq))](auto && cfg)
80  {
81  // if constexpr (detail::has_align_cfg_v<align_cfg::id::on_hit, remove_cvref_t<decltype(cfg)>>)
82  // {
83  // throw std::invalid_argument{"The delegation option is yet not supported."};
84  // }
85  // else // continue with two-way executor.
86  // {
87  //TODO (rrahn): Extend with execution handler.
88  auto align_rng = std::forward<std::tuple_element_t<0, decltype(tpl)>>(std::get<0>(tpl)) | view::persist;
89  detail::alignment_selector<value_type_t<decltype(align_rng)>,
90  std::remove_reference_t<decltype(cfg)>> selector{cfg};
91  using exec_type = detail::alignment_executor_two_way<decltype(align_rng), decltype(selector)>;
92  return alignment_range<exec_type>{align_rng, selector};
93  // }
94  };
95 
96  // TODO: replaces the default arguments.
97  return detail::apply_deferred_configs(dispatch_execution, std::forward<alignment_config_t>(config));
98 }
99 //
100 
101 template <tuple_like_concept seq_t,
102  typename alignment_config_t>
103  requires detail::is_algorithm_configuration_v<remove_cvref_t<alignment_config_t>>
104 constexpr auto align_pairwise(seq_t && seq, alignment_config_t && config)
105 {
106  static_assert(std::tuple_size_v<std::remove_reference_t<seq_t>> == 2,
107  "Expects exactly two sequences for pairwise alignments.");
108 
109  //TODO: Check the problem here.
110  return align_pairwise(ranges::view::single(std::forward<seq_t>(seq)) | ranges::view::bounded,
111  std::forward<alignment_config_t>(config));
112 }
114 } // namespace seqan3
Meta-header for the pairwise execution submodule .
Meta-header for the alignment configuration module .
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Contains seqan3::gapped.
The Concepts library.
::ranges::iterator_t iterator_t
Alias for ranges::iterator_t. Obtains the iterator type of a range.
Definition: ranges:225
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:315
Provides C++20 additions to the type_traits header.
Provides various metafunctions on generic types.
Provides seqan3::align_result.
Meta-Header for components of the algorithm submodule.
Provides seqan3::view::persist.
typename value_type< t >::type value_type_t
Type metafunction shortcut for seqan3::value_type.
Definition: pre.hpp:72