File: alphabet_conversion.cpp

package info (click to toggle)
seqan3 3.4.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,580 kB
  • sloc: cpp: 145,192; sh: 305; xml: 264; javascript: 95; makefile: 70; perl: 29; php: 15
file content (47 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download
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
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0

#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/quality/aliases.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/core/debug_stream.hpp>

using seqan3::operator""_dna4;
using seqan3::operator""_dna5;
using seqan3::operator""_phred42;

int main()
{
    // A vector of combined sequence and quality information.
    std::vector<seqan3::dna4q> sequence1{{'A'_dna4, '!'_phred42},
                                         {'C'_dna4, 'A'_phred42},
                                         {'G'_dna4, '6'_phred42},
                                         {'T'_dna4, '&'_phred42}};
    // A vector of dna5.
    std::vector<seqan3::dna5> sequence2{"AGNCGTNNCAN"_dna5};

    // Convert dna4q to dna4.
    // Since `sequence1` is an lvalue, we capture `in` via const &. When unsure, use the general case below.
    auto view1 = sequence1
               | std::views::transform(
                     [](auto const & in)
                     {
                         return static_cast<seqan3::dna4>(in);
                     });
    seqan3::debug_stream << view1 << '\n'; // ACGT

    // Convert dna5 to dna4.
    // General case: Perfect forward.
    auto view2 = sequence2 | std::views::take(8)
               | std::views::transform(
                     [](auto && in)
                     {
                         return static_cast<seqan3::dna4>(std::forward<decltype(in)>(in));
                     });
    seqan3::debug_stream << view2 << '\n'; // AGACGTAA

    return 0;
}