17 #include <type_traits>
33 namespace seqan3::detail
53 template <std::ranges::viewable_range range_t>
54 struct make_aligned_sequence_type
66 using type = lazy_conditional_t<is_class_template_declarable_with_v<gap_decorator, unaligned_sequence_type>,
67 lazy<gap_decorator, unaligned_sequence_type>,
68 lazy<std::vector, gapped<std::ranges::range_value_t<unaligned_sequence_type>>>>;
78 template <std::ranges::viewable_range first_sequence_t, std::ranges::viewable_range second_sequence_t>
79 struct make_pairwise_alignment_type
82 using first_aligned_t =
typename make_aligned_sequence_type<first_sequence_t>::type;
84 using second_aligned_t =
typename make_aligned_sequence_type<second_sequence_t>::type;
87 "first_aligned_t is required to model seqan3::writable_aligned_sequence!");
89 "second_aligned_t is required to model seqan3::writable_aligned_sequence!");
116 template <std::ranges::viewable_range fst_sequence_t, std::ranges::viewable_range sec_sequence_t>
117 class aligned_sequence_builder
121 using alignment_type =
typename make_pairwise_alignment_type<fst_sequence_t, sec_sequence_t>::type;
124 struct [[nodiscard]] result_type
138 constexpr aligned_sequence_builder() =
default;
139 constexpr aligned_sequence_builder(aligned_sequence_builder
const &) =
default;
140 constexpr aligned_sequence_builder(aligned_sequence_builder &&) =
default;
141 constexpr aligned_sequence_builder & operator=(aligned_sequence_builder
const &) =
default;
142 constexpr aligned_sequence_builder & operator=(aligned_sequence_builder &&) =
default;
143 ~aligned_sequence_builder() =
default;
149 constexpr aligned_sequence_builder(fst_sequence_t fst_rng, sec_sequence_t sec_rng) :
169 template <std::ranges::input_range trace_path_t>
170 result_type operator()(trace_path_t && trace_path)
172 static_assert(std::same_as<std::ranges::range_value_t<trace_path_t>, trace_directions>,
173 "The value type of the trace path must be seqan3::detail::trace_directions");
177 std::tie(res.first_sequence_slice_positions.second, res.second_sequence_slice_positions.second) =
182 while (trace_it != std::ranges::end(trace_path))
184 trace_directions last_dir = *trace_it;
186 for (; trace_it != std::ranges::end(trace_path) && *trace_it == last_dir; ++trace_it, ++span)
192 std::tie(res.first_sequence_slice_positions.first, res.second_sequence_slice_positions.first) =
195 assign_unaligned(std::get<0>(res.alignment),
196 std::views::all(fst_rng) |
views::slice(res.first_sequence_slice_positions.first,
197 res.first_sequence_slice_positions.second));
198 assign_unaligned(std::get<1>(res.alignment),
199 std::views::all(sec_rng) |
views::slice(res.second_sequence_slice_positions.first,
200 res.second_sequence_slice_positions.second));
203 fill_aligned_sequence(trace_segments | std::views::reverse,
204 std::get<0>(res.alignment),
205 std::get<1>(res.alignment));
218 template <
typename reverse_traces_t,
typename fst_aligned_t,
typename sec_aligned_t>
219 void fill_aligned_sequence(reverse_traces_t && rev_traces,
220 fst_aligned_t & fst_aligned,
221 sec_aligned_t & sec_aligned)
const
223 if (std::ranges::empty(rev_traces))
229 for (
auto const & [dir, span] : rev_traces)
231 assert(dir == trace_directions::up || dir == trace_directions::left || dir == trace_directions::diagonal);
233 if (dir == trace_directions::up)
234 fst_it = insert_gap(fst_aligned, fst_it, span);
236 if (dir == trace_directions::left)
237 sec_it = insert_gap(sec_aligned, sec_it, span);
244 type_reduce_view<fst_sequence_t> fst_rng;
245 type_reduce_view<sec_sequence_t> sec_rng;
253 template <std::ranges::viewable_range fst_sequence_t, std::ranges::viewable_range sec_sequence_t>
254 aligned_sequence_builder(fst_sequence_t &&, sec_sequence_t &&) ->
255 aligned_sequence_builder<fst_sequence_t, sec_sequence_t>;
Includes the aligned_sequence and the related insert_gap and erase_gap functions to enable stl contai...
T emplace_back(T... args)
Provides seqan3::gap_decorator.
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:191
constexpr auto type_reduce
A view adaptor that behaves like std::views::all, but type erases certain ranges.
Definition: type_reduce.hpp:158
The generic concept for an aligned sequence that is writable.
Provides a type trait for verifying valid template declarations.
Provides lazy template instantiation traits.
Provides seqan3::detail::alignment_coordinate and associated strong types.
SeqAn specific customisations in the standard namespace.
Adaptations of concepts from the Ranges TS.
Provides seqan3::views::slice.
Provides seqan3::views::to.
Provides the declaration of seqan3::detail::trace_directions.
Provides seqan3::views::type_reduce.
Provides the concepts seqan3::transformation_trait and seqan3::unary_type_trait.
Provides seqan3::views::convert.