SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
edit_distance_algorithm.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 <tuple>
16 
19 
20 namespace seqan3::detail
21 {
22 
37 template <typename config_t, typename traits_t>
38 class edit_distance_algorithm
39 {
40 public:
44  constexpr edit_distance_algorithm() = default;
45  constexpr edit_distance_algorithm(edit_distance_algorithm const &) = default;
46  constexpr edit_distance_algorithm(edit_distance_algorithm &&) = default;
47  constexpr edit_distance_algorithm & operator=(edit_distance_algorithm const &) = default;
48  constexpr edit_distance_algorithm & operator=(edit_distance_algorithm &&) = default;
49  ~edit_distance_algorithm() = default;
50 
62  constexpr edit_distance_algorithm(config_t const & cfg) : cfg_ptr{new config_t(cfg)}
63  {}
65 
79  template <indexed_sequence_pair_range indexed_sequence_pairs_t>
80  constexpr auto operator()(indexed_sequence_pairs_t && indexed_sequence_pairs)
81  {
82  using indexed_sequence_pair_t = std::ranges::range_value_t<indexed_sequence_pairs_t>; // The value type.
83  using sequence_pair_t = std::tuple_element_t<0, indexed_sequence_pair_t>; // The sequence pair type.
86  using alignment_result_value_t = typename align_result_selector<sequence1_t, sequence2_t, config_t>::type;
87 
88  using std::get;
89 
90  std::vector<alignment_result<alignment_result_value_t>> result_vector{}; // Stores the results.
91  for (auto && [sequence_pair, index] : indexed_sequence_pairs)
92  result_vector.push_back(compute_single_pair(index, get<0>(sequence_pair), get<1>(sequence_pair)));
93 
94  return result_vector;
95  }
96 private:
97 
107  template <std::ranges::forward_range first_range_t, std::ranges::forward_range second_range_t>
108  constexpr auto compute_single_pair(size_t const idx, first_range_t && first_range, second_range_t && second_range)
109  {
110  using edit_traits = default_edit_distance_trait_type<first_range_t,
111  second_range_t,
112  config_t,
113  typename traits_t::is_semi_global_type>;
114  edit_distance_unbanded algo{first_range, second_range, *cfg_ptr, edit_traits{}};
115  return algo(idx);
116  }
117 
120 };
121 
122 } // namespace seqan3::detail
std::shared_ptr
std::vector
tuple
edit_distance_unbanded.hpp
Provides a pairwise alignment algorithm for edit distance but without band.
std::vector::push_back
T push_back(T... args)
seqan3::views::get
const auto get
A view calling std::get on each element in a range.
Definition: get.hpp:65
concept.hpp
Provides concepts needed internally for the alignment algorithms.
std::remove_reference_t