15 #include <type_traits>
32 namespace seqan3::detail
52 template <std::ranges::viewable_range range_t>
53 struct make_aligned_sequence_type
65 using type = lazy_conditional_t<is_class_template_declarable_with_v<gap_decorator, unaligned_sequence_type>,
66 lazy<gap_decorator, unaligned_sequence_type>,
67 lazy<std::vector, gapped<std::ranges::range_value_t<unaligned_sequence_type>>>>;
77 template <std::ranges::viewable_range first_sequence_t, std::ranges::viewable_range second_sequence_t>
78 struct make_pairwise_alignment_type
81 using first_aligned_t =
typename make_aligned_sequence_type<first_sequence_t>::type;
83 using second_aligned_t =
typename make_aligned_sequence_type<second_sequence_t>::type;
86 "first_aligned_t is required to model seqan3::writable_aligned_sequence!");
88 "second_aligned_t is required to model seqan3::writable_aligned_sequence!");
115 template <std::ranges::viewable_range fst_sequence_t, std::ranges::viewable_range sec_sequence_t>
116 class aligned_sequence_builder
120 using alignment_type =
typename make_pairwise_alignment_type<fst_sequence_t, sec_sequence_t>::type;
123 struct [[nodiscard]] result_type
131 alignment_type alignment{};
137 constexpr aligned_sequence_builder() =
default;
138 constexpr aligned_sequence_builder(aligned_sequence_builder
const &) =
default;
139 constexpr aligned_sequence_builder(aligned_sequence_builder &&) =
default;
140 constexpr aligned_sequence_builder & operator=(aligned_sequence_builder
const &) =
default;
141 constexpr aligned_sequence_builder & operator=(aligned_sequence_builder &&) =
default;
142 ~aligned_sequence_builder() =
default;
148 constexpr aligned_sequence_builder(fst_sequence_t fst_rng, sec_sequence_t sec_rng) :
168 template <std::ranges::input_range trace_path_t>
169 result_type operator()(trace_path_t && trace_path)
171 static_assert(std::same_as<std::ranges::range_value_t<trace_path_t>, trace_directions>,
172 "The value type of the trace path must be seqan3::detail::trace_directions");
176 std::tie(res.first_sequence_slice_positions.second, res.second_sequence_slice_positions.second) =
181 while (trace_it != std::ranges::end(trace_path))
183 trace_directions last_dir = *trace_it;
185 for (; trace_it != std::ranges::end(trace_path) && *trace_it == last_dir; ++trace_it, ++span)
191 std::tie(res.first_sequence_slice_positions.first, res.second_sequence_slice_positions.first) =
194 assign_unaligned(std::get<0>(res.alignment),
195 std::views::all(fst_rng) |
views::slice(res.first_sequence_slice_positions.first,
196 res.first_sequence_slice_positions.second));
197 assign_unaligned(std::get<1>(res.alignment),
198 std::views::all(sec_rng) |
views::slice(res.second_sequence_slice_positions.first,
199 res.second_sequence_slice_positions.second));
202 fill_aligned_sequence(trace_segments | std::views::reverse,
203 std::get<0>(res.alignment),
204 std::get<1>(res.alignment));
217 template <
typename reverse_traces_t,
typename fst_aligned_t,
typename sec_aligned_t>
218 void fill_aligned_sequence(reverse_traces_t && rev_traces,
219 fst_aligned_t & fst_aligned,
220 sec_aligned_t & sec_aligned)
const
222 if (std::ranges::empty(rev_traces))
228 for (
auto const & [dir, span] : rev_traces)
230 if (dir == trace_directions::up)
231 fst_it = insert_gap(fst_aligned, fst_it, span);
233 if (dir == trace_directions::left)
234 sec_it = insert_gap(sec_aligned, sec_it, span);
241 type_reduce_view<fst_sequence_t> fst_rng;
242 type_reduce_view<sec_sequence_t> sec_rng;
249 template <std::ranges::viewable_range fst_sequence_t, std::ranges::viewable_range sec_sequence_t>
251 aligned_sequence_builder(fst_sequence_t &&, sec_sequence_t &&) ->
252 aligned_sequence_builder<fst_sequence_t, sec_sequence_t>;