SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
align_result_selector.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 <optional>
16 #include <type_traits>
17 
34 #include <seqan3/std/ranges>
35 
36 namespace seqan3::detail
37 {
38 
45 template <typename first_t, typename second_t>
46 struct alignment_type;
47 
49 template <typename first_t, typename second_t>
50  requires std::ranges::random_access_range<first_t> &&
51  std::ranges::sized_range<first_t> &&
52  std::ranges::random_access_range<second_t> &&
53  std::ranges::sized_range<second_t>
54 struct alignment_type<first_t, second_t>
55 {
57  using type = std::tuple<gap_decorator<type_reduce_view<first_t &>>, gap_decorator<type_reduce_view<second_t &>>>;
58 };
59 
66 template <std::ranges::forward_range first_range_t,
67  std::ranges::forward_range second_range_t,
68  typename configuration_t>
70  requires is_type_specialisation_of_v<remove_cvref_t<configuration_t>, configuration>
72 struct align_result_selector
73 {
74 private:
76  using score_type = typename alignment_configuration_traits<configuration_t>::original_score_t;
77 
79  static constexpr auto select()
80  {
81  static_assert(configuration_t::template exists<align_cfg::result>());
82 
83  if constexpr (configuration_t::template exists<align_cfg::result<with_back_coordinate_type, score_type>>())
84  {
85  return alignment_result_value_type<uint32_t,
86  score_type,
87  alignment_coordinate>{};
88  }
89  else if constexpr (configuration_t::template exists<align_cfg::result<with_front_coordinate_type, score_type>>())
90  {
91  return alignment_result_value_type<uint32_t,
92  score_type,
93  alignment_coordinate,
94  alignment_coordinate>{};
95  }
96  else if constexpr (configuration_t::template exists<align_cfg::result<with_alignment_type, score_type>>())
97  {
98  // Due to an error with gcc8 we define these types beforehand.
99  using first_gapped_seq_type = gapped<value_type_t<first_range_t>>;
100  using second_gapped_seq_type = gapped<value_type_t<second_range_t>>;
101 
102  // We use vectors of gapped sequence if the gap decorator cannot be used.
104 
105  // If the ranges are RandomAccess and Sized we can use the Gap Decorator, otherwise fallback_t.
106  using decorator_t = alignment_type<first_range_t, second_range_t>;
107 
108  return alignment_result_value_type<uint32_t,
109  score_type,
110  alignment_coordinate,
111  alignment_coordinate,
112  detail::transformation_trait_or_t<decorator_t, fallback_t>>{};
113  }
114  else
115  {
116  return alignment_result_value_type<uint32_t, score_type>{};
117  }
118  }
119 
121  template <typename alignment_result_value_t>
122  static constexpr auto augment_if_debug(alignment_result_value_t)
123  {
124  if constexpr (configuration_t::template exists<detail::debug_mode>())
125  {
126  using as_type_list = transfer_template_args_onto_t<alignment_result_value_t, type_list>;
127  using score_matrix_t = two_dimensional_matrix<std::optional<score_type>,
129  matrix_major_order::column>;
130  using trace_matrix_t = two_dimensional_matrix<std::optional<trace_directions>,
132  matrix_major_order::column>;
133 
134  if constexpr (configuration_t::template exists<align_cfg::result<with_alignment_type>>())
135  {
136  using with_score_t = list_traits::replace_at<score_matrix_t, 5, as_type_list>;
137  return transfer_template_args_onto_t<list_traits::replace_at<trace_matrix_t, 6, with_score_t>,
138  alignment_result_value_type>{};
139  }
140  else
141  {
142  return transfer_template_args_onto_t<list_traits::replace_at<score_matrix_t, 5, as_type_list>,
143  alignment_result_value_type>{};
144  }
145  }
146  else // Return as is.
147  {
148  return alignment_result_value_t{};
149  }
150  }
151 
152 public:
154  using type = decltype(augment_if_debug(select()));
155 };
156 
157 } // namespace seqan3::detail
type_traits.hpp
Provides helper type traits for the configuration and execution of the alignment algorithm.
gap_decorator.hpp
Provides seqan3::gap_decorator.
std::vector
configuration.hpp
Provides seqan3::detail::configuration and utility functions.
basic.hpp
Provides various type traits on generic types.
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
std::tuple
two_dimensional_matrix.hpp
Provides seqan3::detail::two_dimensional_matrix.
trace_directions.hpp
Provides the declaration of seqan3::detail::trace_directions.
gapped.hpp
Provides seqan3::gapped.
type_reduce.hpp
Provides seqan3::views::type_reduce.
range.hpp
Provides various transformation traits used by the range module.
transformation_trait_or.hpp
Provides seqan3::detail::transformation_trait_or.
ranges
Adaptations of concepts from the Ranges TS.
std::allocator
optional
alignment_coordinate.hpp
Provides seqan3::detail::alignment_coordinate.
traits.hpp
Provides traits for seqan3::type_list.
align_config_result.hpp
Provides configuration for alignment output.
align_config_debug.hpp
Provides seqan3::align_cfg::debug.
type_list.hpp
Provides seqan3::type_list.