SeqAn3
alignment_selector.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 <tuple>
44 #include <utility>
45 #include <vector>
46 
56 
57 namespace seqan3::detail
58 {
59 
66 template <typename seq1_t, typename seq2_t, typename configuration_t>
67 struct determine_result_type
68 {
70  static constexpr auto _determine()
71  {
72  using seq1_value_type = value_type_t<std::remove_reference_t<seq1_t>>;
73  using seq2_value_type = value_type_t<std::remove_reference_t<seq2_t>>;
74  using score_type = int32_t;
75 
76  if constexpr (has_align_cfg_v<align_cfg::id::output, configuration_t>)
77  {
78  if constexpr (get<align_cfg::id::output>(configuration_t{}) ==
79  align_result_key::end)
80  return align_result<type_list<uint32_t,
81  score_type,
82  alignment_coordinate>>{};
83  else if constexpr (get<align_cfg::id::output>(configuration_t{}) ==
84  align_result_key::begin)
85  return align_result<type_list<uint32_t,
86  score_type,
87  alignment_coordinate,
88  alignment_coordinate>>{};
89  else if constexpr (get<align_cfg::id::output>(configuration_t{}) ==
90  align_result_key::trace)
91  return align_result<type_list<uint32_t,
92  score_type,
93  alignment_coordinate,
94  alignment_coordinate,
95  std::pair<std::vector<gapped<seq1_value_type>>,
96  std::vector<gapped<seq2_value_type>>>>>{};
97  else
98  return align_result<type_list<uint32_t,
99  score_type>>{};
100  }
101  else
102  {
103  return align_result<type_list<uint32_t, score_type>>{};
104  }
105  }
106 
108  using type = decltype(_determine());
109 };
110 
117 template <tuple_like_concept seq_tuple_t, typename configuration_t>
118 struct alignment_selector
119 {
121  configuration_t config;
122 
124  using result_type = typename determine_result_type<std::tuple_element_t<0, std::remove_reference_t<seq_tuple_t>>,
125  std::tuple_element_t<1, std::remove_reference_t<seq_tuple_t>>,
126  configuration_t>::type;
127 
136  template <tuple_like_concept _seq_tuple_t>
137  auto select(_seq_tuple_t && seq)
138  {
139  //TODO Currently we only support edit_distance. We need would actually need real checks for this.
140  std::function<result_type(result_type &)> func =
141  pairwise_alignment_edit_distance_unbanded{std::get<0>(std::forward<_seq_tuple_t>(seq)) | view::persist,
142  std::get<1>(std::forward<_seq_tuple_t>(seq)) | view::persist,
143  config};
144  return func;
145  }
146 };
147 } // namespace seqan3::detail
Meta-header for the alignment configuration module .
Provides seqan3::type_list and auxiliary metafunctions.
Provides seqan3::tuple_like_concept.
Contains seqan3::gapped.
Contains the declaration of seqan3::detail::alignment_trace_matrix.
auto constexpr persist
A view adaptor that wraps rvalue references of non-views.
Definition: persist.hpp:315
Definition: aligned_sequence_concept.hpp:288
Provides seqan3::align_result.
Provides seqan3::view::persist.
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:54
Contains a pairwise alignment algorithm for edit distance but without band.
Provides various metafunctions used by the range module.