-
Notifications
You must be signed in to change notification settings - Fork 81
/
aligned_sequence_concept.hpp
568 lines (527 loc) · 26.4 KB
/
aligned_sequence_concept.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------
/*!\file
* \brief Includes the aligned_sequence and the related insert_gap and
* erase_gap functions to enable stl container support.
* \author Svenja Mehringer <svenja.mehringer AT fu-berlin.de>
*/
#pragma once
#include <iomanip>
#include <tuple>
#include <range/v3/algorithm/for_each.hpp>
#include <seqan3/alignment/exception.hpp>
#include <seqan3/alphabet/gap/gapped.hpp>
#include <seqan3/core/concept/tuple.hpp>
#include <seqan3/core/detail/debug_stream_type.hpp>
#include <seqan3/range/container/concept.hpp>
#include <seqan3/range/views/slice.hpp>
#include <seqan3/range/views/to_char.hpp>
#include <seqan3/range/views/zip.hpp>
#include <seqan3/std/ranges>
// ---------------------------------------------------------------------------------------------------------------------
// unaligned_seq transformation trait
// ---------------------------------------------------------------------------------------------------------------------
namespace seqan3::detail
{
//!\brief Helper function to deduce the unaligned sequence type from an aligned sequence container.
template <template <typename ...> typename container_type, typename seq_alph_t, typename ...rest_t>
//!\cond
requires container<container_type<gapped<seq_alph_t>, rest_t...>>
//!\endcond
constexpr auto remove_gap_from_value_type(container_type<gapped<seq_alph_t>, rest_t...>)
-> container_type<seq_alph_t, rest_t...>;
//!\overload
template <template <typename ...> typename container_type,
template <typename ...> typename allocator_type,
typename seq_alph_t, typename ...rest_t>
//!\cond
requires container<container_type<gapped<seq_alph_t>, allocator_type<gapped<seq_alph_t>>, rest_t...>>
//!\endcond
constexpr auto remove_gap_from_value_type(container_type<gapped<seq_alph_t>, allocator_type<gapped<seq_alph_t>>, rest_t...>)
-> container_type<seq_alph_t, allocator_type<seq_alph_t>, rest_t...>;
//!\brief Default transformation trait that shall expose the unaligned sequence type of t when specialised.
template <typename t>
struct unaligned_seq
{};
//!\brief Exposes the unaligned sequence type given an aligned sequence container type.
template <typename t>
//!\cond
requires !requires { typename std::remove_reference_t<t>::unaligned_seq_type; } &&
requires { remove_gap_from_value_type(std::declval<t>()); }
//!\endcond
struct unaligned_seq<t>
{
//!\brief The unaligned sequence type of t
using type = decltype(remove_gap_from_value_type(std::declval<t>()));
};
// customisation point for our gap decorators.
//!\brief Exposes the unaligned sequence type if *t* exposes the type member `unaligned_seq_type`.
template <typename t>
//!\cond
requires requires { typename std::remove_reference_t<t>::unaligned_seq_type; }
//!\endcond
struct unaligned_seq<t>
{
using type = typename std::remove_reference_t<t>::unaligned_seq_type; //!< The unaligned sequence type of t
};
//!\brief Helper type that delegates to seqan3::detail::unaligned_seq::type.
template <typename t>
using unaligned_seq_t = typename unaligned_seq<t>::type;
} // namespace seqan3::detail
// ---------------------------------------------------------------------------------------------------------------------
// aligned_sequence
// ---------------------------------------------------------------------------------------------------------------------
namespace seqan3
{
/*!\interface seqan3::aligned_sequence <>
* \extends std::ranges::forward_range
* \brief The generic concept for an aligned sequence.
* \ingroup aligned_sequence
*
* This concept describes the requirements a sequence must fulfil in order to be used inside of the alignment algorithm
* to store the final alignment.
*
* ### Concepts and doxygen
*
* The requirements for this concept are given as related functions and type traits.
* Types that model this concept are shown as "implementing this interface".
*/
/*!\name Requirements for seqan3::aligned_sequence
* \brief You can expect these functions on all types that model seqan3::aligned_sequence.
* \relates seqan3::aligned_sequence
* \{
*/
/*!\fn inline std::ranges::iterator_t<aligned_seq_t> insert_gap(aligned_seq_t & aligned_seq,
* typename aligned_seq_t::const_iterator pos_it)
* \brief Insert a seqan3::gap into an aligned sequence.
*
* \tparam aligned_seq_t Type of the range to modify; must model seqan3::aligned_sequence.
* \param[in,out] aligned_seq The aligned sequence to modify.
* \param[in] pos_it The iterator pointing to the position where to insert a gap.
* \returns An iterator pointing to the inserted gap.
*
* \details
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*
* \attention This is a concept requirement, not an actual function (however types
* modelling this concept will provide an implementation).
*/
/*!\fn inline std::ranges::iterator_t<aligned_seq_t> insert_gap(aligned_seq_t & aligned_seq,
* typename aligned_seq_t::const_iterator pos_it, typename aligned_seq_t::size_type size)
* \brief Insert multiple seqan3::gap into an aligned sequence.
*
* \tparam aligned_seq_t Type of the range to modify; must model seqan3::aligned_sequence.
* \param[in,out] aligned_seq The aligned sequence to modify.
* \param[in] pos_it The iterator pointing to the position where to insert a gaps.
* \param[in] size The number of gap symbols to insert (will result in a gap of length `size`).
* \returns An iterator pointing to the first inserted gap or `pos_it` if `size == 0`.
*
* \details
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*
* \attention This is a concept requirement, not an actual function (however types
* modelling this concept will provide an implementation).
*/
/*!\fn inline std::ranges::iterator_t<aligned_seq_t> erase_gap(aligned_seq_t & aligned_seq,
* typename aligned_seq_t::const_iterator pos_it)
* \brief Erase a seqan3::gap from an aligned sequence.
*
* \tparam aligned_seq_t Type of the range to modify; must model seqan3::aligned_sequence.
* \param[in,out] aligned_seq The aligned sequence to modify.
* \param[in] pos_it The iterator pointing to the position where to erase a gap.
* \returns An iterator following the removed element. If the iterator `pos_it` refers to the last element, the
* std::ranges::end() iterator is returned.
*
* \throws seqan3::gap_erase_failure if there is no seqan3::gap at \p pos_it.
*
* \details
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*
* \attention This is a concept requirement, not an actual function (however types
* modelling this concept will provide an implementation).
*/
/*!\fn inline std::ranges::iterator_t<aligned_seq_t> erase_gap(aligned_seq_t & aligned_seq,
* typename aligned_seq_t::const_iterator first, typename aligned_seq_t::const_iterator last)
* \brief Erase multiple seqan3::gap from an aligned sequence.
*
* \tparam aligned_seq_t Type of the range to modify; must model seqan3::aligned_sequence.
* \param[in,out] aligned_seq The aligned sequence to modify.
* \param[in] first The iterator pointing to the position where to start erasing gaps.
* \param[in] last The iterator pointing to the position where to stop erasing gaps.
* \returns An iterator following the last removed element. If the iterator `last` refers to the last element, the
* std::ranges::end() iterator is returned.
*
* \throws seqan3::gap_erase_failure if one of the characters in [\p first, \p last) no seqan3::gap.
*
* \details
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*
* \attention This is a concept requirement, not an actual function (however types
* modelling this concept will provide an implementation).
*/
/*!\fn void assign_unaligned(aligned_seq_t & aligned_seq, unaligned_sequence_type && unaligned_seq)
* \brief Assign an ungapped sequence to a gapped sequence.
*
* \tparam aligned_seq_t Type of the container to reassign; must model seqan3::aligned_sequence.
* \tparam unaligned_seq_t Type of the container to assign from; must correspond to the aligned type without
* gap information (see details.)
* \param[in,out] aligned_seq The gapped sequence container to assign to.
* \param[in,out] unaligned_seq The unaligned sequence container to assign from.
*
* \details
*
* An aligned sequence has to be assignable from its unaligned counter part. For example a
* std::vector<seqan3::gapped<seqan3::dna4>> as well as a seqan3::gap_decorator<std::vector<seqan3::dna4>>
* can be assigned from s std::vector<seqan3::dna4> via seqan3::assign_unaligned.
*
* \attention This is a concept requirement, not an actual function (however types
* modelling this concept will provide an implementation).
*/
//!\}
//!\cond
template <typename t>
SEQAN3_CONCEPT aligned_sequence =
std::ranges::forward_range<t> &&
alphabet<reference_t<t>> &&
weakly_assignable_from<reference_t<t>, gap const &> &&
requires { typename detail::unaligned_seq_t<t>; } &&
requires (t v, detail::unaligned_seq_t<t> unaligned)
{
{ insert_gap(v, std::ranges::begin(v)) } -> std::ranges::iterator_t<t>; // global functions for generic usability
{ insert_gap(v, std::ranges::begin(v), 2) } -> std::ranges::iterator_t<t>;
{ erase_gap(v, std::ranges::begin(v)) } -> std::ranges::iterator_t<t>;
{ erase_gap(v, std::ranges::begin(v), std::ranges::end(v)) } -> std::ranges::iterator_t<t>;
{ assign_unaligned(v, unaligned) } -> void;
};
//!\endcond
// ---------------------------------------------------------------------------------------------------------------------
// Aligned sequence interface for containers over the seqan3::gapped alphabet
// ---------------------------------------------------------------------------------------------------------------------
/*!\name Aligned sequence interface for containers over the seqan3::gapped alphabet
* \brief Enables containers to model seqan3::aligned_sequence if they model seqan3::sequence_container
* and have a value type of the seqan3::gapped alphabet.
* \{
*/
/*!\brief An implementation of seqan3::aligned_sequence::insert_gap for sequence containers.
* \ingroup aligned_sequence
* \tparam aligned_seq_t Type of the container to modify; must model seqan3::sequence_container;
* The value type must be a seqan3::gapped alphabet.
* \param[in,out] aligned_seq The aligned container to modify.
* \param[in] pos_it The iterator pointing to the position where to insert a gap.
* \returns An iterator pointing to the inserted gap.
*
* \details
*
* This function delegates to the member function `insert(iterator, value)` of
* the container.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <sequence_container aligned_seq_t>
//!\cond
requires detail::is_gapped_alphabet<std::iter_value_t<aligned_seq_t>>
//!\endcond
inline typename aligned_seq_t::iterator insert_gap(aligned_seq_t & aligned_seq,
typename aligned_seq_t::const_iterator pos_it)
{
return aligned_seq.insert(pos_it, std::iter_value_t<aligned_seq_t>{gap{}});
}
/*!\brief An implementation of seqan3::aligned_sequence::insert_gap for sequence containers.
* \ingroup aligned_sequence
* \tparam aligned_seq_t Type of the container to modify; must model seqan3::sequence_container;
* The value type must be a seqan3::gapped alphabet.
* \param[in,out] aligned_seq The aligned container to modify.
* \param[in] pos_it The iterator pointing to the position where to insert gaps.
* \param[in] size The number of gap symbols to insert (will result in a gap of length `size`).
* \returns An iterator pointing to the first inserted gap or `pos_it` if `size == 0`.
*
* \details
*
* This function delegates to the member function `insert(iterator, `size`, `value`)`
* of the container.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <sequence_container aligned_seq_t>
//!\cond
requires detail::is_gapped_alphabet<std::iter_value_t<aligned_seq_t>>
//!\endcond
inline typename aligned_seq_t::iterator insert_gap(aligned_seq_t & aligned_seq,
typename aligned_seq_t::const_iterator pos_it,
typename aligned_seq_t::size_type size)
{
return aligned_seq.insert(pos_it, size, std::iter_value_t<aligned_seq_t>{gap{}});
}
/*!\brief An implementation of seqan3::aligned_sequence::erase_gap for sequence containers.
* \ingroup aligned_sequence
* \tparam aligned_seq_t Type of the container to modify; must model seqan3::sequence_container;
* The value type must be a seqan3::gapped alphabet.
* \param[in,out] aligned_seq The aligned container to modify.
* \param[in] pos_it The iterator pointing to the position where to erase a gap.
* \returns An iterator following the removed element. If the iterator `pos_it` refers to the last element, the
* std::ranges::end() iterator is returned.
*
* \throws seqan3::gap_erase_failure if there is no seqan3::gap at \p pos_it.
*
* \details
*
* This function delegates to the member function `erase(iterator)` of the
* container. Before delegating, the function checks if the position pointed to
* by \p pos_it is an actual seqan3::gap and throws an exception if not.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <sequence_container aligned_seq_t>
//!\cond
requires detail::is_gapped_alphabet<std::iter_value_t<aligned_seq_t>>
//!\endcond
inline typename aligned_seq_t::iterator erase_gap(aligned_seq_t & aligned_seq,
typename aligned_seq_t::const_iterator pos_it)
{
if (*pos_it != gap{}) // [[unlikely]]
throw gap_erase_failure("The position to be erased does not contain a gap.");
return aligned_seq.erase(pos_it);
}
/*!\brief An implementation of seqan3::aligned_sequence::erase_gap for sequence containers.
* \ingroup aligned_sequence
* \tparam aligned_seq_t Type of the container to modify; must model seqan3::sequence_container;
* The value type must be a seqan3::gapped alphabet.
* \param[in,out] aligned_seq The aligned container to modify.
* \param[in] first The iterator pointing to the position where to start erasing gaps.
* \param[in] last The iterator pointing to the position where to stop erasing gaps.
* \returns An iterator following the last removed element. If the iterator `last` refers to the last element, the
* std::ranges::end() iterator is returned.
*
* \throws seqan3::gap_erase_failure if one of the characters in [\p first, \p last) no seqan3::gap.
*
* \details
*
* This function delegates to the member function `erase(iterator, iterator)` of
* the container. Before delegating, the function checks if the range
* [\p first, \p last) contains only seqan3::gap symbols.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <sequence_container aligned_seq_t>
//!\cond
requires detail::is_gapped_alphabet<std::iter_value_t<aligned_seq_t>>
//!\endcond
inline typename aligned_seq_t::iterator erase_gap(aligned_seq_t & aligned_seq,
typename aligned_seq_t::const_iterator first,
typename aligned_seq_t::const_iterator last)
{
for (auto it = first; it != last; ++it)
if (*it != gap{}) // [[unlikely]]
throw gap_erase_failure("The range to be erased contains at least one non-gap character.");
return aligned_seq.erase(first, last);
}
/*!\brief An implementation of seqan3::aligned_sequence::assign_unaligned_sequence for sequence containers.
* \ingroup aligned_sequence
* \tparam aligned_seq_t Type of the container to reassign; must model seqan3::sequence_container;
* the value type must be a seqan3::gapped alphabet.
* \tparam unaligned_seq_t Type of the container to assign from; must model std::ranges::forward_range.
* \param[in,out] aligned_seq The gapped sequence container to assign to.
* \param[in,out] unaligned_seq The unaligned sequence container to assign from.
*
* \details
*
* This function clears the content of the `gapped` container and reassigns the content of the `unaligned` container by
* using std::copy.
*
* ### Performance
*
* Linear in the size of unaligned_seq.
*
* ### Exceptions
*
* Strong exception guarantee.
*
*/
template <sequence_container aligned_seq_t, std::ranges::forward_range unaligned_sequence_type>
//!\cond
requires detail::is_gapped_alphabet<std::iter_value_t<aligned_seq_t>> &&
weakly_assignable_from<reference_t<aligned_seq_t>, reference_t<unaligned_sequence_type>>
//!\endcond
inline void assign_unaligned(aligned_seq_t & aligned_seq, unaligned_sequence_type && unaligned_seq)
{
using std::swap;
aligned_seq_t tmp;
tmp.resize(std::ranges::distance(unaligned_seq));
std::ranges::copy(unaligned_seq, std::ranges::begin(tmp));
swap(aligned_seq, tmp);
}
//!\}
/*!\name Aligned sequence interface for ranges that have the corresponding member functions.
* \brief Enables ranges to model seqan3::aligned_sequence if they have the member functions
* insert_gap() and erase_gap().
* \{
*/
/*!\brief An implementation of seqan3::aligned_sequence::insert_gap for ranges with the corresponding
* member function insert_gap(it, size).
* \ingroup aligned_sequence
* \tparam range_type Type of the range to modify; must have an insert_gap(it, size) member function.
* \param[in,out] rng The range to modify.
* \param[in] pos_it The iterator pointing to the position where to start inserting gaps.
* \param[in] size The number of gaps to insert as an optional argument, default is 1.
* \returns An iterator pointing to the first inserted gap or `pos_it` if `size == 0`.
*
* \details
*
* This function delegates to the member function `insert(iterator, size)` of the range.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <typename range_type>
//!\cond
requires requires (range_type v)
{
v.insert_gap(std::ranges::iterator_t<range_type>{});
v.insert_gap(std::ranges::iterator_t<range_type>{}, typename range_type::size_type{});
}
//!\endcond
std::ranges::iterator_t<range_type> insert_gap(range_type & rng,
std::ranges::iterator_t<range_type> const pos_it,
typename range_type::size_type const size = 1)
{
return rng.insert_gap(pos_it, size);
}
/*!\brief An implementation of seqan3::aligned_sequence::erase_gap for ranges with the corresponding
* member function erase_gap(it).
* \ingroup aligned_sequence
* \tparam range_type Type of the range to modify; must have an erase_gap(it) member function.
* \param[in,out] rng The range to modify.
* \param[in] pos_it The iterator pointing to the position where to erase one gap.
* \returns An iterator following the removed element. If the iterator `pos_it` refers to the last element, the
* std::ranges::end() iterator is returned.
*
* \details
*
* This function delegates to the member function `erase(it)` of
* the range.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <typename range_type>
//!\cond
requires requires (range_type v) { v.erase_gap(std::ranges::iterator_t<range_type>{}); }
//!\endcond
std::ranges::iterator_t<range_type> erase_gap(range_type & rng,
std::ranges::iterator_t<range_type> const pos_it)
{
return rng.erase_gap(pos_it);
}
/*!\brief An implementation of seqan3::aligned_sequence::erase_gap for ranges with the corresponding
* member function erase_gap(first, last).
* \ingroup aligned_sequence
* \tparam range_type Type of the range to modify; must have an erase_gap(first, last) member function.
* \param[in,out] rng The range to modify.
* \param[in] first The iterator pointing to the position where to start erasing gaps.
* \param[in] last The iterator pointing to the position where to stop erasing gaps.
* \returns An iterator following the last removed element. If the iterator `last` refers to the last element, the
* std::ranges::end() iterator is returned.
*
* \throws seqan3::gap_erase_failure if one of the characters in [\p first, \p last) is no seqan3::gap.
*
* \details
*
* This function delegates to the member function `erase(first, last)` of the range.
*
* \note This may cause reallocations and thus invalidates all iterators and references. Use the returned iterator.
*/
template <typename range_type>
//!\cond
requires requires (range_type v) { v.erase_gap(std::ranges::iterator_t<range_type>{}, std::ranges::iterator_t<range_type>{}); }
//!\endcond
std::ranges::iterator_t<range_type> erase_gap(range_type & rng,
std::ranges::iterator_t<range_type> const first,
std::ranges::iterator_t<range_type> const last)
{
return rng.erase_gap(first, last);
}
//!\}
namespace detail
{
/*!\brief Create the formatted alignment output and add it to the provided debug_stream.
* \ingroup aligned_sequence
* \tparam alignment_t The type of the alignment, must satisfy tuple_like.
* \tparam idx An index sequence.
* \param[in] stream The output stream that receives the formatted alignment.
* \param[in] align The alignment that shall be streamed.
*/
template <typename char_t, tuple_like alignment_t, size_t ...idx>
void stream_alignment(debug_stream_type<char_t> & stream, alignment_t const & align, std::index_sequence<idx...> const & /**/)
{
using std::get;
size_t const alignment_size = get<0>(align).size();
// split alignment into blocks of length 50 and loop over parts
for (size_t begin_pos = 0; begin_pos < alignment_size; begin_pos += 50)
{
size_t const end_pos = std::min(begin_pos + 50, alignment_size);
// write header line
if (begin_pos != 0)
stream << '\n';
stream << std::setw(7) << begin_pos << ' ';
for (size_t pos = begin_pos + 1; pos <= end_pos; ++pos)
{
if (pos % 10 == 0)
stream << ':';
else if (pos % 5 == 0)
stream << '.';
else
stream << ' ';
}
// write first sequence
stream << '\n' << std::setw(8) << "";
std::ranges::for_each(get<0>(align) | views::slice(begin_pos, end_pos) | views::to_char,
[&stream] (char ch) { stream << ch; });
auto stream_f = [&] (auto const & previous_seq, auto const & aligned_seq)
{
// write alignment bars
stream << '\n' << std::setw(8) << "";
std::ranges::for_each(views::zip(previous_seq, aligned_seq) | views::slice(begin_pos, end_pos),
[&stream] (auto && ch) { stream << (get<0>(ch) == get<1>(ch) ? '|' : ' '); });
// write next sequence
stream << '\n' << std::setw(8) << "";
std::ranges::for_each(aligned_seq | views::slice(begin_pos, end_pos) | views::to_char,
[&stream] (char ch) { stream << ch; });
};
(stream_f(get<idx>(align), get<idx + 1>(align)), ...);
stream << '\n';
}
}
/*!\brief True, if each type satisfies aligned_sequence; false otherwise.
* \tparam elems The pack of types to be tested.
*/
template <typename ...elems>
inline bool constexpr all_satisfy_aligned_seq = false;
/*!\brief True, if each type satisfies aligned_sequence; false otherwise.
* \tparam elems The pack of types to be tested.
*/
template <typename ...elems>
inline bool constexpr all_satisfy_aligned_seq<type_list<elems...>> = (aligned_sequence<elems> && ...);
} // namespace detail
/*!\brief Stream operator for alignments, which are represented as tuples of aligned sequences.
* \ingroup aligned_sequence
* \tparam tuple_t The alignment type, must satisfy tuple_like and its size must be at least 2.
* \param stream The target stream for the formatted output.
* \param alignment The alignment that shall be formatted. All sequences must be equally long.
* \return The given stream to which the alignment representation is appended.
*/
template <typename tuple_t, typename char_t>
//!\cond
requires !std::ranges::input_range<tuple_t> &&
!alphabet<tuple_t> && // exclude alphabet_tuple_base
tuple_like<remove_cvref_t<tuple_t>> &&
detail::all_satisfy_aligned_seq<detail::tuple_type_list_t<remove_cvref_t<tuple_t>>>
//!\endcond
inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & stream, tuple_t && alignment)
{
static_assert(std::tuple_size_v<remove_cvref_t<tuple_t>> >= 2, "An alignment requires at least two sequences.");
detail::stream_alignment(stream, alignment, std::make_index_sequence<std::tuple_size_v<remove_cvref_t<tuple_t>> - 1> {});
return stream;
}
} // namespace seqan