46 #include <range/v3/algorithm/for_each.hpp> 47 #include <range/v3/view/slice.hpp> 146 template <
typename t>
155 { insert_gap(v, v.begin()) } ->
typename t::iterator;
156 { insert_gap(v, v.begin(), 2) } ->
typename t::iterator;
157 { erase_gap(v, v.begin()) } ->
typename t::iterator;
158 { erase_gap(v, v.begin(), v.end()) } ->
typename t::iterator;
187 template <sequence_container_concept seq_type>
191 inline typename seq_type::iterator
insert_gap(seq_type & seq,
typename seq_type::const_iterator pos_it)
212 template <sequence_container_concept seq_type>
214 requires weakly_assignable_concept<reference_t<seq_type>,
gap const &>
216 inline typename seq_type::iterator
insert_gap(seq_type & seq,
217 typename seq_type::const_iterator pos_it,
218 typename seq_type::size_type
size)
241 template <sequence_container_concept seq_type>
243 requires weakly_assignable_concept<reference_t<seq_type>,
gap const &>
245 inline typename seq_type::iterator
erase_gap(seq_type & seq,
typename seq_type::const_iterator pos_it)
247 if (*pos_it != gap::GAP)
250 return seq.erase(pos_it);
272 template <sequence_container_concept seq_type>
274 requires weakly_assignable_concept<reference_t<seq_type>,
gap const &>
276 inline typename seq_type::iterator
erase_gap(seq_type & seq,
277 typename seq_type::const_iterator first,
278 typename seq_type::const_iterator last)
280 for (
auto it = first; it != last; ++it)
282 throw gap_erase_failure(
"The range to be erased contains at least one non-gap character.");
284 return seq.erase(first, last);
299 void stream_alignment(
debug_stream_type & stream, alignment_t
const & align, std::index_sequence<idx...>
const & )
302 size_t const alignment_size = get<0>(align).
size();
305 for (
size_t begin_pos = 0; begin_pos < alignment_size; begin_pos += 50)
307 size_t const end_pos = std::min(begin_pos + 50, alignment_size);
313 stream << std::setw(7) << begin_pos <<
' ';
314 for (
size_t pos = begin_pos + 1; pos <= end_pos; ++pos)
318 else if (pos % 5 == 0)
325 stream <<
'\n' << std::setw(8) <<
"";
326 ranges::for_each(get<0>(align) | ranges::view::slice(begin_pos, end_pos) |
view::to_char,
327 [&stream] (
char ch) { stream << ch; });
329 auto stream_f = [&] (
auto const & previous_seq,
auto const & aligned_seq)
332 stream <<
'\n' << std::setw(8) <<
"";
333 ranges::for_each(ranges::zip_view(previous_seq, aligned_seq) | ranges::view::slice(begin_pos, end_pos),
334 [&stream] (
auto && ch) { stream << (get<0>(ch) == get<1>(ch) ?
'|' :
' '); });
337 stream <<
'\n' << std::setw(8) <<
"";
338 ranges::for_each(aligned_seq | ranges::view::slice(begin_pos, end_pos) |
view::to_char,
339 [&stream] (
char ch) { stream << ch; });
341 (stream_f(get<idx>(align), get<idx + 1>(align)), ...);
349 template <
typename ...elems>
350 inline bool constexpr all_satisfy_aligned_seq =
false;
355 template <
typename ...elems>
366 template <tuple_like_concept tuple_t>
368 requires detail::all_satisfy_aligned_seq<detail::tuple_type_list_t<tuple_t>>
372 static_assert(std::tuple_size_v<tuple_t> >= 2,
"An alignment requires at least two sequences.");
373 detail::stream_alignment(stream, alignment, std::make_index_sequence<std::tuple_size_v<tuple_t> - 1> {});
debug_stream_type & operator<<(debug_stream_type &stream, tuple_t const &alignment)
Streaming operator for alignments, which are represented as tuples of aligned sequences.
Definition: aligned_sequence_concept.hpp:370
seq_type::iterator erase_gap(seq_type &seq, typename seq_type::const_iterator first, typename seq_type::const_iterator last)
An implementation of seqan3::aligned_sequence_concept::erase_gap for sequence containers.
Definition: aligned_sequence_concept.hpp:276
The alphabet of a gap character '-'.
Definition: gap.hpp:62
The generic concept for an aligned sequence.This concept describes the requirements a sequence must f...
Whether a type behaves like a tuple.
Resolves to std::is_assignable_v<t>.
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:195
The generic alphabet concept that covers most data types used in ranges.This is the core alphabet con...
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
seq_type::iterator erase_gap(seq_type &seq, typename seq_type::const_iterator pos_it)
An implementation of seqan3::aligned_sequence_concept::erase_gap for sequence containers.
Definition: aligned_sequence_concept.hpp:245
seq_type::iterator insert_gap(seq_type &seq, typename seq_type::const_iterator pos_it, typename seq_type::size_type size)
An implementation of seqan3::aligned_sequence_concept::insert_gap for sequence containers.
Definition: aligned_sequence_concept.hpp:216
Provides seqan3::tuple_like_concept.
Adaptations of concepts from the Ranges TS.
Meta-header for the gap submodule; includes all headers from alphabet/gap/.
seq_type::iterator insert_gap(seq_type &seq, typename seq_type::const_iterator pos_it)
An implementation of seqan3::aligned_sequence_concept::insert_gap for sequence containers.
Definition: aligned_sequence_concept.hpp:191
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition: to_char.hpp:88
Thrown in function seqan3::erase_gap, if a position does not contain a gap.
Definition: exception.hpp:50
Specifies requirements of a Range type for which begin returns a type that models std::ForwardIterato...
auto const get
A view calling std::get on each element in a range.
Definition: get.hpp:88
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:54
Provides seqan3::view::to_char.
Includes customized exception types for the alignment module .
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream.hpp:104
Adaptations of concepts from the standard library.
Provides seqan3::debug_stream and related types.