Loading...
Searching...
No Matches
The SeqAn Cookbook

This document provides example recipes on how to carry out particular tasks using the SeqAn functionalities in C++. Please note that these recipes are not ordered. You can use the links in the table of contents or the search function of your browser to navigate them.

It will take some time, but we hope to expand this document into containing numerous great examples. If you have suggestions for how to improve the Cookbook and/or examples you would like included, please feel free to contact us.

# Read sequence files

#include <string>
#include <seqan3/core/debug_stream.hpp> // for debug_stream
#include <seqan3/io/sequence_file/input.hpp> // for sequence_file_input
int main()
{
std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the tmp directory
// Initialise a file input object with a FASTA file.
seqan3::sequence_file_input file_in{tmp_dir / "seq.fasta"};
// Retrieve the sequences and ids.
for (auto & [seq, id, qual] : file_in)
{
seqan3::debug_stream << "ID: " << id << '\n';
seqan3::debug_stream << "SEQ: " << seq << '\n';
seqan3::debug_stream << "Empty Qual." << qual << '\n'; // qual is empty for FASTA files
}
return 0;
}

# Construction and assignment of alphabet symbols

#include <seqan3/alphabet/all.hpp> // for working with alphabets directly
int main()
{
using namespace seqan3::literals;
// Two objects of seqan3::dna4 alphabet constructed with a char literal.
seqan3::dna4 ade = 'A'_dna4;
seqan3::dna4 gua = 'G'_dna4;
// Two additional objects assigned explicitly from char or rank.
seqan3::dna4 cyt, thy;
cyt.assign_char('C');
thy.assign_rank(3);
// Further code here...
return 0;
}
// Get the rank type of the alphabet (here uint8_t).
using rank_type = seqan3::alphabet_rank_t<seqan3::dna4>;
// Retrieve the numerical representation (rank) of the objects.
rank_type rank_a = ade.to_rank(); // => 0
rank_type rank_g = gua.to_rank(); // => 2

# Reverse complement and the six-frame translation of a string using views

This recipe creates a small program that

1. reads a string from the command line (first argument to the program)
2. "converts" the string to a range of seqan3::dna5 (Bonus: throws an exception if loss of information occurs)
3. prints the string and its reverse complement
4. prints the six-frame translation of the string

// 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 <ranges> // include all of the standard library's views
#include <seqan3/alphabet/views/all.hpp> // include all of SeqAn's views
#include <seqan3/argument_parser/all.hpp> // optional: include the argument_parser
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char ** argv)
{
// We use the seqan3::argument_parser which was introduced in the second chapter
// of the tutorial: "Parsing command line arguments with SeqAn".
seqan3::argument_parser myparser{"Assignment-3", argc, argv}; // initialize
std::string s{};
myparser.add_positional_option(s, "Please specify the DNA string.");
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR]" << ext.what() << '\n'; // you can customize your error message
return 0;
}
auto s_as_dna = s | seqan3::views::char_to<seqan3::dna5>;
// Bonus:
//auto s_as_dna = s | std::views::transform([] (char const c)
//{
// return seqan3::assign_char_strictly_to(c, seqan3::dna5{});
//});
seqan3::debug_stream << "Original: " << s_as_dna << '\n';
seqan3::debug_stream << "RevComp: " << (s_as_dna | std::views::reverse | seqan3::views::complement) << '\n';
seqan3::debug_stream << "Frames: " << (s_as_dna | seqan3::views::translate) << '\n';
}
all.hpp
Meta-header for the Alphabet / Views submodule .
all.hpp
Meta-header for the Argument Parser module .
std::string
std::cerr
seqan3::argument_parser_error
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition exceptions.hpp:39
seqan3::argument_parser
The SeqAn command line parser.
Definition argument_parser.hpp:147
seqan3::argument_parser::add_positional_option
void add_positional_option(option_type &value, std::string const &desc, validator_type option_validator=validator_type{})
Adds a positional option to the seqan3::argument_parser.
Definition argument_parser.hpp:314
seqan3::argument_parser::parse
void parse()
Initiates the actual command line parsing.
Definition argument_parser.hpp:404
debug_stream.hpp
Provides seqan3::debug_stream and related types.
seqan3::views::translate
constexpr auto translate
A view that translates nucleotide into aminoacid alphabet with 1, 2, 3 or 6 frames.
Definition translate.hpp:800
seqan3::views::complement
auto const complement
A view that converts a range of nucleotides to their complement.
Definition complement.hpp:64
seqan3::views::char_to
auto const char_to
A view over an alphabet, given a range of characters.
Definition char_to.hpp:64
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38
std::runtime_error::what
T what(T... args)

# Reading records

After construction, you can now read the sequence records. Our file object behaves like a range, you can use a range-based for loop to conveniently iterate over the file:

// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
for (auto & record : fin)
{
seqan3::debug_stream << "ID: " << record.id() << '\n';
seqan3::debug_stream << "SEQ: " << record.sequence() << '\n';
// a quality field also exists, but is not printed, because we know it's empty for FASTA files.
}
}
std::istringstream
seqan3::format_fasta
The FASTA format.
Definition format_fasta.hpp:77
seqan3::sequence_file_input
A class for reading sequence files, e.g. FASTA, FASTQ ...
Definition sequence_file/input.hpp:206
input.hpp
Provides seqan3::sequence_file_input and corresponding traits classes.
sstream

Attention
  An input file is a single input range, which means you can only iterate over it once!

Note
  It is important to write auto & and not just auto, otherwise you will copy the record on every iteration.

You can also use structured binding, i.e. for (auto & [seq, id, qual] : fin) But beware: with structured bindings you do need to get the order of elements correct!

You can also read a file in chunks:

# Reading records in chunks

#include <seqan3/io/sequence_file/all.hpp>
#include <seqan3/utility/views/chunk.hpp>
int main()
{
seqan3::sequence_file_input fin{std::filesystem::current_path() / "my.fastq"};
// `&&` is important because seqan3::views::chunk returns temporaries!
for (auto && records : fin | seqan3::views::chunk(10))
{
// `records` contains 10 elements (or less at the end)
seqan3::debug_stream << "Taking the next 10 sequences:\n";
seqan3::debug_stream << "ID: " << (*records.begin()).id() << '\n'; // prints first ID in batch
}

The example above will iterate over the file by reading 10 records at a time. If no 10 records are available anymore, it will just print the remaining records.

# Applying a filter to a file

On some occasions you are only interested in sequence records that fulfill a certain criterion, e.g. having a minimum sequence length or a minimum average quality.

This recipe can be used to filter the sequences in your file by a custom criterion.

#include <numeric> // std::accumulate
#include <ranges>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/all.hpp>
int main()
{
seqan3::sequence_file_input fin{std::filesystem::current_path() / "my.fastq"};
// std::views::filter takes a function object (a lambda in this case) as input that returns a boolean
auto minimum_quality_filter = std::views::filter(
[](auto const & rec)
{
auto qualities = rec.base_qualities()
| std::views::transform(
[](auto quality)
{
return seqan3::to_phred(quality);
});
auto sum = std::accumulate(qualities.begin(), qualities.end(), 0);
return sum / std::ranges::size(qualities) >= 40; // minimum average quality >= 40
});
for (auto & rec : fin | minimum_quality_filter)
{
seqan3::debug_stream << "ID: " << rec.id() << '\n';
}
}

# Reading paired-end reads

In modern Next Generation Sequencing experiments you often have paired-end read data which is split into two files. The read pairs are identified by their identical name/id and position in the two files.

This recipe can be used to handle one pair of reads at a time.

#include <seqan3/io/sequence_file/all.hpp>
#include <seqan3/utility/views/zip.hpp>
int main()
{
// for simplicity we take the same file
seqan3::sequence_file_input fin1{std::filesystem::current_path() / "my.fastq"};
seqan3::sequence_file_input fin2{std::filesystem::current_path() / "my.fastq"};
for (auto && [rec1, rec2] : seqan3::views::zip(fin1, fin2)) // && is important!
{ // because seqan3::views::zip returns temporaries
if (rec1.id() != rec2.id())
throw std::runtime_error("Your pairs don't match.");
}
}

# Storing records in a std::vector

This recipe creates a small program that reads in a FASTA file and stores all the records in a std::vector.

#include <filesystem>
#include <ranges> // std::ranges::copy
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/all.hpp>
int main()
{
std::filesystem::path current_path = std::filesystem::current_path();
seqan3::sequence_file_input fin{current_path / "my.fasta"};
using record_type = decltype(fin)::record_type;
std::vector<record_type> records{};
// You can use a for loop:
for (auto & record : fin)
{
records.push_back(std::move(record));
}
// But you can also do this:
std::ranges::copy(fin, std::back_inserter(records));
seqan3::debug_stream << records << '\n';
}

Note that you can move the record out of the file if you want to store it somewhere without copying.

#include <seqan3/io/sequence_file/all.hpp>
int main()
{
seqan3::sequence_file_input fin{std::filesystem::current_path() / "my.fastq"};
using record_type = typename decltype(fin)::record_type;
record_type rec = std::move(*fin.begin()); // avoid copying
}

# Writing records

The easiest way to write to a sequence file is to use the seqan3::sequence_file_output::push_back() or seqan3::sequence_file_output::emplace_back() member functions. These work similarly to how they work on a std::vector.

// 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 <string>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
#include <seqan3/io/sequence_file/record.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::cout, seqan3::format_fasta{}};
using types = seqan3::type_list<std::vector<seqan3::dna5>, std::string>;
using fields = seqan3::fields<seqan3::field::seq, seqan3::field::id>;
using sequence_record_type = seqan3::sequence_record<types, fields>;
for (int i = 0; i < 5; ++i) // ...
{
std::string id{"test_id"};
seqan3::dna5_vector sequence{"ACGT"_dna5};
sequence_record_type record{std::move(sequence), std::move(id)};
fout.push_back(record);
}
}
seqan3::sequence_file_output
A class for writing sequence files, e.g. FASTA, FASTQ ...
Definition io/sequence_file/output.hpp:66
seqan3::sequence_file_output::push_back
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition io/sequence_file/output.hpp:273
seqan3::sequence_record
The record type of seqan3::sequence_file_input.
Definition sequence_file/record.hpp:26
std::cout
dna5.hpp
Provides seqan3::dna5, container aliases and string literals.
sequence
The generic concept for a (biological) sequence.
output.hpp
Provides seqan3::sequence_file_output and corresponding traits classes.
seqan3::literals
The SeqAn namespace for literals.
record.hpp
Provides seqan3::sequence_record.
string
seqan3::fields
A class template that holds a choice of seqan3::field.
Definition record.hpp:125
seqan3::record
The class template that file records are based on; behaves like a std::tuple.
Definition record.hpp:190
seqan3::type_list
Type that contains multiple types.
Definition type_list.hpp:26

# File conversion

#include <seqan3/io/sequence_file/all.hpp>
int main()
{
auto current_path = std::filesystem::current_path();
seqan3::sequence_file_output{current_path / "output.fasta"} =
seqan3::sequence_file_input{current_path / "my.fastq"};
}

# Define a custom scoring scheme

#include <seqan3/alignment/scoring/aminoacid_scoring_scheme.hpp>
#include <seqan3/alignment/scoring/hamming_scoring_scheme.hpp>
#include <seqan3/alignment/scoring/nucleotide_scoring_scheme.hpp>
using namespace seqan3::literals;
// Define a simple scoring scheme with match and mismatch cost and get the score.
seqan3::nucleotide_scoring_scheme nc_scheme{seqan3::match_score{4}, seqan3::mismatch_score{-5}};
auto sc_nc = nc_scheme.score('A'_dna4, 'C'_dna4); // sc_nc == -5.
// Define a amino acid similarity matrix and get the score.
seqan3::aminoacid_scoring_scheme aa_scheme{};
aa_scheme.set_similarity_matrix(seqan3::aminoacid_similarity_matrix::blosum30);
auto sc_aa = aa_scheme.score('M'_aa27, 'K'_aa27); // sc_aa == 2.

Attention
  SeqAn's alignment algorithm computes the maximal similarity score, thus the match score must be set to a positive value and the scores for mismatch and gap must be negative in order to maximize over the matching letters.

# Calculate edit distance for a set of sequences

This recipe can be used to calculate the edit distance for all six pairwise combinations. Here we only allow at most 7 errors and filter all alignments with 6 or fewer errors.

// 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 <ranges>
#include <utility>
#include <vector>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alignment/scoring/nucleotide_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/pairwise_combine.hpp>
int main()
{
using namespace seqan3::literals;
std::vector vec{"ACGTGACTGACT"_dna4, "ACGAAGACCGAT"_dna4, "ACGTGACTGACT"_dna4, "AGGTACGAGCGACACT"_dna4};
// Configure the alignment kernel.
auto config = seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme | seqan3::align_cfg::min_score{-7}
| seqan3::align_cfg::output_score{};
auto alignment_results = seqan3::align_pairwise(seqan3::views::pairwise_combine(vec), config);
auto filter_v = std::views::filter(
[](auto && res)
{
return res.score() >= -6;
});
for (auto const & result : alignment_results | filter_v)
{
seqan3::debug_stream << "Score: " << result.score() << '\n';
}
}
align_pairwise.hpp
Provides pairwise alignment function.
seqan3::align_cfg::method_global
Sets the global alignment method.
Definition align_config_method.hpp:119
seqan3::align_cfg::min_score
Sets the minimal score (maximal errors) allowed during an distance computation e.g....
Definition align_config_min_score.hpp:36
seqan3::align_cfg::output_score
Configures the alignment result to output the score.
Definition align_config_output.hpp:40
dna4.hpp
Provides seqan3::dna4, container aliases and string literals.
seqan3::align_cfg::edit_scheme
constexpr configuration edit_scheme
Shortcut for edit distance configuration.
Definition align_config_edit.hpp:48
seqan3::align_pairwise
constexpr auto align_pairwise(sequence_t &&seq, alignment_config_t const &config)
Computes the pairwise alignment for a pair of sequences or a range over sequence pairs.
Definition align_pairwise.hpp:130
seqan3::views::pairwise_combine
constexpr auto pairwise_combine
A view adaptor that generates all pairwise combinations of the elements of the underlying range.
Definition pairwise_combine.hpp:647
nucleotide_scoring_scheme.hpp
Provides seqan3::nucleotide_scoring_scheme.
pairwise_combine.hpp
Provides seqan3::views::pairwise_combine.
utility
vector

# Searching for matches

This recipe can be used to search for all occurrences of a substring and print the number of hits and the positions in an ascending ordering.

// 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/core/debug_stream.hpp>
#include <seqan3/search/fm_index/fm_index.hpp>
#include <seqan3/search/search.hpp>
using namespace seqan3::literals;
void run_text_single()
{
seqan3::dna4_vector text{
"CGCTGTCTGAAGGATGAGTGTCAGCCAGTGTAACCCGATGAGCTACCCAGTAGTCGAACTGGGCCAGACAACCCGGCGCTAATGCACTCA"_dna4};
seqan3::fm_index index{text};
seqan3::debug_stream << "===== Running on a single text =====\n"
<< "The following hits were found:\n";
for (auto && result : search("GCT"_dna4, index))
seqan3::debug_stream << result << '\n';
}
void run_text_collection()
{
std::vector<seqan3::dna4_vector> text{"CGCTGTCTGAAGGATGAGTGTCAGCCAGTGTA"_dna4,
"ACCCGATGAGCTACCCAGTAGTCGAACTG"_dna4,
"GGCCAGACAACCCGGCGCTAATGCACTCA"_dna4};
seqan3::fm_index index{text};
seqan3::debug_stream << "===== Running on a text collection =====\n"
<< "The following hits were found:\n";
for (auto && result : search("GCT"_dna4, index))
seqan3::debug_stream << result << '\n';
}
int main()
{
run_text_single();
seqan3::debug_stream << '\n';
run_text_collection();
}
seqan3::fm_index
The SeqAn FM Index.
Definition fm_index.hpp:185
fm_index.hpp
Provides the unidirectional seqan3::fm_index.
seqan3::search
auto search(queries_t &&queries, index_t const &index, configuration_t const &cfg=search_cfg::default_configuration)
Search a query or a range of queries in an index.
Definition search.hpp:104
search.hpp
Provides the public interface for search algorithms.

If you want to allow errors in your query, you need to configure the approximate search with the following search configuration objects:

- seqan3::search_cfg::max_error_total: Maximum number of total errors
- seqan3::search_cfg::max_error_substitution: Maximum number of substitutions
- seqan3::search_cfg::max_error_insertion: Maximum number of insertions
- seqan3::search_cfg::max_error_deletion: Maximum number of deletions These are constructed with absolute numbers or rates:
- seqan3::search_cfg::error_count: Absolute number of errors
- seqan3::search_cfg::error_rate: Rate of errors

To search for either 1 insertion or 1 deletion you can use the seqan3::search_cfg::error_count:

std::string text{"Garfield the fat cat without a hat."};
seqan3::fm_index index{text};
seqan3::configuration const cfg = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}}
| seqan3::search_cfg::max_error_substitution{seqan3::search_cfg::error_count{0}}
| seqan3::search_cfg::max_error_insertion{seqan3::search_cfg::error_count{1}}
| seqan3::search_cfg::max_error_deletion{seqan3::search_cfg::error_count{1}};
seqan3::debug_stream << search("cat"s, index, cfg) << '\n';
// prints: [<query_id:0, reference_id:0, reference_pos:14>,
// <query_id:0, reference_id:0, reference_pos:17>,
// <query_id:0, reference_id:0, reference_pos:18>,
// <query_id:0, reference_id:0, reference_pos:32>]

# Reading the CIGAR information from a SAM file and constructing an alignment

This recipe can be used to:

1. Read in a FASTA file with the reference and a SAM file with the alignment
2. Filter the alignment records and only take those with a mapping quality >= 30.
3. For the resulting alignments, print which read was mapped against with reference id and the number of seqan3::gap's involved in the alignment (either in aligned reference or in read sequence).

#include <algorithm> // std::ranges::count
#include <filesystem>
#include <ranges>
#include <string>
#include <vector>
#include <seqan3/alignment/cigar_conversion/alignment_from_cigar.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/record.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/io/sequence_file/input.hpp>
int main()
{
std::filesystem::path current_path = std::filesystem::current_path();
// read in reference information
seqan3::sequence_file_input reference_file{current_path / "reference.fasta"};
std::vector<std::string> reference_ids{};
std::vector<seqan3::dna5_vector> reference_sequences{};
for (auto && record : reference_file)
{
reference_ids.push_back(std::move(record.id()));
reference_sequences.push_back(std::move(record.sequence()));
}
// filter out alignments
seqan3::sam_file_input mapping_file{current_path / "mapping.sam", reference_ids, reference_sequences};
auto mapq_filter = std::views::filter(
[](auto & record)
{
return record.mapping_quality() >= 30;
});
for (auto & record : mapping_file | mapq_filter)
{
auto alignment = seqan3::alignment_from_cigar(record.cigar_sequence(),
reference_sequences[record.reference_id().value()],
record.reference_position().value(),
record.sequence());
// as loop
size_t sum_reference{};
for (auto const & char_reference : std::get<0>(alignment))
if (char_reference == seqan3::gap{})
++sum_reference;
// or via std::ranges::count
size_t sum_read = std::ranges::count(std::get<1>(alignment), seqan3::gap{});
// The reference_id is ZERO based and an optional. -1 is represented by std::nullopt (= reference not known).
std::optional reference_id = record.reference_id();
seqan3::debug_stream << record.id() << " mapped against "
<< (reference_id ? std::to_string(reference_id.value()) : "unknown reference") << " with "
<< sum_read << " gaps in the read sequence and " << sum_reference
<< " gaps in the reference sequence.\n";
}
}

# Map reads and write output to SAM file

For a full recipe on creating your own readmapper, see the very end of the tutorial Implementing your own read mapper with SeqAn.

void map_reads(std::filesystem::path const & query_path,
std::filesystem::path const & index_path,
std::filesystem::path const & sam_path,
reference_storage_t & storage,
uint8_t const errors)
{
// we need the alphabet and text layout before loading
seqan3::bi_fm_index<seqan3::dna5, seqan3::text_layout::collection> index;
{
std::ifstream is{index_path, std::ios::binary};
cereal::BinaryInputArchive iarchive{is};
iarchive(index);
}
seqan3::sequence_file_input query_file_in{query_path};
seqan3::sam_file_output sam_out{sam_path,
seqan3::fields<seqan3::field::seq,
seqan3::field::id,
seqan3::field::ref_id,
seqan3::field::ref_offset,
seqan3::field::cigar,
seqan3::field::qual,
seqan3::field::mapq>{}};
seqan3::configuration const search_config =
seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{errors}}
| seqan3::search_cfg::hit_all_best{};
seqan3::configuration const align_config =
seqan3::align_cfg::method_global{seqan3::align_cfg::free_end_gaps_sequence1_leading{true},
seqan3::align_cfg::free_end_gaps_sequence2_leading{false},
seqan3::align_cfg::free_end_gaps_sequence1_trailing{true},
seqan3::align_cfg::free_end_gaps_sequence2_trailing{false}}
| seqan3::align_cfg::edit_scheme | seqan3::align_cfg::output_alignment{}
| seqan3::align_cfg::output_begin_position{} | seqan3::align_cfg::output_score{};
for (auto && record : query_file_in)
{
auto & query = record.sequence();
for (auto && result : search(query, index, search_config))
{
size_t start = result.reference_begin_position() ? result.reference_begin_position() - 1 : 0;
std::span text_view{std::data(storage.seqs[result.reference_id()]) + start, query.size() + 1};
for (auto && alignment : seqan3::align_pairwise(std::tie(text_view, query), align_config))
{
auto cigar = seqan3::cigar_from_alignment(alignment.alignment());
size_t ref_offset = alignment.sequence1_begin_position() + 2 + start;
size_t map_qual = 60u + alignment.score();
sam_out.emplace_back(query,
record.id(),
storage.ids[result.reference_id()],
ref_offset,
cigar,
record.base_qualities(),
map_qual);
}
}
}
}

# Constructing a basic argument parser

// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
void run_program(std::filesystem::path const & reference_path, std::filesystem::path const & index_path)
{
seqan3::debug_stream << "reference_file_path: " << reference_path << '\n';
seqan3::debug_stream << "index_path " << index_path << '\n';
}
struct cmd_arguments
{
std::filesystem::path reference_path{};
std::filesystem::path index_path{"out.index"};
};
void initialise_argument_parser(seqan3::argument_parser & parser, cmd_arguments & args)
{
parser.info.author = "E. coli";
parser.info.short_description = "Creates an index over a reference.";
parser.info.version = "1.0.0";
parser.add_option(args.reference_path,
'r',
"reference",
"The path to the reference.",
seqan3::option_spec::required,
seqan3::input_file_validator{{"fa", "fasta"}});
parser.add_option(args.index_path,
'o',
"output",
"The output index file path.",
seqan3::option_spec::standard,
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"index"}});
}
int main(int argc, char const ** argv)
{
seqan3::argument_parser parser("Indexer", argc, argv);
cmd_arguments args{};
initialise_argument_parser(parser, args);
try
{
parser.parse();
}
catch (seqan3::argument_parser_error const & ext)
{
std::cerr << "[PARSER ERROR] " << ext.what() << '\n';
return -1;
}
run_program(args.reference_path, args.index_path);
return 0;
}
seqan3::argument_parser::add_option
void add_option(option_type &value, char const short_id, std::string const &long_id, std::string const &desc, option_spec const spec=option_spec::standard, validator_type option_validator=validator_type{})
Adds an option to the seqan3::argument_parser.
Definition argument_parser.hpp:238
seqan3::argument_parser::info
argument_parser_meta_data info
Aggregates all parser related meta data (see seqan3::argument_parser_meta_data struct).
Definition argument_parser.hpp:636
seqan3::input_file_validator
A validator that checks if a given path is a valid input file.
Definition validators.hpp:517
seqan3::output_file_validator
A validator that checks if a given path is a valid output file.
Definition validators.hpp:647
seqan3::standard
@ standard
The default were no checking or special displaying is happening.
Definition auxiliary.hpp:250
seqan3::required
@ required
Definition auxiliary.hpp:251
std::filesystem::path
seqan3::argument_parser_meta_data::author
std::string author
Your name ;-).
Definition auxiliary.hpp:299
seqan3::argument_parser_meta_data::version
std::string version
The version information MAJOR.MINOR.PATH (e.g. 3.1.3).
Definition auxiliary.hpp:295
seqan3::argument_parser_meta_data::short_description
std::string short_description
A short description of the application (e.g. "A tool for mapping reads to the genome").
Definition auxiliary.hpp:297

# Constructing a subcommand argument parser

// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
// =====================================================================================================================
// pull
// =====================================================================================================================
struct pull_arguments
{
std::string repository{};
std::string branch{};
bool progress{false};
};
int run_git_pull(seqan3::argument_parser & parser)
{
pull_arguments args{};
parser.add_positional_option(args.repository, "The repository name to pull from.");
parser.add_positional_option(args.branch, "The branch name to pull from.");
try
{
parser.parse();
}
catch (seqan3::argument_parser_error const & ext)
{
seqan3::debug_stream << "[Error git pull] " << ext.what() << "\n";
return -1;
}
seqan3::debug_stream << "Git pull with repository " << args.repository << " and branch " << args.branch << '\n';
return 0;
}
// =====================================================================================================================
// push
// =====================================================================================================================
struct push_arguments
{
std::string repository{};
std::vector<std::string> branches{};
bool push_all{false};
};
int run_git_push(seqan3::argument_parser & parser)
{
push_arguments args{};
parser.add_positional_option(args.repository, "The repository name to push to.");
parser.add_positional_option(args.branches, "The branch names to push (if none are given, push current).");
try
{
parser.parse();
}
catch (seqan3::argument_parser_error const & ext)
{
seqan3::debug_stream << "[Error git push] " << ext.what() << "\n";
return -1;
}
seqan3::debug_stream << "Git push with repository " << args.repository << " and branches " << args.branches << '\n';
return 0;
}
// =====================================================================================================================
// main
// =====================================================================================================================
int main(int argc, char const ** argv)
{
seqan3::argument_parser top_level_parser{"mygit", argc, argv, seqan3::update_notifications::on, {"push", "pull"}};
// Add information and flags, but no (positional) options to your top-level parser.
// Because of ambiguity, we do not allow any (positional) options for the top-level parser.
top_level_parser.info.description.push_back("You can push or pull from a remote repository.");
// A flag's default value must be false.
bool flag{false};
top_level_parser.add_flag(flag, 'f', "flag", "some flag");
try
{
top_level_parser.parse(); // trigger command line parsing
}
catch (seqan3::argument_parser_error const & ext) // catch user errors
{
seqan3::debug_stream << "[Error] " << ext.what() << "\n"; // customise your error message
return -1;
}
seqan3::argument_parser & sub_parser = top_level_parser.get_sub_parser(); // hold a reference to the sub_parser
std::cout << "Proceed to sub parser.\n";
if (sub_parser.info.app_name == std::string_view{"mygit-pull"})
return run_git_pull(sub_parser);
else if (sub_parser.info.app_name == std::string_view{"mygit-push"})
return run_git_push(sub_parser);
else
std::cout << "Unhandled subparser named " << sub_parser.info.app_name << '\n';
// Note: Arriving in this else branch means you did not handle all sub_parsers in the if branches above.
return 0;
}
std::string_view
seqan3::argument_parser::add_flag
void add_flag(bool &value, char const short_id, std::string const &long_id, std::string const &desc, option_spec const spec=option_spec::standard)
Adds a flag to the seqan3::argument_parser.
Definition argument_parser.hpp:270
seqan3::argument_parser::get_sub_parser
argument_parser & get_sub_parser()
Returns a reference to the sub-parser instance if subcommand parsing was enabled.
Definition argument_parser.hpp:438
seqan3::field::flag
@ flag
The alignment flag (bit information), uint16_t value.
Definition record.hpp:84
seqan3::update_notifications::on
@ on
Automatic update notifications should be enabled.
Definition auxiliary.hpp:269
std::vector::push_back
T push_back(T... args)
seqan3::argument_parser_meta_data::app_name
std::string app_name
The application name that will be displayed on the help page.
Definition auxiliary.hpp:293
seqan3::argument_parser_meta_data::description
std::vector< std::string > description
A more detailed description that is displayed on the help page in the section "DESCRIPTION"....
Definition auxiliary.hpp:327

# Serialise data structures with cereal

// 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 <fstream>
#include <vector>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/test/tmp_directory.hpp>
#include <cereal/archives/binary.hpp> // includes the cereal::BinaryInputArchive and cereal::BinaryOutputArchive
#include <cereal/types/vector.hpp> // includes cerealisation support for std::vector
// Written for std::vector, other types also work.
void load(std::vector<int16_t> & data, std::filesystem::path const & tmp_file)
{
std::ifstream is(tmp_file, std::ios::binary); // Where input can be found.
cereal::BinaryInputArchive archive(is); // Create an input archive from the input stream.
archive(data); // Load data.
}
// Written for std::vector, other types also work.
void store(std::vector<int16_t> const & data, std::filesystem::path const & tmp_file)
{
std::ofstream os(tmp_file, std::ios::binary); // Where output should be stored.
cereal::BinaryOutputArchive archive(os); // Create an output archive from the output stream.
archive(data); // Store data.
}
int main()
{
// The following example is for a std::vector but any seqan3 data structure that is documented as serialisable
// could be used, e.g. seqan3::fm_index.
seqan3::test::tmp_directory tmp{};
auto tmp_file = tmp.path() / "data.out"; // This is a temporary file name, use any other filename.
std::vector<int16_t> vec{1, 2, 3, 4};
store(vec, tmp_file); // Calls store on a std::vector.
// This vector is needed to load the information into it.
std::vector<int16_t> vec2;
load(vec2, tmp_file); // Calls load on a std::vector.
seqan3::debug_stream << vec2 << '\n'; // Prints [1,2,3,4].
return 0;
}
std::ifstream
std::ofstream
fstream

# Converting a range of an alphabet

// 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;
}
aliases.hpp
Provides aliases for qualified.
seqan3::dna4
The four letter DNA alphabet of A,C,G,T.
Definition dna4.hpp:50
std::forward
T forward(T... args)
phred42.hpp
Provides seqan3::phred42 quality scores.
qualified.hpp
Provides quality alphabet composites.

# A custom dna4 alphabet that converts all unknown characters to A

When assigning from char or converting from a larger nucleotide alphabet to a smaller one, loss of information can occur since obviously some bases are not available. When converting to seqan3::dna5 or seqan3::rna5, non-canonical bases (letters other than A, C, G, T, U) are converted to 'N' to preserve ambiguity at that position. For seqan3::dna4 and seqan3::rna4 there is no letter 'N' to represent ambiguity, so the conversion from char for IUPAC characters tries to choose the best fitting alternative (see seqan3::dna4 for more details).

If you would like to always convert unknown characters to A instead, you can create your own alphabet with a respective char conversion table very easily like this:

// 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/nucleotide_base.hpp>
#include <seqan3/core/debug_stream.hpp>
// We inherit from seqan3::nucleotide_base s.t. we do not need to implement the full nucleotide interface
// but it is sufficient to define `rank_to_char`, `char_to_rank`, and `complement_table`.
class my_dna4 : public seqan3::nucleotide_base<my_dna4, 4 /*alphabet size is 4*/>
{
public:
using nucleotide_base<my_dna4, 4>::nucleotide_base; // Use constructors of the base class.
private:
// Returns the character representation of rank. This is where rank conversion for to_char() is handled!
static constexpr char_type rank_to_char(rank_type const rank)
{
return rank_to_char_table[rank];
}
// Returns the rank representation of character. This is where char conversion for assign_char() is handled!
static constexpr rank_type char_to_rank(char_type const chr)
{
using index_t = std::make_unsigned_t<char_type>;
return char_to_rank_table[static_cast<index_t>(chr)];
}
// Returns the complement by rank. This is where complement is handled and with this, my_dna4 models
// seqan3::nucleotide_alphabet.
static constexpr rank_type rank_complement(rank_type const rank)
{
return rank_complement_table[rank];
}
private:
// === lookup-table implementation detail ===
// Value to char conversion table.
static constexpr char_type rank_to_char_table[alphabet_size]{'A', 'C', 'G', 'T'}; // rank 0,1,2,3
// Char-to-value conversion table.
static constexpr std::array<rank_type, 256> char_to_rank_table{
[]() constexpr
{
// By default, everything has rank 0 which equals `A`.
std::array<rank_type, 256> conversion_table{};
conversion_table['C'] = conversion_table['c'] = 1;
conversion_table['G'] = conversion_table['g'] = 2;
conversion_table['T'] = conversion_table['t'] = 3;
conversion_table['U'] = conversion_table['T']; // set U equal to T
conversion_table['u'] = conversion_table['t']; // set u equal to t
return conversion_table;
}()};
// The rank complement table.
static constexpr rank_type rank_complement_table[alphabet_size]{
3, // T is complement of 'A'_dna4
2, // G is complement of 'C'_dna4
1, // C is complement of 'G'_dna4
0 // A is complement of 'T'_dna4
};
friend nucleotide_base<my_dna4, 4>; // Grant seqan3::nucleotide_base access to private/protected members.
friend nucleotide_base<my_dna4, 4>::base_t; // Grant seqan3::alphabet_base access to private/protected members.
};
// Defines the `_my_dna4` *char literal* so you can write `'C'_my_dna4` instead of `my_dna4{}.assign_char('C')`.
constexpr my_dna4 operator""_my_dna4(char const c) noexcept
{
return my_dna4{}.assign_char(c);
}
int main()
{
my_dna4 my_letter{'C'_my_dna4};
my_letter.assign_char('S'); // Characters other than A,C,G,T are implicitly converted to `A`.
seqan3::debug_stream << my_letter << "\n"; // "A";
seqan3::debug_stream << seqan3::complement(my_letter) << "\n"; // "T";
}
seqan3::nucleotide_base
A CRTP-base that refines seqan3::alphabet_base and is used by the nucleotides.
Definition nucleotide_base.hpp:41
seqan3::complement
constexpr auto complement
Return the complement of a nucleotide object.
Definition alphabet/nucleotide/concept.hpp:102
seqan3::alphabet_size
constexpr auto alphabet_size
A type trait that holds the size of a (semi-)alphabet.
Definition alphabet/concept.hpp:834
std::make_unsigned_t
nucleotide_base.hpp
Provides seqan3::nucleotide_base.

If you are interested in custom alphabets, also take a look at our tutorial How to write your own alphabet.

# Controlling threads of (de-)compression streams

When reading or writing compressed files, parallelisation is automatically applied when using BGZF-compressed files, e.g., BAM files. This will use 4 threads by default and can be adjusted by setting seqan3::contrib::bgzf_thread_count to the desired value:

# include <seqan3/io/all.hpp>
// The `bgzf_thread_count` is a variable that can only be changed during the runtime of a program.
// The following does not work, the value must be overwritten within a function:
// seqan3::contrib::bgzf_thread_count = 1u; // Does not work.
int main()
{
// Here, we change the number of threads to `1`.
// This is a global change and will affect every future bgzf (de-)compression.
// However, running (de-)compressions will not be affected.
// `bgzf_thread_count` may be overwritten multiple times during the runtime of a program, in which case
// the latest modification will determine the value.
seqan3::contrib::bgzf_thread_count = 1u;
// Read/Write compressed files.
// ...
return 0;
}

# Auto vectorized dna4 complement

Our alphabet seqan3::dna4 cannot be easily auto-vectorized by the compiler.

See this discussion for more details.

You can add your own alphabet that is auto-vectorizable in some use cases. Here is an example for a dna4-like alphabet:

class simd_dna4 : public seqan3::nucleotide_base<simd_dna4, 256>
{
private:
using base_t = seqan3::nucleotide_base<simd_dna4, 256>;
friend base_t; // nucleotide_base
friend base_t::base_t; // alphabet_base
friend seqan3::rna4;
public:
constexpr simd_dna4() noexcept = default;
constexpr simd_dna4(simd_dna4 const &) noexcept = default;
constexpr simd_dna4(simd_dna4 &&) noexcept = default;
constexpr simd_dna4 & operator=(simd_dna4 const &) noexcept = default;
constexpr simd_dna4 & operator=(simd_dna4 &&) noexcept = default;
~simd_dna4() noexcept = default;
template <std::same_as<seqan3::rna4> t> // template parameter t to accept incomplete type
constexpr simd_dna4(t const r) noexcept
{
assign_rank(r.to_rank());
}
using base_t::assign_rank;
using base_t::base_t;
using base_t::to_rank;
static constexpr uint8_t alphabet_size = 4;
constexpr simd_dna4 & assign_char(char_type const c) noexcept
{
char_type const upper_case_char = c & 0b0101'1111;
rank_type rank = (upper_case_char == 'T') * 3 + (upper_case_char == 'G') * 2 + (upper_case_char == 'C');
return assign_rank(rank);
}
constexpr char_type to_char() const noexcept
{
rank_type const rank = to_rank();
switch (rank)
{
case 0u:
return 'A';
case 1u:
return 'C';
case 2u:
return 'G';
default:
return 'T';
}
}
constexpr simd_dna4 complement() const noexcept
{
rank_type rank{to_rank()};
rank ^= 0b11;
simd_dna4 ret{};
return ret.assign_rank(rank);
}
static constexpr bool char_is_valid(char_type const c) noexcept
{
char_type const upper_case_char = c & 0b0101'1111;
return (upper_case_char == 'A') || (upper_case_char == 'C') || (upper_case_char == 'G')
|| (upper_case_char == 'T');
}
};

# All SeqAn documentation snippets

The following lists all snippets that appear in our documentation. Search for keywords with Strg + F.

// 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/alignment/cigar_conversion/alignment_from_cigar.hpp>
#include <seqan3/alphabet/cigar/cigar.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
using namespace seqan3::literals;
int main()
{
// CIGAR string = 2M1D2M
std::vector<seqan3::cigar> cigar_vector{{2, 'M'_cigar_operation},
{1, 'D'_cigar_operation},
{2, 'M'_cigar_operation}};
uint32_t reference_start_position{0}; // The read is aligned at the start of the reference.
seqan3::dna5_vector reference = "ACTGATCGAGAGGATCTAGAGGAGATCGTAGGAC"_dna5;
seqan3::dna5_vector query = "ACGA"_dna5;
auto alignment = alignment_from_cigar(cigar_vector, reference, reference_start_position, query);
seqan3::debug_stream << alignment << '\n'; // prints (ACTGA,AC-GA)
}
alignment_from_cigar.hpp
Provides the function seqan3::alignment_from_cigar.
cigar.hpp
Provides the seqan3::cigar alphabet.
seqan3::alignment_from_cigar
auto alignment_from_cigar(std::vector< cigar > const &cigar_vector, reference_type const &reference, uint32_t const zero_based_reference_start_position, sequence_type const &query)
Construct an alignment from a CIGAR string and the corresponding sequences.
Definition alignment_from_cigar.hpp:81
seqan3::field::alignment
@ alignment
The (pairwise) alignment stored in an object that models seqan3::detail::pairwise_alignment.
Definition record.hpp:78
// 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/alignment/cigar_conversion/alignment_from_cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/all.hpp>
using namespace seqan3::literals;
auto sam_file_raw = R"(@HD VN:1.6
@SQ SN:ref LN:34
read1 41 ref 1 61 1S1M1D1M1I ref 10 300 ACGT !##$ AS:i:2 NM:i:7
read2 42 ref 2 62 1H7M1D1M1S2H ref 10 300 AGGCTGNAG !##$&'()* xy:B:S,3,4,5
read3 43 ref 3 63 1S1M1P1M1I1M1I1D1M1S ref 10 300 GGAGTATA !!*+,-./
)";
int main()
{
// The reference sequence might be read from a different file.
seqan3::dna5_vector reference = "ACTGATCGAGAGGATCTAGAGGAGATCGTAGGAC"_dna5;
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
// You will probably read it from a file, e.g., like this:
// seqan3::sam_file_input fin{"test.sam"};
for (auto && rec : fin)
{
auto alignment =
alignment_from_cigar(rec.cigar_sequence(), reference, rec.reference_position().value(), rec.sequence());
seqan3::debug_stream << alignment << '\n';
}
// prints:
// (ACT-,C-GT)
// (CTGATCGAG,AGGCTGN-A)
// (T-G-A-TC,G-AGTA-T)
}
seqan3::format_sam
The SAM format (tag).
Definition format_sam.hpp:105
seqan3::sam_file_input
A class for reading SAM files, both SAM and its binary representation BAM are supported.
Definition sam_file/input.hpp:236
all.hpp
Meta-header for the IO / SAM File submodule .
// 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/alignment/aligned_sequence/aligned_sequence_concept.hpp>
#include <seqan3/alignment/cigar_conversion/cigar_from_alignment.hpp>
#include <seqan3/alignment/decorator/gap_decorator.hpp>
#include <seqan3/alphabet/gap/gapped.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/slice.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector reference = "ATGGCGTAGAGCTTCCCCCCCCCCCCCCCCC"_dna5;
seqan3::dna5_vector read = "ATGCCCCGTTGCTT"_dna5; // length 14
// Align the full query against the first 14 bases of the reference.
seqan3::gap_decorator aligned_reference{reference | seqan3::views::slice(0, 14)};
seqan3::gap_decorator aligned_read{read};
// Insert gaps to represent the alignment:
seqan3::insert_gap(aligned_read, aligned_read.begin() + 11, 2);
seqan3::insert_gap(aligned_reference, aligned_reference.begin() + 4, 2);
seqan3::debug_stream << aligned_reference << '\n' << aligned_read << '\n';
// prints:
// ATGG--CGTAGAGCTT
// ATGCCCCGTTG--CTT
auto cigar_sequence = seqan3::cigar_from_alignment(std::tie(aligned_reference, aligned_read));
seqan3::debug_stream << cigar_sequence << '\n'; // prints [4M,2I,5M,2D,3M]
}
aligned_sequence_concept.hpp
Includes the aligned_sequence and the related insert_gap and erase_gap functions to enable stl contai...
cigar_from_alignment.hpp
Provides the function seqan3::cigar_from_alignment and a helper struct seqan3::cigar_clipped_bases.
seqan3::gap_decorator
A gap decorator allows the annotation of sequences with gap symbols while leaving the underlying sequ...
Definition gap_decorator.hpp:78
seqan3::gap_decorator::begin
const_iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition gap_decorator.hpp:349
gap_decorator.hpp
Provides seqan3::gap_decorator.
gapped.hpp
Provides seqan3::gapped.
seqan3::insert_gap
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)
An implementation of seqan3::writable_aligned_sequence::insert_gap for ranges with the corresponding ...
Definition aligned_sequence_concept.hpp:409
seqan3::cigar_from_alignment
auto cigar_from_alignment(alignment_type const &alignment, cigar_clipped_bases const &clipped_bases={}, bool const extended_cigar=false)
Creates a CIGAR string (SAM format) given a seqan3::detail::pairwise_alignment represented by two seq...
Definition cigar_from_alignment.hpp:111
seqan3::views::slice
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:137
slice.hpp
Provides seqan3::views::slice.
std::tie
T tie(T... args)
// 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/alignment/aligned_sequence/aligned_sequence_concept.hpp>
#include <seqan3/alignment/cigar_conversion/cigar_from_alignment.hpp>
#include <seqan3/alignment/decorator/gap_decorator.hpp>
#include <seqan3/alphabet/gap/gapped.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/slice.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector reference = "ATGGCGTAGAGCTTCCCCCCCCCCCCCCCCC"_dna5;
seqan3::dna5_vector read = "ATGCCCCGTTGCTT"_dna5; // length 14
// Let's say, we want to ignore the last 2 bases of the query because the quality is low.
// We thus only align the first 12 bases, the last two will be soft-clipped bases in the CIGAR string.
seqan3::gap_decorator aligned_reference{reference | seqan3::views::slice(0, 12)};
seqan3::gap_decorator aligned_query{read | seqan3::views::slice(0, 12)};
// insert gaps
seqan3::insert_gap(aligned_reference, aligned_reference.begin() + 4, 2);
seqan3::insert_gap(aligned_query, aligned_query.begin() + 11, 2);
auto cigar_sequence =
seqan3::cigar_from_alignment(std::tie(aligned_reference, aligned_query),
{.hard_front = 1, .hard_back = 0, .soft_front = 0, .soft_back = 2});
seqan3::debug_stream << cigar_sequence << '\n'; // prints [1H,4M,2I,5M,2D,1M,2S]
}
// 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/alignment/configuration/align_config_band.hpp>
int main()
{
// A symmetric band around the main diagonal.
seqan3::align_cfg::band_fixed_size band_cfg{seqan3::align_cfg::lower_diagonal{-4},
seqan3::align_cfg::upper_diagonal{4}};
// A band starting with the main diagonal shifted by 3 cells to the right.
seqan3::align_cfg::band_fixed_size band_cfg_hi{seqan3::align_cfg::lower_diagonal{3},
seqan3::align_cfg::upper_diagonal{7}};
// A band starting with the main diagonal shifted by 3 cells down.
seqan3::align_cfg::band_fixed_size band_cfg_lo{seqan3::align_cfg::lower_diagonal{-7},
seqan3::align_cfg::upper_diagonal{-3}};
// An invalid band configuration.
// Using this band as a configuration in seqan3::align_pairwise would cause the algorithm to throw an exception.
seqan3::align_cfg::band_fixed_size band_cfg_invalid{seqan3::align_cfg::lower_diagonal{7},
seqan3::align_cfg::upper_diagonal{3}};
}
align_config_band.hpp
Provides seqan3::detail::align_config_band.
seqan3::align_cfg::band_fixed_size
Configuration element for setting a fixed size band.
Definition align_config_band.hpp:60
seqan3::align_cfg::lower_diagonal
A strong type representing the lower diagonal of the seqan3::align_cfg::band_fixed_size.
Definition align_config_band.hpp:28
seqan3::align_cfg::upper_diagonal
A strong type representing the upper diagonal of the seqan3::align_cfg::band_fixed_size.
Definition align_config_band.hpp:39
// 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/alignment/configuration/align_config_edit.hpp>
#include <seqan3/alignment/configuration/align_config_method.hpp>
#include <seqan3/alignment/configuration/align_config_min_score.hpp>
int main()
{
// Computes semi global edit distance using fast-bit vector algorithm.
auto cfg_fast = seqan3::align_cfg::method_global{seqan3::align_cfg::free_end_gaps_sequence1_leading{true},
seqan3::align_cfg::free_end_gaps_sequence2_leading{false},
seqan3::align_cfg::free_end_gaps_sequence1_trailing{true},
seqan3::align_cfg::free_end_gaps_sequence2_trailing{false}}
| seqan3::align_cfg::edit_scheme;
// Computes semi global edit distance using slower standard pairwise algorithm.
auto cfg_slow = seqan3::align_cfg::method_global{seqan3::align_cfg::free_end_gaps_sequence1_leading{false},
seqan3::align_cfg::free_end_gaps_sequence2_leading{true},
seqan3::align_cfg::free_end_gaps_sequence1_trailing{false},
seqan3::align_cfg::free_end_gaps_sequence2_trailing{true}}
| seqan3::align_cfg::edit_scheme;
// Computes global distance allowing a minimal score of 3 (Default: edit distance).
auto cfg_errors =
seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme | seqan3::align_cfg::min_score{-3};
}
align_config_edit.hpp
Provides seqan3::align_cfg::edit_scheme.
align_config_method.hpp
Provides global and local alignment configurations.
align_config_min_score.hpp
Provides seqan3::align_cfg::min_score configuration.
seqan3::align_cfg::free_end_gaps_sequence1_leading
A strong type representing free_end_gaps_sequence1_leading of the seqan3::align_cfg::method_global.
Definition align_config_method.hpp:65
seqan3::align_cfg::free_end_gaps_sequence1_trailing
A strong type representing free_end_gaps_sequence1_trailing of the seqan3::align_cfg::method_global.
Definition align_config_method.hpp:85
seqan3::align_cfg::free_end_gaps_sequence2_leading
A strong type representing free_end_gaps_sequence2_leading of the seqan3::align_cfg::method_global.
Definition align_config_method.hpp:75
seqan3::align_cfg::free_end_gaps_sequence2_trailing
A strong type representing free_end_gaps_sequence2_trailing of the seqan3::align_cfg::method_global.
Definition align_config_method.hpp:95
// 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 <iostream>
#include <seqan3/alignment/configuration/align_config_gap_cost_affine.hpp>
int main()
{
// Configuration with linear gap costs.
seqan3::align_cfg::gap_cost_affine linear_cfg{seqan3::align_cfg::open_score{0},
seqan3::align_cfg::extension_score{-1}};
// Configuration with affine gap costs. Score for opening a gap during the alignment algorithm will be -11.
seqan3::align_cfg::gap_cost_affine affine_cfg{seqan3::align_cfg::open_score{-1},
seqan3::align_cfg::extension_score{-10}};
// Accessing the members of the gap scheme
int open = affine_cfg.open_score;
int extension = affine_cfg.extension_score;
std::cout << open << '\n'; // -1
std::cout << extension << '\n'; // -10
}
align_config_gap_cost_affine.hpp
Provides seqan3::align_config::gap_cost_affine.
seqan3::align_cfg::gap_cost_affine
A configuration element for the affine gap cost scheme.
Definition align_config_gap_cost_affine.hpp:72
seqan3::align_cfg::gap_cost_affine::open_score
int32_t open_score
The score per consecutive sequence of gaps. Defaults to 0.
Definition align_config_gap_cost_affine.hpp:75
seqan3::align_cfg::gap_cost_affine::extension_score
int32_t extension_score
The cost per gap character. Defaults to -1.
Definition align_config_gap_cost_affine.hpp:77
iostream
seqan3::align_cfg::extension_score
A strong type of underlying type int32_t that represents the score (usually negative) of any characte...
Definition align_config_gap_cost_affine.hpp:48
seqan3::align_cfg::open_score
A strong type of underlying type int32_t that represents a score (usually negative) that is incurred ...
Definition align_config_gap_cost_affine.hpp:31
// 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/alignment/configuration/align_config_method.hpp>
#include <seqan3/alignment/configuration/align_config_scoring_scheme.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alignment/scoring/nucleotide_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
using namespace seqan3::literals;
int main()
{
// configure a global alignment for DNA sequences
auto min_cfg = seqan3::align_cfg::method_global{}
| seqan3::align_cfg::scoring_scheme{seqan3::nucleotide_scoring_scheme{seqan3::match_score{4},
seqan3::mismatch_score{-5}}}
| seqan3::align_cfg::gap_cost_affine{seqan3::align_cfg::open_score{-10},
seqan3::align_cfg::extension_score{-1}};
auto seq1 = "TCGT"_dna4;
auto seq2 = "ACGA"_dna4;
for (auto res : seqan3::align_pairwise(std::tie(seq1, seq2), min_cfg))
seqan3::debug_stream << res.score() << '\n'; // print out the alignment score
}
align_config_scoring_scheme.hpp
Provides seqan3::align_cfg::scoring_scheme.
seqan3::align_cfg::scoring_scheme
Sets the scoring scheme for the alignment algorithm.
Definition align_config_scoring_scheme.hpp:42
seqan3::nucleotide_scoring_scheme
A data structure for managing and computing the score of two nucleotides.
Definition nucleotide_scoring_scheme.hpp:35
seqan3::match_score
A strong type of underlying type score_type that represents the score of two matching characters.
Definition scoring_scheme_base.hpp:38
seqan3::mismatch_score
A strong type of underlying type score_type that represents the score two different characters.
Definition scoring_scheme_base.hpp:63
// 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/alignment/configuration/align_config_method.hpp>
#include <seqan3/alignment/configuration/align_config_scoring_scheme.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alignment/scoring/nucleotide_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
using namespace seqan3::literals;
int main()
{
// configure a local alignment for DNA sequences
auto min_cfg = seqan3::align_cfg::method_local{}
| seqan3::align_cfg::scoring_scheme{
seqan3::nucleotide_scoring_scheme{seqan3::match_score{4}, seqan3::mismatch_score{-5}}};
auto seq1 = "TCGT"_dna4;
auto seq2 = "ACGA"_dna4;
for (auto res : seqan3::align_pairwise(std::tie(seq1, seq2), min_cfg))
seqan3::debug_stream << res.score() << '\n'; // print out the alignment score
}
seqan3::align_cfg::method_local
Sets the local alignment method.
Definition align_config_method.hpp:42
// 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/alignment/configuration/align_config_min_score.hpp>
#include <seqan3/core/configuration/configuration.hpp>
int main()
{
// Allow a minimal score of -5, i.e. at most 5 edit operations.
seqan3::configuration config = seqan3::align_cfg::min_score{-5};
auto min_score = std::get<seqan3::align_cfg::min_score>(config);
min_score.score = -5;
}
seqan3::configuration
Collection of elements to configure an algorithm.
Definition configuration.hpp:42
configuration.hpp
Provides seqan3::configuration and utility functions.
// 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/alignment/configuration/align_config_on_result.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
seqan3::align_cfg::on_result cfg{[](auto && result)
{
seqan3::debug_stream << result << '\n';
}};
}
align_config_on_result.hpp
Provides seqan3::align_cfg::on_result.
seqan3::align_cfg::on_result
Configuration element to provide a user defined callback function for the alignment.
Definition align_config_on_result.hpp:51
// 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/alignment/configuration/align_config_output.hpp>
int main()
{
// Compute only the alignment.
seqan3::configuration cfg = seqan3::align_cfg::output_alignment{};
}
align_config_output.hpp
Provides configuration for alignment output.
seqan3::align_cfg::output_alignment
Configures the alignment result to output the alignment.
Definition align_config_output.hpp:168
// 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/alignment/configuration/align_config_output.hpp>
int main()
{
// Compute only the begin position of the aligned sequences.
seqan3::configuration cfg = seqan3::align_cfg::output_begin_position{};
}
seqan3::align_cfg::output_begin_position
Configures the alignment result to output the begin positions.
Definition align_config_output.hpp:128
// 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/alignment/configuration/align_config_output.hpp>
int main()
{
// Compute only the end position of the aligned sequences.
seqan3::configuration cfg = seqan3::align_cfg::output_end_position{};
}
seqan3::align_cfg::output_end_position
Configures the alignment result to output the end position.
Definition align_config_output.hpp:84
// 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 <vector>
#include <seqan3/alignment/configuration/align_config_edit.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
// Basic alignment algorithm configuration.
auto config = seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme;
std::pair p{"ACGTAGC"_dna4, "AGTACGACG"_dna4};
// Compute only the score:
for (auto res : seqan3::align_pairwise(p, config | seqan3::align_cfg::output_score{}))
seqan3::debug_stream << res << "\n"; // prints: {score: -4}
// Compute only the alignment:
for (auto res : seqan3::align_pairwise(p, config | seqan3::align_cfg::output_alignment{}))
seqan3::debug_stream << res << "\n"; // prints: {alignment: (ACGTA-G-C-,A-GTACGACG)}
// Compute the score and the alignment:
for (auto res :
seqan3::align_pairwise(p, config | seqan3::align_cfg::output_score{} | seqan3::align_cfg::output_alignment{}))
seqan3::debug_stream << res << "\n"; // prints: {score: -4, alignment: (ACGTA-G-C-,A-GTACGACG)}
// By default compute everything:
for (auto res : seqan3::align_pairwise(p, config))
seqan3::debug_stream
<< res << "\n"; // prints {id: 0, score: -4, begin: (0,0), end: (7,9) alignment: (ACGTA-G-C-,A-GTACGACG)}
}
std::pair
// 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/alignment/configuration/align_config_output.hpp>
int main()
{
// Compute only the score.
seqan3::configuration cfg = seqan3::align_cfg::output_score{};
}
// 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/alignment/configuration/align_config_output.hpp>
int main()
{
// Output only the id of the first sequence.
seqan3::configuration cfg = seqan3::align_cfg::output_sequence1_id{};
}
seqan3::align_cfg::output_sequence1_id
Configures the alignment result to output the id of the first sequence.
Definition align_config_output.hpp:208
// 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/alignment/configuration/align_config_output.hpp>
int main()
{
// Output only the id of the second sequence.
seqan3::configuration cfg = seqan3::align_cfg::output_sequence2_id{};
}
seqan3::align_cfg::output_sequence2_id
Configures the alignment result to output the id of the second sequence.
Definition align_config_output.hpp:247
// 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 <thread>
#include <seqan3/alignment/configuration/align_config_parallel.hpp>
int main()
{
// Enables parallel computation with two threads.
seqan3::align_cfg::parallel cfg_2{2};
// Enables parallel computation with the number of concurrent threads supported by the current architecture.
seqan3::align_cfg::parallel cfg_n{std::thread::hardware_concurrency()};
;
}
align_config_parallel.hpp
Provides seqan3::align_cfg::parallel configuration.
seqan3::align_cfg::parallel
seqan3::detail::parallel_mode< std::integral_constant< seqan3::detail::align_config_id, seqan3::detail::align_config_id::parallel > > parallel
Enables the parallel execution of the alignment algorithm if possible for the given configuration.
Definition align_config_parallel.hpp:34
std::thread::hardware_concurrency
T hardware_concurrency(T... args)
thread
// 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/alignment/configuration/align_config_score_type.hpp>
#include <seqan3/core/configuration/configuration.hpp>
int main()
{
// Compute only the score.
seqan3::configuration cfg1 =
seqan3::align_cfg::score_type<int16_t>{}; // Now the alignment computes 16 bit integers.
seqan3::configuration cfg2 = seqan3::align_cfg::score_type<float>{}; // Now the alignment computes float scores.
}
align_config_score_type.hpp
Provides alignment configuration seqan3::align_cfg::score_type.
seqan3::align_cfg::score_type
A configuration element to set the score type used in the alignment algorithm.
Definition align_config_score_type.hpp:33
// 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/alignment/configuration/align_config_vectorised.hpp>
int main()
{
// Enable SIMD vectorised alignment computation.
auto cfg = seqan3::align_cfg::vectorised{};
}
align_config_vectorised.hpp
Provides seqan3::align_cfg::vectorised configuration.
seqan3::align_cfg::vectorised
Enables the vectorised alignment computation if possible for the current configuration.
Definition align_config_vectorised.hpp:39
// 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/alignment/configuration/align_config_method.hpp>
#include <seqan3/alignment/configuration/align_config_scoring_scheme.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alignment/scoring/nucleotide_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
using namespace seqan3::literals;
int main()
{
auto min_cfg = seqan3::align_cfg::method_global{}
| seqan3::align_cfg::scoring_scheme{
seqan3::nucleotide_scoring_scheme{seqan3::match_score{4}, seqan3::mismatch_score{-5}}};
auto seq1 = "ACGT"_dna4;
auto seq2 = "ACCT"_dna4;
for (auto res : align_pairwise(std::tie(seq1, seq2), min_cfg))
seqan3::debug_stream << res.score() << '\n';
}
// 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 <span>
#include <vector>
#include <seqan3/alignment/matrix/detail/alignment_matrix_column_major_range_base.hpp>
#include <seqan3/core/debug_stream.hpp>
class my_matrix : public seqan3::detail::alignment_matrix_column_major_range_base<my_matrix>
{
public:
// Alias the base class
using base_t = seqan3::detail::alignment_matrix_column_major_range_base<my_matrix>;
friend base_t;
// Inherit the alignment column type defined in the base class. This type is returned in initialise_column.
using typename base_t::alignment_column_type;
// The following types are required by the base type since they cannot be inferred within the base.
using column_data_view_type = std::span<int>; //This type is the underlying view over the actual memory location.
using value_type = int; // The actual value type.
using reference = int &; // The actual reference type.
my_matrix() = default;
my_matrix(my_matrix const &) = default;
my_matrix(my_matrix &&) = default;
my_matrix & operator=(my_matrix const &) = default;
my_matrix & operator=(my_matrix &&) = default;
~my_matrix() = default;
my_matrix(size_t const num_rows, size_t const num_cols) : num_rows{num_rows}, num_cols{num_cols}
{
data.resize(num_rows * num_cols);
}
protected:
std::vector<int> data{};
size_t num_rows{};
size_t num_cols{};
//Required for the base class. Initialises the current column given the column index.
alignment_column_type initialise_column(size_t const column_index) noexcept
{
return alignment_column_type{*this,
column_data_view_type{std::addressof(data[num_rows * column_index]), num_rows}};
}
//Required for the base class. Initialises the proxy for the current iterator over the current column.
template <std::random_access_iterator iter_t>
constexpr reference make_proxy(iter_t iter) noexcept
{
return *iter;
}
};
int main()
{
my_matrix matrix{3, 5};
// Fill the matrix with
int val = 0;
for (auto col : matrix) // Iterate over the columns
for (auto & cell : col) // Iterate over the cells in one column.
cell = val++;
// Print the matrix column by column
for (auto col : matrix)
seqan3::debug_stream << col << '\n';
}
std::addressof
T addressof(T... args)
alignment_matrix_column_major_range_base.hpp
Provides seqan3::detail::alignment_matrix_column_major_range_base.
// 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 <iostream>
#include <seqan3/alignment/matrix/detail/debug_matrix.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using seqan3::detail::debug_matrix;
using namespace seqan3::literals;
std::vector<seqan3::dna4> database = "AACCGGTT"_dna4;
std::vector<seqan3::dna4> query = "ACGT"_dna4;
seqan3::detail::row_wise_matrix<int> score_matrix{
seqan3::detail::number_rows{5u},
seqan3::detail::number_cols{9u},
std::vector{-0, -1, -2, -3, -4, -5, -6, -7, -8, -1, -0, -1, -2, -3, -4, -5, -6, -7, -2, -1, -1, -1, -2,
-3, -4, -5, -6, -3, -2, -2, -2, -2, -2, -3, -4, -5, -4, -3, -3, -3, -3, -3, -3, -3, -4}};
seqan3::debug_stream << "database:\t" << database << '\n';
seqan3::debug_stream << "query:\t\t" << query << '\n';
seqan3::debug_stream << '\n';
seqan3::debug_stream << "score_matrix: " << score_matrix.cols() << " columns and " << score_matrix.rows()
<< " rows\n";
// Prints out the matrix in a convenient way
seqan3::debug_stream << score_matrix << '\n'; // without sequences
seqan3::debug_stream << debug_matrix{score_matrix, database, query} << '\n'; // with sequences
seqan3::debug_stream << seqan3::fmtflags2::utf8 << debug_matrix{score_matrix, database, query}; // as utf8
return 0;
}
debug_matrix.hpp
Provides the declaration of seqan3::detail::debug_matrix.
seqan3::fmtflags2::utf8
@ utf8
Enables use of non-ASCII UTF8 characters in formatted output.
Definition debug_stream_type.hpp:34
// 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 <iostream>
#include <seqan3/alignment/matrix/detail/debug_matrix.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using seqan3::detail::debug_matrix;
using namespace seqan3::literals;
using seqan3::operator|;
std::vector<seqan3::dna4> database = "AACCGGTT"_dna4;
std::vector<seqan3::dna4> query = "ACGT"_dna4;
auto N = seqan3::detail::trace_directions::none;
auto D = seqan3::detail::trace_directions::diagonal;
auto U = seqan3::detail::trace_directions::up;
auto L = seqan3::detail::trace_directions::left;
seqan3::detail::row_wise_matrix<seqan3::detail::trace_directions> trace_matrix{
seqan3::detail::number_rows{5u},
seqan3::detail::number_cols{9u},
std::vector{N, L, L, L, L, L, L, L, L, U, D, D | L, L, L, L,
L, L, L, U, U, D, D, D | L, L, L, L, L, U, U, D | U,
D | U, D, D, D | L, L, L, U, U, D | U, D | U, D | U, D | U, D, D, D | L}};
seqan3::debug_stream << "database:\t" << database << '\n';
seqan3::debug_stream << "query:\t\t" << query << '\n';
seqan3::debug_stream << '\n';
seqan3::debug_stream << "trace_matrix: " << trace_matrix.cols() << " columns and " << trace_matrix.rows()
<< " rows\n";
// Prints out the matrix in a convenient way
seqan3::debug_stream << trace_matrix << '\n'; // without sequences
seqan3::debug_stream << debug_matrix{trace_matrix, database, query} << '\n'; // with sequences
seqan3::debug_stream << seqan3::fmtflags2::utf8 << debug_matrix{trace_matrix, database, query}; // as utf8
return 0;
}
to_char.hpp
Provides seqan3::views::to_char.
// 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 <vector>
#include <seqan3/alignment/configuration/align_config_edit.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
// Configure the alignment kernel.
auto config = seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme;
{
std::pair p{"ACGTAGC"_dna4, "AGTACGACG"_dna4};
auto result = seqan3::align_pairwise(p, config);
}
{
std::vector vec{"ACCA"_dna4, "ATTA"_dna4};
auto result = seqan3::align_pairwise(std::tie(vec[0], vec[1]), config);
}
std::vector vec{std::pair{"AGTGCTACG"_dna4, "ACGTGCGACTAG"_dna4},
std::pair{"AGTAGACTACG"_dna4, "ACGTACGACACG"_dna4},
std::pair{"AGTTACGAC"_dna4, "AGTAGCGATCG"_dna4}};
// Compute the alignment of a single pair.
auto edit_config = seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme;
for (auto const & res : seqan3::align_pairwise(std::tie(vec[0].first, vec[0].second), edit_config))
seqan3::debug_stream << "The score: " << res.score() << "\n";
// Compute the alignment over a range of pairs.
for (auto const & res : seqan3::align_pairwise(vec, edit_config))
seqan3::debug_stream << "The score: " << res.score() << "\n";
}
// 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 <ranges>
#include <vector>
#include <seqan3/alignment/configuration/all.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alignment/scoring/hamming_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
std::vector data1{"AGTGCTACG"_dna4, "AGTAGACTACG"_dna4, "AGTTACGAC"_dna4};
std::vector data2{"ACGTGCGACTAG"_dna4, "ACGTACGACACG"_dna4, "AGTAGCGATCG"_dna4};
// Configure the alignment kernel.
auto config =
seqan3::align_cfg::method_global{} | seqan3::align_cfg::scoring_scheme{seqan3::hamming_scoring_scheme{}};
// Compute the alignment over a range of pairs.
for (auto const & res : seqan3::align_pairwise(seqan3::views::zip(data1, data2), config))
seqan3::debug_stream << "The score: " << res.score() << "\n";
}
all.hpp
Meta-header for the Alignment / Configuration submodule .
seqan3::hamming_scoring_scheme
A scoring scheme that assigns a score of 0 to matching letters and -1 to mismatching letters.
Definition hamming_scoring_scheme.hpp:33
seqan3::views::zip
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
hamming_scoring_scheme.hpp
Provides seqan3::hamming_scoring_scheme.
// 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/alignment/pairwise/alignment_configurator.hpp>
int main()
{
using sequences_t = std::vector<std::pair<std::string, std::string>>;
using config_t = decltype(seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme
| seqan3::align_cfg::output_score{});
using first_seq_t = std::tuple_element_t<0, std::ranges::range_value_t<sequences_t>>;
using second_seq_t = std::tuple_element_t<1, std::ranges::range_value_t<sequences_t>>;
// Select the result type based on the sequences and the configuration.
using result_t =
seqan3::alignment_result<typename seqan3::detail::align_result_selector<std::remove_reference_t<first_seq_t>,
std::remove_reference_t<second_seq_t>,
config_t>::type>;
// Define the function wrapper type.
using function_wrapper_t = std::function<result_t(first_seq_t &, second_seq_t &)>;
static_assert(seqan3::detail::is_type_specialisation_of_v<function_wrapper_t, std::function>);
}
alignment_configurator.hpp
Provides seqan3::detail::alignment_selector.
seqan3::alignment_result
Stores the alignment results and gives access to score, alignment and the front and end positions.
Definition alignment_result.hpp:147
std::function
std::remove_reference_t
// 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 <mutex>
#include <vector>
#include <seqan3/alignment/configuration/all.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
// Generate some sequences.
using namespace seqan3::literals;
using sequence_pair_t = std::pair<seqan3::dna4_vector, seqan3::dna4_vector>;
std::vector<sequence_pair_t> sequences{100, {"AGTGCTACG"_dna4, "ACGTGCGACTAG"_dna4}};
// Use edit distance with 4 threads.
auto const alignment_config =
seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme | seqan3::align_cfg::parallel{4};
// Compute the alignments in parallel and output them in order based on the input.
for (auto && result : seqan3::align_pairwise(sequences, alignment_config))
seqan3::debug_stream << result << '\n';
seqan3::debug_stream << '\n';
// prints:
// [id: 0 score: -4]
// [id: 1 score: -4]
// [id: 2 score: -4]
// [id: 3 score: -4]
// [id: 4 score: -4]
// [id: 5 score: -4]
// ...
// [id: 98 score: -4]
// [id: 99 score: -4]
// Compute the alignments in parallel and output them unordered using the callback (order is not deterministic).
std::mutex write_to_debug_stream{}; // Need mutex to synchronise the output.
auto const alignment_config_with_callback =
alignment_config
| seqan3::align_cfg::on_result{[&](auto && result)
{
std::lock_guard sync{write_to_debug_stream}; // critical section
seqan3::debug_stream << result << '\n';
}};
seqan3::align_pairwise(sequences, alignment_config_with_callback); // seqan3::align_pairwise is now declared void.
// might print:
// [id: 0 score: -4]
// [id: 1 score: -4]
// [id: 2 score: -4]
// [id: 6 score: -4]
// [id: 7 score: -4]
// [id: 3 score: -4]
// ...
// [id: 99 score: -4]
// [id: 92 score: -4]
}
std::lock_guard
mutex
// 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/alignment/scoring/aminoacid_scoring_scheme.hpp>
#include <seqan3/alphabet/aminoacid/aa27.hpp>
#include <seqan3/alphabet/aminoacid/all.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/zip.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aminoacid_scoring_scheme scheme{seqan3::aminoacid_similarity_matrix::blosum62};
// How to score two letters:
seqan3::debug_stream << "blosum62 score for T and S: " << (int)scheme.score('T'_aa27, 'S'_aa27) << "\n"; // == 1
scheme.set_similarity_matrix(seqan3::aminoacid_similarity_matrix::blosum80);
// You can also score aa20 against aa27:
seqan3::debug_stream << "blosum80 score for 'T'_aa27 and 'S'_aa20: " << (int)scheme.score('T'_aa27, 'S'_aa20)
<< "\n"; // == 2
scheme.set_hamming_distance();
seqan3::debug_stream << "Hamming distance between T and S: " << (int)scheme.score('T'_aa27, 'S'_aa20)
<< "\n"; // == -1
seqan3::debug_stream << "Hamming distance between T and T: " << (int)scheme.score('T'_aa27, 'T'_aa20)
<< "\n"; // == 0
seqan3::aminoacid_scoring_scheme scheme2{seqan3::aminoacid_similarity_matrix::blosum80};
// You can "edit" a given matrix directly:
seqan3::debug_stream << "blosum80 score between T and S: " << (int)scheme2.score('T'_aa27, 'S'_aa27)
<< "\n"; // == 2
auto & cell = scheme2.score('T'_aa27, 'S'_aa27);
cell = 3;
seqan3::debug_stream << "New score after editing entry: " << (int)scheme2.score('T'_aa27, 'S'_aa27) << "\n"; // == 3
std::vector<seqan3::aa27> one = "ALIGATOR"_aa27;
std::vector<seqan3::aa27> two = "ANIMATOR"_aa27;
seqan3::aminoacid_scoring_scheme scheme3{seqan3::aminoacid_similarity_matrix::blosum62};
// You can also score two sequences:
int score = 0;
for (auto pair : seqan3::views::zip(one, two))
score += scheme3.score(std::get<0>(pair), std::get<1>(pair));
seqan3::debug_stream << "Score: " << score << "\n"; // 4 + -3 + 4 + -3 + 4 + 5 + -1 + 5 = 15
}
aa27.hpp
Provides seqan3::aa27, container aliases and string literals.
all.hpp
Meta-header for the Alphabet / Aminoacid submodule .
aminoacid_scoring_scheme.hpp
Provides seqan3::aminoacid_scoring_scheme.
seqan3::aminoacid_scoring_scheme
A data structure for managing and computing the score of two amino acids.
Definition aminoacid_scoring_scheme.hpp:72
seqan3::aminoacid_scoring_scheme::set_similarity_matrix
constexpr void set_similarity_matrix(aminoacid_similarity_matrix const matrix_id)
Set the similarity matrix scheme (e.g. blosum62).
Definition aminoacid_scoring_scheme.hpp:118
seqan3::scoring_scheme_base::set_hamming_distance
constexpr void set_hamming_distance() noexcept
Set the hamming scheme, a variant of the simple scheme where match is scored 0 and mismatch -1.
Definition scoring_scheme_base.hpp:163
seqan3::scoring_scheme_base::score
constexpr score_t & score(alph1_t const alph1, alph2_t const alph2) noexcept
Score two letters (either two nucleotids or two amino acids).
Definition scoring_scheme_base.hpp:214
seqan3::aminoacid_similarity_matrix::blosum80
@ blosum80
The blosum80 matrix for closely related proteins.
Definition aminoacid_scoring_scheme.hpp:54
seqan3::aminoacid_similarity_matrix::blosum62
@ blosum62
The blosum62 matrix recommended for most use-cases.
Definition aminoacid_scoring_scheme.hpp:49
zip.hpp
Provides seqan3::views::zip.
// 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/alignment/scoring/nucleotide_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/zip.hpp>
int main()
{
using namespace seqan3::literals;
// You can score two letters:
seqan3::nucleotide_scoring_scheme scheme; // hamming is default
seqan3::debug_stream << "Score between DNA5 A and G: " << (int)scheme.score('A'_dna5, 'G'_dna5) << "\n"; // == -1
seqan3::debug_stream << "Score between DNA5 A and A: " << (int)scheme.score('A'_dna5, 'A'_dna5) << "\n"; // == 0
// You can also score differenct nucleotides:
scheme.set_simple_scheme(seqan3::match_score{3}, seqan3::mismatch_score{-2});
seqan3::debug_stream << "Score between DNA5 A and RNA15 G: " << (int)scheme.score('A'_dna5, 'G'_rna15)
<< "\n"; // == -2
seqan3::debug_stream << "Score between DNA5 A and RNA15 A: " << (int)scheme.score('A'_dna5, 'A'_rna15)
<< "\n"; // == 3
// You can "edit" a given matrix directly:
seqan3::nucleotide_scoring_scheme scheme2; // hamming distance is default
seqan3::debug_stream << "Score between DNA A and G before edit: " << (int)scheme2.score('A'_dna15, 'G'_dna15)
<< "\n"; // == -1
scheme2.score('A'_dna15, 'G'_dna15) = 3;
seqan3::debug_stream << "Score after editing: " << (int)scheme2.score('A'_dna15, 'G'_dna15) << "\n"; // == 3
// You can score two sequences:
std::vector<seqan3::dna15> one = "AGAATA"_dna15;
std::vector<seqan3::dna15> two = "ATACTA"_dna15;
seqan3::nucleotide_scoring_scheme scheme3; // hamming distance is default
int score = 0;
for (auto pair : seqan3::views::zip(one, two))
score += scheme3.score(std::get<0>(pair), std::get<1>(pair));
seqan3::debug_stream << "Score: " << score << "\n"; // == 0 - 1 + 0 - 1 + 0 + 0 = -2
}
seqan3::scoring_scheme_base::set_simple_scheme
constexpr void set_simple_scheme(match_score< score_arg_t > const ms, mismatch_score< score_arg_t > const mms)
Set the simple scheme (everything is either match or mismatch).
Definition scoring_scheme_base.hpp:175
rna15.hpp
Provides seqan3::rna15, container aliases and string literals.
// 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>
int main()
{
// does not work:
// seqan3::dna4 my_letter{0}; // we want to set the default, an A
// seqan3::dna4 my_letter{'A'}; // we also want to set an A, but we are setting value 65
// std::cout << my_letter; // you expect 'A', but how would you access the number?
}
// 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>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter = 'A'_dna4; // identical to assign_char_to('A', letter);
seqan3::dna4_vector sequence = "ACGT"_dna4; // identical to calling assign_char for each element
}
// 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/core/debug_stream.hpp>
int main()
{
seqan3::dna4 my_letter;
seqan3::assign_rank_to(0, my_letter); // assign an A via rank interface
seqan3::assign_char_to('A', my_letter); // assign an A via char interface
std::cout << seqan3::to_char(my_letter) << '\n'; // prints 'A'
std::cout << (unsigned)seqan3::to_rank(my_letter) << '\n'; // prints 0
// we have to add the cast here, because uint8_t is also treated as a char type by default :(
// Using SeqAn's debug_stream:
seqan3::debug_stream << seqan3::to_char(my_letter) << '\n'; // prints 'A'
seqan3::debug_stream << my_letter << '\n'; // prints 'A' (calls to_char() automatically!)
seqan3::debug_stream << seqan3::to_rank(my_letter) << '\n'; // prints 0 (casts uint8_t to unsigned automatically!)
}
seqan3::assign_char_to
constexpr auto assign_char_to
Assign a character to an alphabet object.
Definition alphabet/concept.hpp:517
seqan3::to_char
constexpr auto to_char
Return the char representation of an alphabet object.
Definition alphabet/concept.hpp:381
seqan3::assign_rank_to
constexpr auto assign_rank_to
Assign a rank to an alphabet object.
Definition alphabet/concept.hpp:288
seqan3::to_rank
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition alphabet/concept.hpp:152
// 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/alphabet_base.hpp>
#include <seqan3/alphabet/concept.hpp>
#include <seqan3/utility/char_operations/transform.hpp> // seqan3::to_lower
class ab : public seqan3::alphabet_base<ab, 2>
{
private:
// make the base class a friend so it can access the tables:
friend alphabet_base<ab, 2>;
// This function is expected by seqan3::alphabet_base
static constexpr char_type rank_to_char(rank_type const rank)
{
// via a lookup table
return rank_to_char_table[rank];
// or via an arithmetic expression
return rank == 1 ? 'B' : 'A';
}
// This function is expected by seqan3::alphabet_base
static constexpr rank_type char_to_rank(char_type const chr)
{
// via a lookup table
using index_t = std::make_unsigned_t<char_type>;
return char_to_rank_table[static_cast<index_t>(chr)];
// or via an arithmetic expression
return seqan3::to_lower(chr) == 'b' ? 1 : 0;
}
private:
// === lookup-table implementation detail ===
// map 0 -> A and 1 -> B
static constexpr std::array<char_type, alphabet_size> rank_to_char_table{'A', 'B'};
// map every letter to rank zero, except Bs
static constexpr std::array<rank_type, 256> char_to_rank_table{
// initialise with an immediately evaluated lambda expression:
[]()
{
std::array<rank_type, 256> ret{}; // initialise all values with 0 / 'A'
// only 'b' and 'B' result in rank 1
ret['b'] = 1;
ret['B'] = 1;
return ret;
}()};
};
// The class ab satisfies the alphabet concept.
static_assert(seqan3::alphabet<ab>);
static_assert(seqan3::writable_alphabet<ab>);
concept.hpp
Core alphabet concept and free function/type trait wrappers.
alphabet_base.hpp
Provides seqan3::alphabet_base.
seqan3::alphabet_base
A CRTP-base that makes defining a custom alphabet easier.
Definition alphabet_base.hpp:54
seqan3::to_lower
constexpr char_type to_lower(char_type const c) noexcept
Converts 'A'-'Z' to 'a'-'z' respectively; other characters are returned as is.
Definition transform.hpp:74
transform.hpp
Provides utilities for modifying characters.
// 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 <iostream>
#include <seqan3/alphabet/adaptation/char.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
auto sigma_char = seqan3::alphabet_size<char>; // calls seqan3::custom::alphabet_size(char{})
static_assert(std::same_as<decltype(sigma_char), uint16_t>);
std::cout << sigma_char << '\n'; // 256
auto sigma_dna5 = seqan3::alphabet_size<seqan3::dna5>; // returns dna5::alphabet_size
static_assert(std::same_as<decltype(sigma_dna5), uint8_t>);
std::cout << static_cast<uint16_t>(sigma_dna5) << '\n'; // 5
}
char.hpp
Provides alphabet adaptations for standard char types.
// 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/aminoacid/aa10li.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa10li letter{'A'_aa10li};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('?'); // Unknown characters are implicitly converted to A.
seqan3::debug_stream << letter << '\n'; // prints "A"
}
aa10li.hpp
Provides seqan3::aa10li, container aliases and string literals.
seqan3::aa10li
The reduced Li amino acid alphabet.
Definition aa10li.hpp:80
seqan3::alphabet_base::assign_char
constexpr derived_type & assign_char(char_type const chr) noexcept
Assign from a character, implicitly converts invalid characters.
Definition alphabet_base.hpp:160
// 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/aminoacid/aa10li.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa10li letter1{'A'_aa10li};
auto letter2 = 'A'_aa10li;
}
// 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/aminoacid/aa10li.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa10li_vector sequence1{"ACGTTA"_aa10li};
seqan3::aa10li_vector sequence2 = "ACGTTA"_aa10li;
auto sequence3 = "ACGTTA"_aa10li;
}
// 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/aminoacid/aa10murphy.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa10murphy letter{'A'_aa10murphy};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('?'); // Unknown characters are implicitly converted to S.
seqan3::debug_stream << letter << '\n'; // prints "S"
}
aa10murphy.hpp
Provides seqan3::aa10murphy, container aliases and string literals.
seqan3::aa10murphy
The reduced Murphy amino acid alphabet.
Definition aa10murphy.hpp:79
// 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/aminoacid/aa10murphy.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa10murphy letter1{'A'_aa10murphy};
auto letter2 = 'A'_aa10murphy;
}
// 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/aminoacid/aa10murphy.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa10murphy_vector sequence1{"ACGTTA"_aa10murphy};
seqan3::aa10murphy_vector sequence2 = "ACGTTA"_aa10murphy;
auto sequence3 = "ACGTTA"_aa10murphy;
}
// 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/aminoacid/aa20.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa20 letter{'A'_aa20};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('?'); // Unknown characters are implicitly converted to S.
seqan3::debug_stream << letter << '\n'; // prints "S"
}
aa20.hpp
Provides seqan3::aa20, container aliases and string literals.
seqan3::aa20
The canonical amino acid alphabet.
Definition aa20.hpp:61
// 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/aminoacid/aa20.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa20 letter1{'A'_aa20};
auto letter2 = 'A'_aa20;
}
// 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/aminoacid/aa20.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa20_vector sequence1{"ACGTTA"_aa20};
seqan3::aa20_vector sequence2 = "ACGTTA"_aa20;
auto sequence3 = "ACGTTA"_aa20;
}
// 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/aminoacid/aa27.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa27 letter{'A'_aa27};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('?'); // Unknown characters are implicitly converted to X.
seqan3::debug_stream << letter << '\n'; // prints "X"
}
seqan3::aa27
The twenty-seven letter amino acid alphabet.
Definition aa27.hpp:43
// 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/aminoacid/aa27.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa27 letter1{'A'_aa27};
auto letter2 = 'A'_aa27;
}
// 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/aminoacid/aa27.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::aa27_vector sequence1{"ACGTTA"_aa27};
seqan3::aa27_vector sequence2 = "ACGTTA"_aa27;
auto sequence3 = "ACGTTA"_aa27;
}
// 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/aminoacid/concept.hpp>
namespace your_namespace
{
// your own aminoacid definition
struct your_aa : seqan3::aminoacid_empty_base
{
//...
};
} // namespace your_namespace
static_assert(seqan3::enable_aminoacid<your_namespace::your_aa> == true);
/***** OR *****/
namespace your_namespace2
{
// your own aminoacid definition
struct your_aa
{
//...
};
constexpr bool enable_aminoacid(your_aa) noexcept
{
return true;
}
} // namespace your_namespace2
static_assert(seqan3::enable_aminoacid<your_namespace2::your_aa> == true);
concept.hpp
Provides seqan3::aminoacid_alphabet.
seqan3::enable_aminoacid
constexpr bool enable_aminoacid
A trait that indicates whether a type shall model seqan3::aminoacid_alphabet.
Definition alphabet/aminoacid/concept.hpp:143
seqan3::aminoacid_empty_base
This is an empty base class that can be inherited by types that shall model seqan3::aminoacid_alphabe...
Definition alphabet/aminoacid/concept.hpp:32
// 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/adaptation/char.hpp>
#include <seqan3/alphabet/concept.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
char c = '!';
seqan3::assign_char_strictly_to('?', c); // calls seqan3::custom::assign_char_strictly_to('A', c)
seqan3::dna5 d{};
seqan3::assign_char_strictly_to('A', d); // calls .assign_char('A') member
// also works for temporaries:
seqan3::dna5 d2 = seqan3::assign_char_strictly_to('A', seqan3::dna5{});
}
seqan3::dna5
The five letter DNA alphabet of A,C,G,T and the unknown character N.
Definition dna5.hpp:48
seqan3::assign_char_strictly_to
constexpr auto assign_char_strictly_to
Assign a character to an alphabet object, throw if the character is not valid.
Definition alphabet/concept.hpp:721
// 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/adaptation/char.hpp>
#include <seqan3/alphabet/concept.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
char c = '!';
seqan3::assign_char_to('?', c); // calls seqan3::custom::assign_char_to('A', c)
seqan3::dna5 d{};
seqan3::assign_char_to('A', d); // calls .assign_char('A') member
// also works for temporaries:
seqan3::dna5 d2 = seqan3::assign_char_to('A', seqan3::dna5{});
// invalid/unknown characters are converted:
seqan3::dna5 d3 = seqan3::assign_char_to('!', seqan3::dna5{}); // == 'N'_dna5
}
// 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/adaptation/char.hpp>
#include <seqan3/alphabet/concept.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
char c = '!';
seqan3::assign_rank_to(66, c); // calls seqan3::custom::assign_rank_to(66, c); == 'B'
seqan3::dna5 d{};
seqan3::assign_rank_to(2, d); // calls .assign_rank(2) member; == 'G'_dna5
// also works for temporaries:
seqan3::dna5 d2 = seqan3::assign_rank_to(2, seqan3::dna5{});
// too-large ranks are undefined behaviour:
// seqan3::dna5 d3 = seqan3::assign_rank_to(50, seqan3::dna5{});
}
// 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 <iostream>
#include <seqan3/alphabet/adaptation/char.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
// calls seqan3::custom::char_is_valid_for<char>('A')
std::cout << std::boolalpha << seqan3::char_is_valid_for<char>('A') << '\n'; // always 'true'
// calls dna5::char_is_valid('A') member
std::cout << std::boolalpha << seqan3::char_is_valid_for<seqan3::dna5>('A') << '\n'; // true
// for some alphabets, characters that are not uniquely mappable are still valid:
std::cout << std::boolalpha << seqan3::char_is_valid_for<seqan3::dna5>('a') << '\n'; // true
}
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::cigar letter{12, 'M'_cigar_operation};
letter.assign_string("10D");
seqan3::debug_stream << letter << '\n'; // prints "10D"
letter.assign_string("20Z"); // Unknown strings are implicitly converted to 0P.
seqan3::debug_stream << letter << '\n'; // prints "0P"
}
seqan3::cigar
The seqan3::cigar semialphabet pairs a counter with a seqan3::cigar::operation letter.
Definition alphabet/cigar/cigar.hpp:57
seqan3::cigar::assign_string
cigar & assign_string(std::string_view const input) noexcept
Assign from a std::string_view.
Definition alphabet/cigar/cigar.hpp:167
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
std::string cigar_str{"4S134M"}; // input
seqan3::cigar letter1{};
seqan3::cigar letter2{};
// Assign from string
// convenient but creates an unnecessary string copy "4S"
letter1.assign_string(cigar_str.substr(0, 2));
letter2.assign_string(cigar_str.substr(2, 4));
seqan3::debug_stream << letter1 << '\n'; // prints 4S
seqan3::debug_stream << letter2 << '\n'; // prints 134M
// Assign from std::string_view (No extra string copies)
// Version 1
letter1.assign_string(std::string_view{cigar_str}.substr(0, 2));
letter2.assign_string(std::string_view{cigar_str}.substr(2, 4));
seqan3::debug_stream << letter1 << '\n'; // prints 4S
seqan3::debug_stream << letter2 << '\n'; // prints 134M
// No extra string copiesersion 2
letter1.assign_string(/*std::string_view*/ {cigar_str.data(), 2});
letter2.assign_string(/*std::string_view*/ {cigar_str.data() + 2, 4});
seqan3::debug_stream << letter1 << '\n'; // prints 4S
seqan3::debug_stream << letter2 << '\n'; // prints 134M
// Assign from char array
letter2.assign_string("40S");
seqan3::debug_stream << letter2 << '\n'; // prints 40S
// Assign from seqan3::small_string
letter2.assign_string(letter1.to_string());
seqan3::debug_stream << letter2 << '\n'; // prints 4S
}
std::string::data
T data(T... args)
std::string::substr
T substr(T... args)
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using seqan3::get;
using namespace seqan3::literals;
seqan3::cigar letter{10, 'M'_cigar_operation};
// Note that this is equivalent to get<uint32_t>(letter)
uint32_t size{get<0>(letter)};
// Note that this is equivalent to get<seqan3::cigar::operation>(letter)
seqan3::cigar::operation cigar_char{get<1>(letter)};
seqan3::debug_stream << "Size is " << size << '\n';
seqan3::debug_stream << "Cigar char is " << cigar_char << '\n'; // seqan3::debug_stream converts to char on the fly.
}
seqan3::cigar::operation
exposition_only::cigar_operation operation
The (extended) cigar operation alphabet of M,D,I,H,N,P,S,X,=.
Definition alphabet/cigar/cigar.hpp:93
seqan3::pack_traits::size
constexpr size_t size
The size of a type pack.
Definition type_pack/traits.hpp:143
seqan3::get
constexpr auto const & get(configuration< configs_t... > const &config) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition configuration.hpp:412
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using seqan3::get;
using namespace seqan3::literals;
seqan3::cigar letter{10, 'M'_cigar_operation};
// Note that this is equivalent to get<0>(letter)
uint32_t size{get<uint32_t>(letter)};
// Note that this is equivalent to get<1>(letter)
seqan3::cigar::operation cigar_char{get<seqan3::cigar::operation>(letter)};
seqan3::debug_stream << "Size is " << size << '\n';
seqan3::debug_stream << "Cigar char is " << cigar_char << '\n'; // seqan3::debug_stream converts to char on the fly.
}
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::cigar::operation letter{'M'_cigar_operation};
letter.assign_char('D');
seqan3::debug_stream << letter << '\n'; // prints "D"
letter.assign_char('Z'); // Unknown characters are implicitly converted to M.
seqan3::debug_stream << letter << '\n'; // prints "M"
}
// 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/cigar/cigar.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::cigar::operation letter1{'M'_cigar_operation};
auto letter2 = 'M'_cigar_operation;
}
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::cigar letter{10, 'I'_cigar_operation};
seqan3::debug_stream << "letter: " << letter << '\n'; // 10I
letter = 'D'_cigar_operation;
seqan3::debug_stream << "letter: " << letter << '\n'; // 10D
letter = 20;
seqan3::debug_stream << "letter: " << letter << '\n'; // 20D
}
// 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/cigar/cigar.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
// creates 10M, as the cigar_op field is not provided.
seqan3::cigar letter1{10};
seqan3::debug_stream << "letter1: " << letter1 << '\n'; // 10M
// creates 0I, as the integer field is not provided.
seqan3::cigar letter2{'I'_cigar_operation};
seqan3::debug_stream << "letter2: " << letter2 << '\n'; // 0I
// creates 10I, as both fields are explicitly given.
seqan3::cigar letter3{10, 'I'_cigar_operation};
seqan3::debug_stream << "letter3: " << letter3 << '\n'; // 10I
}
// 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/all.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter1{'T'_dna4, '"'_phred42};
letter1 = 'C'_rna4; // yields {'C'_dna4, '"'_phred42}
}
all.hpp
Meta-header for the Alphabet / Nucleotide submodule .
seqan3::qualified
Joins an arbitrary alphabet with a quality alphabet.
Definition qualified.hpp:59
// 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/all.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
// The following creates {'C'_dna4, '!'_phred42}
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter1{'C'_dna4};
// The following also creates {'C'_dna4, '!'_phred42}, since rna4 assignable to dna4
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter2{'C'_rna4};
if (letter1 == letter2)
seqan3::debug_stream << "yeah\n"; // yeah
}
// 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/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter1{'T'_dna4, '"'_phred42};
letter1 = 'C'_dna4; // yields {'C'_dna4, '"'_phred42}
letter1 = '#'_phred42; // yields {'C'_dna4, '#'_phred42}
}
// 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/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter1{'C'_dna4}; // creates {'C'_dna4, '!'_phred42}
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter2{'"'_phred42}; // creates {'A'_dna4, '"'_phred42}
if (letter1 == letter2)
seqan3::debug_stream << "yeah\n"; // yeah
}
// 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/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::alphabet_variant<seqan3::dna5, seqan3::gap> letter{}; // implicitly 'A'_dna5
seqan3::alphabet_variant<seqan3::dna5, seqan3::gap> letter2{'C'_dna5}; // constructed from alternative (== 'C'_dna5)
seqan3::alphabet_variant<seqan3::dna5, seqan3::gap> letter3{
'U'_rna5}; // constructed from type that alternative is constructible from (== 'T'_dna5)
letter2.assign_char('T'); // == 'T'_dna5
letter2.assign_char('-'); // == gap{}
letter2.assign_char('K'); // unknown characters map to the default/unknown
// character of the first alternative type (== 'N'_dna5)
letter2 = seqan3::gap{}; // assigned from alternative (== gap{})
letter2 = 'U'_rna5; // assigned from type that alternative is assignable from (== 'T'_dna5)
seqan3::dna5 letter4 = letter2.convert_to<seqan3::dna5>();
}
alphabet_variant.hpp
Provides seqan3::alphabet_variant.
seqan3::alphabet_variant
A combined alphabet that can hold values of either of its alternatives..
Definition alphabet_variant.hpp:127
seqan3::alphabet_variant::convert_to
constexpr auto convert_to() const
Convert to the specified alphabet (throws if holds_alternative() would be false).
Definition alphabet_variant.hpp:330
seqan3::gap
The alphabet of a gap character '-'.
Definition gap.hpp:36
gap.hpp
Provides seqan3::gap.
// 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/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::alphabet_variant<seqan3::dna4, seqan3::dna5> var;
var.assign_char('A'); // will be in the "dna4-state"
var = 'A'_dna5; // will be in the "dna5-state"
}
// 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/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter1{'C'_rna4};
seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter2 = 'C'_rna4;
}
// 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/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using namespace seqan3::literals;
// possible:
seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter1{'C'_dna5};
// not possible:
// seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter2 = 'C'_dna5;
}
// 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 <gtest/gtest.h>
#include <seqan3/alphabet/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using variant_t = seqan3::alphabet_variant<seqan3::dna5, seqan3::gap>;
static_assert(variant_t::is_alternative<seqan3::dna5>(), "dna5 is an alternative of variant_t");
static_assert(!variant_t::is_alternative<seqan3::dna4>(), "dna4 is not an alternative of variant_t");
static_assert(variant_t::is_alternative<seqan3::gap>(), "gap is an alternative of variant_t");
}
// 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/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter1{};
letter1 = 'C'_rna4;
}
// 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/composite/alphabet_variant.hpp>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/alphabet/nucleotide/all.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter1{'C'_dna4}; // or
seqan3::alphabet_variant<seqan3::dna4, seqan3::gap> letter2 = seqan3::gap{};
}
// 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
// This example illustrates how we can reduce the usage of templates (or the amount of different instantiations) via
// type erasure. Having only one function generated for `algorithm()` is the only benefit of using `semialphabet_any`
// here. Of course this only makes sense for your application if the part of the program that is agnostic of the
// character representation (your equivalent of `algorithm()`) is substantially larger than the specific parts – and
// if compile-time and/or size of the executable are a concern.
#include <iostream>
#include <seqan3/alphabet/aminoacid/all.hpp>
#include <seqan3/alphabet/composite/semialphabet_any.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/range/to.hpp>
using namespace seqan3::literals;
// Print is a template and gets instantiated two times because the behaviour is different for both types
template <typename rng_t>
void print(rng_t && r)
{
seqan3::debug_stream << r << '\n';
}
// Algorithm is not a template, only one instance is generated by the compiler
// Type information is encoded via a run-time parameter
void algorithm(std::vector<seqan3::semialphabet_any<10>> & r, bool is_murphy)
{
// Algorithm example that replaces rank 0 with rank 1
for (auto & v : r)
if (seqan3::to_rank(v) == 0)
seqan3::assign_rank_to(1, v);
// Here we verify the type for printing
if (is_murphy)
print(r
| std::views::transform(
[](auto const & in)
{
return static_cast<seqan3::aa10murphy>(in);
}));
else
print(r
| std::views::transform(
[](auto const & in)
{
return static_cast<seqan3::aa10li>(in);
}));
}
// Two instances of algo_pre exist
// They type erase the different arguments to the same type and encode the type information as a run-time parameter
void algo_pre(seqan3::aa10li_vector const & v)
{
std::vector<seqan3::semialphabet_any<10>> tmp = v
| std::views::transform(
[](auto const & in)
{
return static_cast<seqan3::semialphabet_any<10>>(in);
})
| seqan3::ranges::to<std::vector>();
algorithm(tmp, false);
}
void algo_pre(seqan3::aa10murphy_vector const & v)
{
std::vector<seqan3::semialphabet_any<10>> tmp = v
| std::views::transform(
[](auto const & in)
{
return static_cast<seqan3::semialphabet_any<10>>(in);
})
| seqan3::ranges::to<std::vector>();
algorithm(tmp, true);
}
int main()
{
seqan3::aa10li_vector v1{"AVRSTXOUB"_aa10li};
algo_pre(v1); // BIKBBBKCB
seqan3::aa10murphy_vector v2{"AVRSTXOUB"_aa10murphy};
algo_pre(v2); // BIKSSSKCB
}
seqan3::semialphabet_any
A semi-alphabet that type erases all other semi-alphabets of the same size.
Definition semialphabet_any.hpp:45
seqan3::ranges::to
seqan::stl::ranges::to to
Converts a range to a container. <dl class="no-api">This entity is not part of the SeqAn API....
Definition to.hpp:23
semialphabet_any.hpp
Provides seqan3::semialphabet_any.
to.hpp
Provides seqan3::ranges::to.
// 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 <vector>
#include <seqan3/alphabet/container/bitpacked_sequence.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> v0{"ACGT"_dna4}; // data occupies 4 bytes in memory
seqan3::bitpacked_sequence<seqan3::dna4> v1{"ACGT"_dna4}; // data occupies 1 byte in memory
}
bitpacked_sequence.hpp
Provides seqan3::bitpacked_sequence.
seqan3::bitpacked_sequence
A space-optimised version of std::vector that compresses multiple letters into a single byte.
Definition bitpacked_sequence.hpp:62
// 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 <vector>
#include <seqan3/alphabet/container/concatenated_sequences.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::concatenated_sequences<seqan3::dna4_vector> concat1{"ACGT"_dna4, "GAGGA"_dna4};
seqan3::debug_stream << concat1[0] << '\n'; // "ACGT"
std::vector<seqan3::dna4_vector> concat2{"ACTA"_dna4, "AGGA"_dna4};
concat1 = concat2; // you can assign from other ranges
concat2[0] = "ATTA"_dna4; // this works for vector of vector
concat1[0][1] = 'T'_dna4; // and this works for concatenated_sequences
seqan3::debug_stream << concat1[0] << '\n'; // "ATTA"
// if you know that you will be adding ten vectors of length ten:
std::vector<seqan3::dna4> vector_of_length10{"ACGTACGTAC"_dna4};
concat1.reserve(10);
concat1.concat_reserve(10 * vector_of_length10.size());
while (concat1.size() < 10)
{
// ...
concat1.push_back(vector_of_length10);
}
}
seqan3::concatenated_sequences
Container that stores sequences concatenated internally.
Definition concatenated_sequences.hpp:86
seqan3::concatenated_sequences::reserve
void reserve(size_type const new_cap)
Increase the capacity to a value that's greater or equal to new_cap.
Definition concatenated_sequences.hpp:776
seqan3::concatenated_sequences::size
size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition concatenated_sequences.hpp:706
seqan3::concatenated_sequences::push_back
void push_back(rng_type &&value)
Appends the given element value to the end of the container.
Definition concatenated_sequences.hpp:1216
seqan3::concatenated_sequences::concat_reserve
void concat_reserve(size_type const new_cap)
Increase the concat_capacity() to a value that's greater or equal to new_cap.
Definition concatenated_sequences.hpp:866
concatenated_sequences.hpp
Provides seqan3::concatenated_sequences.
std::vector::size
T size(T... args)
// 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/container/concatenated_sequences.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::concatenated_sequences<seqan3::dna4_vector> foobar;
foobar.insert(foobar.end(), "ACGT"_dna4);
seqan3::debug_stream << foobar[0] << '\n'; // "ACGT"
}
seqan3::concatenated_sequences::end
iterator end() noexcept
Returns an iterator to the element following the last element of the container.
Definition concatenated_sequences.hpp:487
seqan3::concatenated_sequences::insert
iterator insert(const_iterator pos, rng_type &&value)
Inserts value before position in the container.
Definition concatenated_sequences.hpp:921
// 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/container/concatenated_sequences.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::concatenated_sequences<seqan3::dna4_vector> foobar;
foobar.insert(foobar.end(), 2, "ACGT"_dna4);
seqan3::debug_stream << foobar[0] << '\n'; // "ACGT"
seqan3::debug_stream << foobar[1] << '\n'; // "ACGT"
}
// 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 <iostream>
#include <seqan3/alphabet/gap/gap.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
seqan3::gap my_gap = seqan3::gap{};
seqan3::gap another_gap{};
another_gap.assign_char('A'); // this does not change anything
seqan3::debug_stream << my_gap.to_char(); // outputs '-'
if (my_gap.to_char() == another_gap.to_char())
seqan3::debug_stream << "Both gaps are the same!\n";
}
seqan3::alphabet_base::to_char
constexpr char_type to_char() const noexcept
Return the letter as a character of char_type.
Definition alphabet_base.hpp:112
// 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/gap/gapped.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::gapped<seqan3::dna4> gapped_letter{};
seqan3::gapped<seqan3::dna4> converted_letter{'C'_dna4};
seqan3::gapped<seqan3::dna4> gap_letter{seqan3::gap{}};
seqan3::gapped<seqan3::dna4>{}.assign_char('C');
seqan3::gapped<seqan3::dna4>{}.assign_char('-'); // gap character
seqan3::gapped<seqan3::dna4>{}.assign_char('K'); // unknown characters map to the default/unknown
// character of the given alphabet type (i.e. A of dna4)
}
seqan3::gapped
alphabet_variant< alphabet_t, gap > gapped
Extends a given alphabet with a gap character.
Definition gapped.hpp:38
// 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/mask/mask.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
seqan3::mask my_mask = seqan3::mask::masked;
seqan3::mask another_mask{};
my_mask.assign_rank(false); // will assign my_mask the value mask::unmasked
another_mask.assign_rank(0); // will also assign another_mask the value mask::unmasked
if (my_mask.to_rank() == another_mask.to_rank())
seqan3::debug_stream << "Both are UNMASKED!\n";
}
seqan3::alphabet_base::to_rank
constexpr rank_type to_rank() const noexcept
Return the letter's numeric value (rank in the alphabet).
Definition alphabet_base.hpp:134
seqan3::alphabet_base::assign_rank
constexpr derived_type & assign_rank(rank_type const c) noexcept
Assign from a numeric value.
Definition alphabet_base.hpp:184
seqan3::mask
Implementation of a masked alphabet to be used for tuple composites.
Definition mask.hpp:35
seqan3::mask::masked
static mask const masked
Member for masked.
Definition mask.hpp:71
mask.hpp
Create a mask composite which can be applied with another alphabet.
// 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/mask/masked.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::masked<seqan3::dna4> dna4_masked{};
seqan3::masked<seqan3::dna4> dna4_another_masked{'A'_dna4, seqan3::mask::unmasked};
// create a dna4 masked alphabet with an unmasked A
dna4_masked.assign_char('a'); // assigns a masked 'A'_dna4
if (dna4_masked.to_char() != dna4_another_masked.to_char())
{
seqan3::debug_stream << dna4_masked.to_char() << " is not the same as " << dna4_another_masked.to_char()
<< "\n";
}
}
seqan3::mask::unmasked
static mask const unmasked
Member for unmasked.
Definition mask.hpp:65
seqan3::masked
Implementation of a masked composite, which extends a given alphabet with a mask.
Definition masked.hpp:42
seqan3::masked::assign_char
constexpr masked & assign_char(char_type const c) noexcept
Assign from a character.
Definition masked.hpp:86
seqan3::masked::to_char
constexpr char_type to_char() const noexcept
Return a character.
Definition masked.hpp:101
masked.hpp
Extends a given alphabet with the mask alphabet.
// 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/concept.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
using namespace seqan3::literals;
int main()
{
auto r1 = 'A'_rna5.complement(); // calls member function rna5::complement(); r1 == 'U'_rna5
auto r2 = seqan3::complement('A'_rna5); // calls global complement() function on the rna5 object; r2 == 'U'_rna5
}
concept.hpp
Provides seqan3::nucleotide_alphabet.
rna5.hpp
Provides seqan3::rna5, container aliases and string literals.
// 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/dna15.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15 letter{'A'_dna15};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('F'); // Unknown characters are implicitly converted to N.
seqan3::debug_stream << letter << '\n'; // prints "N"
}
seqan3::dna15
The 15 letter DNA alphabet, containing all IUPAC smybols minus the gap.
Definition dna15.hpp:48
dna15.hpp
Provides seqan3::dna15, container aliases and string literals.
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15 letter1{'A'_dna15};
auto letter2 = 'A'_dna15;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15 letter1 = 'C'_rna15; // implicitly converted
seqan3::dna15 letter2{};
letter2 = 'C'_rna15; // implicitly converted
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_inherit.cpp.in
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
struct my_dna15 : public seqan3::dna15
{
// using seqan3::dna15::dna15; // uncomment to import implicit conversion shown by letter1
};
struct my_rna15 : public seqan3::rna15
{};
int main()
{
using namespace seqan3::literals;
// my_dna15 letter1 = 'C'_rna15; // NO automatic implicit conversion!
// seqan3::dna15 letter2 = my_rna15{}; // seqan3::dna15 only allows implicit conversion from seqan3::rna15!
}
#include <seqan3/utility/concept.hpp>
static_assert(seqan3::implicitly_convertible_to<seqan3::rna15, seqan3::dna15>);
static_assert(!seqan3::implicitly_convertible_to<seqan3::rna15, my_dna15>);
static_assert(!seqan3::implicitly_convertible_to<my_rna15, seqan3::dna15>);
seqan3::rna15
The 15 letter RNA alphabet, containing all IUPAC smybols minus the gap.
Definition rna15.hpp:48
concept.hpp
Provides concepts that do not have equivalents in C++20.
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_vector.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15_vector vector{'A'_rna15, 'C'_rna15, 'G'_rna15}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::dna15_vector dna15_vector{"ACGT"_rna15};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::rna15_vector rna15_vector = "ACGT"_rna15;
seqan3::dna15_vector dna15_vector{rna15_vector.begin(), rna15_vector.end()};
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_views.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15_vector vector = "ACG"_dna15;
auto rna15_view = vector | seqan3::views::convert<seqan3::rna15>;
for (auto && chr : rna15_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::rna15 &&>);
}
}
seqan3::views::convert
constexpr auto convert
A view that converts each element in the input range (implicitly or via static_cast).
Definition utility/views/convert.hpp:66
convert.hpp
Provides seqan3::views::convert.
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15_vector sequence1{"ACGTTA"_dna15};
seqan3::dna15_vector sequence2 = "ACGTTA"_dna15;
auto sequence3 = "ACGTTA"_dna15;
}
// 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/dna16sam.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna16sam letter{'A'_dna16sam};
letter.assign_char('=');
seqan3::debug_stream << letter << '\n'; // prints "="
letter.assign_char('F'); // Unknown characters are implicitly converted to N.
seqan3::debug_stream << letter << '\n'; // "N";
}
seqan3::dna16sam
A 16 letter DNA alphabet, containing all IUPAC symbols minus the gap and plus an equality sign ('=').
Definition dna16sam.hpp:45
dna16sam.hpp
Provides seqan3::dna16sam.
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna16sam.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna16sam letter1{'A'_dna16sam};
auto letter2 = 'A'_dna16sam;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna16sam.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna16sam_vector sequence1{"ACGTTA"_dna16sam};
seqan3::dna16sam_vector sequence2 = "ACGTTA"_dna16sam;
auto sequence3 = "ACGTTA"_dna16sam;
}
// 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/dna3bs.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna3bs letter{'A'_dna3bs};
letter.assign_char('C'); // All C will be converted to T.
seqan3::debug_stream << letter << '\n'; // prints "T"
letter.assign_char('F'); // Unknown characters are implicitly converted to A.
seqan3::debug_stream << letter << '\n'; // prints "A"
}
seqan3::dna3bs
The three letter reduced DNA alphabet for bisulfite sequencing mode (A,G,T(=C)).
Definition dna3bs.hpp:58
dna3bs.hpp
Provides seqan3::dna3bs, container aliases and string literals.
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna3bs.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna3bs letter1{'A'_dna3bs};
auto letter2 = 'A'_dna3bs;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna3bs.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna3bs_vector sequence1{"ACGTTA"_dna3bs};
seqan3::dna3bs_vector sequence2 = "ACGTTA"_dna3bs;
auto sequence3 = "ACGTTA"_dna3bs;
}
// 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/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter{'C'_dna4};
letter.assign_char('F'); // Characters other than IUPAC characters are implicitly converted to A.
seqan3::debug_stream << letter << '\n'; // prints "A"
// IUPAC characters are implicitly converted to their best fitting representative
seqan3::debug_stream << letter.assign_char('R') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('Y') << '\n'; // prints "C"
seqan3::debug_stream << letter.assign_char('S') << '\n'; // prints "C"
seqan3::debug_stream << letter.assign_char('W') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('K') << '\n'; // prints "G"
seqan3::debug_stream << letter.assign_char('M') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('B') << '\n'; // prints "C"
seqan3::debug_stream << letter.assign_char('D') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('H') << '\n'; // prints "A"
seqan3::debug_stream << letter.assign_char('V') << '\n'; // prints "A"
letter.assign_char('a'); // Lower case letters are the same as their upper case equivalent.
seqan3::debug_stream << letter << '\n'; // prints "A"
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter1{'A'_dna4};
auto letter2 = 'A'_dna4;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 letter1 = 'C'_rna4; // implicitly converted
seqan3::dna4 letter2{};
letter2 = 'C'_rna4; // implicitly converted
}
rna4.hpp
Provides seqan3::rna4, container aliases and string literals.
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_inherit.cpp.in
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
struct my_dna4 : public seqan3::dna4
{
// using seqan3::dna4::dna4; // uncomment to import implicit conversion shown by letter1
};
struct my_rna4 : public seqan3::rna4
{};
int main()
{
using namespace seqan3::literals;
// my_dna4 letter1 = 'C'_rna4; // NO automatic implicit conversion!
// seqan3::dna4 letter2 = my_rna4{}; // seqan3::dna4 only allows implicit conversion from seqan3::rna4!
}
#include <seqan3/utility/concept.hpp>
static_assert(seqan3::implicitly_convertible_to<seqan3::rna4, seqan3::dna4>);
static_assert(!seqan3::implicitly_convertible_to<seqan3::rna4, my_dna4>);
static_assert(!seqan3::implicitly_convertible_to<my_rna4, seqan3::dna4>);
seqan3::rna4
The four letter RNA alphabet of A,C,G,U.
Definition rna4.hpp:46
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_vector.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vector{'A'_rna4, 'C'_rna4, 'G'_rna4}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::dna4_vector dna4_vector{"ACGT"_rna4};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::rna4_vector rna4_vector = "ACGT"_rna4;
seqan3::dna4_vector dna4_vector{rna4_vector.begin(), rna4_vector.end()};
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_views.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vector = "ACG"_dna4;
auto rna4_view = vector | seqan3::views::convert<seqan3::rna4>;
for (auto && chr : rna4_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::rna4 &&>);
}
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector sequence1{"ACGTTA"_dna4};
seqan3::dna4_vector sequence2 = "ACGTTA"_dna4;
auto sequence3 = "ACGTTA"_dna4;
}
// 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/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5 letter{'A'_dna5};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('F'); // Unknown characters are implicitly converted to N.
seqan3::debug_stream << letter << '\n'; // prints "N"
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5 letter1{'A'_dna5};
auto letter2 = 'A'_dna5;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5 letter1 = 'C'_rna5; // implicitly converted
seqan3::dna5 letter2{};
letter2 = 'C'_rna5; // implicitly converted
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_inherit.cpp.in
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
struct my_dna5 : public seqan3::dna5
{
// using seqan3::dna5::dna5; // uncomment to import implicit conversion shown by letter1
};
struct my_rna5 : public seqan3::rna5
{};
int main()
{
using namespace seqan3::literals;
// my_dna5 letter1 = 'C'_rna5; // NO automatic implicit conversion!
// seqan3::dna5 letter2 = my_rna5{}; // seqan3::dna5 only allows implicit conversion from seqan3::rna5!
}
#include <seqan3/utility/concept.hpp>
static_assert(seqan3::implicitly_convertible_to<seqan3::rna5, seqan3::dna5>);
static_assert(!seqan3::implicitly_convertible_to<seqan3::rna5, my_dna5>);
static_assert(!seqan3::implicitly_convertible_to<my_rna5, seqan3::dna5>);
seqan3::rna5
The five letter RNA alphabet of A,C,G,U and the unknown character N.
Definition rna5.hpp:46
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_vector.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector vector{'A'_rna5, 'C'_rna5, 'G'_rna5}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::dna5_vector dna5_vector{"ACGT"_rna5};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::rna5_vector rna5_vector = "ACGT"_rna5;
seqan3::dna5_vector dna5_vector{rna5_vector.begin(), rna5_vector.end()};
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_views.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector vector = "ACG"_dna5;
auto rna5_view = vector | seqan3::views::convert<seqan3::rna5>;
for (auto && chr : rna5_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::rna5 &&>);
}
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector sequence1{"ACGTTA"_dna5};
seqan3::dna5_vector sequence2 = "ACGTTA"_dna5;
auto sequence3 = "ACGTTA"_dna5;
}
// 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/rna15.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna15 letter{'A'_rna15};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('F'); // Unknown characters are implicitly converted to N.
seqan3::debug_stream << letter << '\n'; // prints "N"
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/rna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna15 letter1{'A'_rna15};
auto letter2 = 'A'_rna15;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna15 letter1 = 'C'_dna15; // implicitly converted
seqan3::rna15 letter2{};
letter2 = 'C'_dna15; // implicitly converted
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_inherit.cpp.in
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
struct my_rna15 : public seqan3::rna15
{
// using seqan3::rna15::rna15; // uncomment to import implicit conversion shown by letter1
};
struct my_dna15 : public seqan3::dna15
{};
int main()
{
using namespace seqan3::literals;
// my_rna15 letter1 = 'C'_dna15; // NO automatic implicit conversion!
// seqan3::rna15 letter2 = my_dna15{}; // seqan3::rna15 only allows implicit conversion from seqan3::dna15!
}
#include <seqan3/utility/concept.hpp>
static_assert(seqan3::implicitly_convertible_to<seqan3::dna15, seqan3::rna15>);
static_assert(!seqan3::implicitly_convertible_to<seqan3::dna15, my_rna15>);
static_assert(!seqan3::implicitly_convertible_to<my_dna15, seqan3::rna15>);
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_vector.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna15_vector vector{'A'_dna15, 'C'_dna15, 'G'_dna15}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::rna15_vector rna15_vector{"ACGT"_dna15};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::dna15_vector dna15_vector = "ACGT"_dna15;
seqan3::rna15_vector rna15_vector{dna15_vector.begin(), dna15_vector.end()};
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_views.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna15.hpp>
#include <seqan3/alphabet/nucleotide/rna15.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna15_vector vector = "ACG"_rna15;
auto dna15_view = vector | seqan3::views::convert<seqan3::dna15>;
for (auto && chr : dna15_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::dna15 &&>);
}
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/rna15.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna15_vector sequence1{"ACGTTA"_rna15};
seqan3::rna15_vector sequence2 = "ACGTTA"_rna15;
auto sequence3 = "ACGTTA"_rna15;
}
// 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/rna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna4 letter{'A'_rna4};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('F'); // Unknown characters are implicitly converted to A.
seqan3::debug_stream << letter << '\n'; // prints "A"
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna4 letter1{'A'_rna4};
auto letter2 = 'A'_rna4;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna4 letter1 = 'C'_dna4; // implicitly converted
seqan3::rna4 letter2{};
letter2 = 'C'_dna4; // implicitly converted
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_inherit.cpp.in
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
struct my_rna4 : public seqan3::rna4
{
// using seqan3::rna4::rna4; // uncomment to import implicit conversion shown by letter1
};
struct my_dna4 : public seqan3::dna4
{};
int main()
{
using namespace seqan3::literals;
// my_rna4 letter1 = 'C'_dna4; // NO automatic implicit conversion!
// seqan3::rna4 letter2 = my_dna4{}; // seqan3::rna4 only allows implicit conversion from seqan3::dna4!
}
#include <seqan3/utility/concept.hpp>
static_assert(seqan3::implicitly_convertible_to<seqan3::dna4, seqan3::rna4>);
static_assert(!seqan3::implicitly_convertible_to<seqan3::dna4, my_rna4>);
static_assert(!seqan3::implicitly_convertible_to<my_dna4, seqan3::rna4>);
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_vector.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna4_vector vector{'A'_dna4, 'C'_dna4, 'G'_dna4}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::rna4_vector rna4_vector{"ACGT"_dna4};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::dna4_vector dna4_vector = "ACGT"_dna4;
seqan3::rna4_vector rna4_vector{dna4_vector.begin(), dna4_vector.end()};
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_views.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna4_vector vector = "ACG"_rna4;
auto dna4_view = vector | seqan3::views::convert<seqan3::dna4>;
for (auto && chr : dna4_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::dna4 &&>);
}
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/rna4.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna4_vector sequence1{"ACGTTA"_rna4};
seqan3::rna4_vector sequence2 = "ACGTTA"_rna4;
auto sequence3 = "ACGTTA"_rna4;
}
// 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/rna5.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna5 letter{'A'_rna5};
letter.assign_char('C');
seqan3::debug_stream << letter << '\n'; // prints "C"
letter.assign_char('F'); // Unknown characters are implicitly converted to N.
seqan3::debug_stream << letter << '\n'; // prints "N"
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_char_literal.cpp.in
#include <seqan3/alphabet/nucleotide/rna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna5 letter1{'A'_rna5};
auto letter2 = 'A'_rna5;
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna5 letter1 = 'C'_dna5; // implicitly converted
seqan3::rna5 letter2{};
letter2 = 'C'_dna5; // implicitly converted
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_inherit.cpp.in
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
struct my_rna5 : public seqan3::rna5
{
// using seqan3::rna5::rna5; // uncomment to import implicit conversion shown by letter1
};
struct my_dna5 : public seqan3::dna5
{};
int main()
{
using namespace seqan3::literals;
// my_rna5 letter1 = 'C'_dna5; // NO automatic implicit conversion!
// seqan3::rna5 letter2 = my_dna5{}; // seqan3::rna5 only allows implicit conversion from seqan3::dna5!
}
#include <seqan3/utility/concept.hpp>
static_assert(seqan3::implicitly_convertible_to<seqan3::dna5, seqan3::rna5>);
static_assert(!seqan3::implicitly_convertible_to<seqan3::dna5, my_rna5>);
static_assert(!seqan3::implicitly_convertible_to<my_dna5, seqan3::rna5>);
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_vector.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna5_vector vector{'A'_dna5, 'C'_dna5, 'G'_dna5}; // (element-wise) implicit conversion
// but this won't work:
// seqan3::rna5_vector rna5_vector{"ACGT"_dna5};
// as a workaround you can use:
// side note: this would also work without the implicit conversion.
seqan3::dna5_vector dna5_vector = "ACGT"_dna5;
seqan3::rna5_vector rna5_vector{dna5_vector.begin(), dna5_vector.end()};
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_implicit_conversion_from_@source_alphabet@_views.cpp.in
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna5_vector vector = "ACG"_rna5;
auto dna5_view = vector | seqan3::views::convert<seqan3::dna5>;
for (auto && chr : dna5_view) // converts lazily on-the-fly
{
static_assert(std::same_as<decltype(chr), seqan3::dna5 &&>);
}
}
// 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
// generated from test/snippet/alphabet/nucleotide/@target_alphabet@_literal.cpp.in
#include <seqan3/alphabet/nucleotide/rna5.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::rna5_vector sequence1{"ACGTTA"_rna5};
seqan3::rna5_vector sequence2 = "ACGTTA"_rna5;
auto sequence3 = "ACGTTA"_rna5;
}
// 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/quality/phred42.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred42 letter{'@'_phred42};
letter.assign_char('!');
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "0"
seqan3::debug_stream << letter.to_char() << '\n'; // prints "!"
letter.assign_phred(49); // Values exceeding the maximum are implicitly limited to the maximum phred value.
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "41"
}
seqan3::phred42
Quality type for traditional Sanger and modern Illumina Phred scores.
Definition phred42.hpp:44
seqan3::phred_base::to_phred
constexpr phred_type to_phred() const noexcept
Return the alphabet's value in Phred score representation.
Definition phred_base.hpp:98
seqan3::phred_base::assign_phred
constexpr derived_type & assign_phred(phred_type const p) noexcept
Assign from the numeric Phred score value.
Definition phred_base.hpp:123
// 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/quality/phred42.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred42 letter1{'!'_phred42};
auto letter2 = '!'_phred42;
}
// 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/quality/phred42.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::phred42> sequence1{"##!!##"_phred42};
std::vector<seqan3::phred42> sequence2 = "##!!##"_phred42;
auto sequence3 = "##!!##"_phred42;
}
// 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/quality/phred63.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred63 letter{'@'_phred63};
letter.assign_char('!');
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "0"
seqan3::debug_stream << letter.to_char() << '\n'; // prints "!"
letter.assign_phred(72); // Values exceeding the maximum are implicitly limited to the maximum phred value.
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "62"
}
seqan3::phred63
Quality type for traditional Sanger and modern Illumina Phred scores.
Definition phred63.hpp:44
phred63.hpp
Provides seqan3::phred63 quality scores.
// 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/quality/phred63.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred63 letter1{'!'_phred63};
auto letter2 = '!'_phred63;
}
// 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/quality/phred63.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::phred63> sequence1{"##!!##"_phred63};
std::vector<seqan3::phred63> sequence2 = "##!!##"_phred63;
auto sequence3 = "##!!##"_phred63;
}
// 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/quality/phred68solexa.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred68solexa letter{'@'_phred68solexa};
letter.assign_char(';');
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "-5"
seqan3::debug_stream << letter.to_char() << '\n'; // prints ";"
letter.assign_phred(72); // Values exceeding the maximum are implicitly limited to the maximum phred value.
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "62"
}
seqan3::phred68solexa
Quality type for Solexa and deprecated Illumina formats.
Definition phred68solexa.hpp:37
phred68solexa.hpp
Provides seqan3::phred68solexa quality scores.
// 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/quality/phred68solexa.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred68solexa letter1{'!'_phred68solexa};
auto letter2 = '!'_phred68solexa;
}
// 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/quality/phred68solexa.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::phred68solexa> sequence1{"##!!##"_phred68solexa};
std::vector<seqan3::phred68solexa> sequence2 = "##!!##"_phred68solexa;
auto sequence3 = "##!!##"_phred68solexa;
}
// 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/quality/phred94.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred94 letter{'@'_phred94};
letter.assign_char('!');
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "0"
seqan3::debug_stream << letter.to_char() << '\n'; // prints "!"
letter.assign_phred(99); // Values exceeding the maximum are implicitly limited to the maximum phred value.
seqan3::debug_stream << letter.to_phred() << '\n'; // prints "93"
}
seqan3::phred94
Quality type for PacBio Phred scores of HiFi reads.
Definition phred94.hpp:41
phred94.hpp
Provides seqan3::phred94 quality scores.
// 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/quality/phred94.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::phred94 letter1{'!'_phred94};
auto letter2 = '!'_phred94;
}
// 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/quality/phred94.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::phred94> sequence1{"##!!##"_phred94};
std::vector<seqan3::phred94> sequence2 = "##!!##"_phred94;
auto sequence3 = "##!!##"_phred94;
}
// 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/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
using seqan3::get;
seqan3::qualified<seqan3::dna4, seqan3::phred42> letter{'A'_dna4, '('_phred42};
seqan3::debug_stream << seqan3::to_rank(letter) << ' ' // 7
<< seqan3::to_rank(get<0>(letter)) << ' ' // 0
<< seqan3::to_rank(get<1>(letter)) << '\n'; // 7
seqan3::debug_stream << seqan3::to_char(letter) << ' ' // A
<< seqan3::to_char(get<0>(letter)) << ' ' // A
<< seqan3::to_char(get<1>(letter)) << '\n'; // (
seqan3::debug_stream << seqan3::to_phred(letter) << ' ' // 7
<< seqan3::to_phred(get<1>(letter)) << '\n'; // 7
// Modify:
get<0>(letter) = 'G'_dna4;
seqan3::debug_stream << seqan3::to_char(letter) << '\n'; // G
}
seqan3::to_phred
constexpr auto to_phred
The public getter function for the Phred representation of a quality score.
Definition alphabet/quality/concept.hpp:97
// 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/structure/dot_bracket3.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dot_bracket3 letter{'.'_db3};
letter.assign_char('(');
seqan3::debug_stream << letter << '\n'; // prints "("
letter.assign_char('F'); // Unknown characters are implicitly converted to '.'.
seqan3::debug_stream << letter << '\n'; // prints "."
}
seqan3::dot_bracket3
The three letter RNA structure alphabet of the characters ".()".
Definition dot_bracket3.hpp:51
dot_bracket3.hpp
Provides the dot bracket format for RNA structure.
// 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/structure/dot_bracket3.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dot_bracket3 letter1{'('_db3};
auto letter2 = '('_db3;
}
// 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/structure/dot_bracket3.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dot_bracket3> sequence1{".(..)."_db3};
std::vector<seqan3::dot_bracket3> sequence2 = ".(..)."_db3;
auto sequence3 = ".(..)."_db3;
}
// 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/structure/dssp9.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dssp9 letter{'H'_dssp9};
letter.assign_char('B');
seqan3::debug_stream << letter << '\n'; // prints "B"
letter.assign_char('F'); // Unknown characters are implicitly converted to 'X'.
seqan3::debug_stream << letter << '\n'; // prints "X"
}
seqan3::dssp9
The protein structure alphabet of the characters "HGIEBTSCX".
Definition dssp9.hpp:59
dssp9.hpp
Provides the dssp format for protein structure.
// 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/structure/dssp9.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dssp9 letter1{'('_dssp9};
auto letter2 = '('_dssp9;
}
// 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/structure/dssp9.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dssp9> sequence1{"EHHHHT"_dssp9};
std::vector<seqan3::dssp9> sequence2 = "EHHHHT"_dssp9;
auto sequence3 = "EHHHHT"_dssp9;
}
// 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/aminoacid/aa27.hpp>
#include <seqan3/alphabet/structure/dssp9.hpp>
#include <seqan3/alphabet/structure/structured_aa.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
using seqan3::get;
seqan3::structured_aa<seqan3::aa27, seqan3::dssp9> letter{'W'_aa27, 'B'_dssp9};
seqan3::debug_stream << seqan3::to_rank(letter) << ' ' // 199
<< seqan3::to_rank(get<0>(letter)) << ' ' // 22
<< seqan3::to_rank(get<1>(letter)) << '\n'; // 1
seqan3::debug_stream << seqan3::to_char(letter) << ' ' // W
<< seqan3::to_char(get<0>(letter)) << ' ' // W
<< seqan3::to_char(get<1>(letter)) << '\n'; // B
// Modify:
get<0>(letter) = 'V'_aa27;
seqan3::debug_stream << seqan3::to_char(letter) << '\n'; // V
}
seqan3::structured_aa
A seqan3::alphabet_tuple_base that joins an aminoacid alphabet with a protein structure alphabet.
Definition structured_aa.hpp:52
structured_aa.hpp
Provides the composite of aminoacid with structure alphabets.
// 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/rna4.hpp>
#include <seqan3/alphabet/structure/dot_bracket3.hpp>
#include <seqan3/alphabet/structure/structured_rna.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
using seqan3::get;
seqan3::structured_rna<seqan3::rna4, seqan3::dot_bracket3> letter{'G'_rna4, '('_db3};
seqan3::debug_stream << seqan3::to_rank(letter) << ' ' // 7
<< seqan3::to_rank(get<0>(letter)) << ' ' // 2
<< seqan3::to_rank(get<1>(letter)) << '\n'; // 1
seqan3::debug_stream << seqan3::to_char(letter) << ' ' // G
<< seqan3::to_char(get<0>(letter)) << ' ' // G
<< seqan3::to_char(get<1>(letter)) << '\n'; // (
// Modify:
get<0>(letter) = 'U'_rna4;
seqan3::debug_stream << seqan3::to_char(letter) << '\n'; // U
}
seqan3::structured_rna
A seqan3::alphabet_tuple_base that joins a nucleotide alphabet with an RNA structure alphabet.
Definition structured_rna.hpp:53
structured_rna.hpp
Provides the composite of nucleotide with structure alphabets.
// 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/structure/wuss.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::wuss51 letter{':'_wuss51};
letter.assign_char('~');
seqan3::debug_stream << letter << '\n'; // prints "~"
letter.assign_char('#'); // Unknown characters are implicitly converted to ';'.
seqan3::debug_stream << letter << '\n'; // prints ";"
}
seqan3::structured_rna::assign_char
constexpr structured_rna & assign_char(char_type const c) noexcept
Assign from a nucleotide character. This modifies the internal sequence letter.
Definition structured_rna.hpp:139
wuss.hpp
Provides the WUSS format for RNA structure.
// 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/structure/wuss.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::wuss51 letter1{'('_wuss51};
auto letter2 = '('_wuss51;
}
// 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 <iostream>
#include <seqan3/alphabet/structure/wuss.hpp>
int main()
{
using namespace seqan3::literals;
bool is_closing_char_member = '}'_wuss51.is_pair_close();
bool is_closing_char_free = seqan3::is_pair_close('.'_wuss51);
std::cout << std::boolalpha << is_closing_char_member << '\n'; // true
std::cout << std::boolalpha << is_closing_char_free << '\n'; // false
}
std::boolalpha
T boolalpha(T... args)
seqan3::is_pair_close
constexpr auto is_pair_close
Check whether the given character represents a leftward interaction in an RNA structure.
Definition alphabet/structure/concept.hpp:179
// 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 <iostream>
#include <seqan3/alphabet/structure/wuss.hpp>
int main()
{
using namespace seqan3::literals;
bool is_opening_char_member = '{'_wuss51.is_pair_open();
bool is_opening_char_free = seqan3::is_pair_open('.'_wuss51);
std::cout << std::boolalpha << is_opening_char_member << '\n'; // true
std::cout << std::boolalpha << is_opening_char_free << '\n'; // false
}
seqan3::is_pair_open
constexpr auto is_pair_open
Check whether the given character represents a rightward interaction in an RNA structure.
Definition alphabet/structure/concept.hpp:97
// 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 <iostream>
#include <seqan3/alphabet/structure/wuss.hpp>
int main()
{
using namespace seqan3::literals;
bool is_unpaired_char_member = '.'_wuss51.is_unpaired();
bool is_unpaired_char_free = seqan3::is_unpaired('{'_wuss51);
std::cout << std::boolalpha << is_unpaired_char_member << '\n'; // true
std::cout << std::boolalpha << is_unpaired_char_free << '\n'; // false
}
seqan3::is_unpaired
constexpr auto is_unpaired
Check whether the given character represents an unpaired nucleotide in an RNA structure.
Definition alphabet/structure/concept.hpp:261
// 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/structure/wuss.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::wuss51> sequence1{".<..>."_wuss51};
std::vector<seqan3::wuss51> sequence2 = ".<..>."_wuss51;
auto sequence3 = ".<..>."_wuss51;
}
// 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 <iostream>
#include <seqan3/alphabet/structure/wuss.hpp>
int main()
{
uint8_t max_depth_member = seqan3::wuss51::max_pseudoknot_depth;
uint8_t max_depth_meta = seqan3::max_pseudoknot_depth<seqan3::wuss51>;
std::cout << static_cast<uint16_t>(max_depth_member) << '\n'; // 22
std::cout << static_cast<uint16_t>(max_depth_meta) << '\n'; // 22
}
seqan3::max_pseudoknot_depth
constexpr auto max_pseudoknot_depth
A type trait that holds the ability of the structure alphabet to represent pseudoknots,...
Definition alphabet/structure/concept.hpp:371
// 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/structure/wuss.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
auto pk_opt = '.'_wuss51.pseudoknot_id(); // std::optional -> false
pk_opt = seqan3::pseudoknot_id('{'_wuss51); // std::optional -> true: 3
if (pk_opt)
seqan3::debug_stream << *pk_opt << '\n'; // 3
}
seqan3::pseudoknot_id
constexpr auto pseudoknot_id
Retrieve an id for the level of a pseudoknotted interaction (also known as 'page number').
Definition alphabet/structure/concept.hpp:454
// 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/views/char_strictly_to.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
std::string_view str{"ACTTTGATAN"};
try
{
seqan3::debug_stream << (str | seqan3::views::char_strictly_to<seqan3::dna4>); // ACTTTGATA
}
catch (seqan3::invalid_char_assignment const &)
{
seqan3::debug_stream << "\n[ERROR] Invalid char!\n"; // Will throw on parsing 'N'
}
}
char_strictly_to.hpp
Provides seqan3::views::char_strictly_to.
seqan3::views::char_strictly_to
auto const char_strictly_to
A view over an alphabet, given a range of characters.
Definition char_strictly_to.hpp:69
seqan3::invalid_char_assignment
An exception typically thrown by seqan3::alphabet::assign_char_strict.
Definition alphabet/exception.hpp:27
// 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/views/char_to.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
std::string str{"ACTTTGATAN"};
seqan3::debug_stream << (str | seqan3::views::char_to<seqan3::dna4>) << '\n'; // ACTTTGATAA
seqan3::debug_stream << (str | seqan3::views::char_to<seqan3::dna5>) << '\n'; // ACTTTGATAN
}
char_to.hpp
Provides seqan3::views::char_to.
// 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/dna5.hpp>
#include <seqan3/alphabet/views/complement.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector foo{"ACGTA"_dna5};
// pipe notation
auto v = foo | seqan3::views::complement;
seqan3::debug_stream << v << '\n'; // TGCAT
// function notation
auto v2(seqan3::views::complement(foo));
seqan3::debug_stream << v2 << '\n'; // TGCAT
// generate the reverse complement:
auto v3 = foo | seqan3::views::complement | std::views::reverse;
seqan3::debug_stream << v3 << '\n'; // TACGT
}
complement.hpp
Provides seqan3::views::complement.
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/quality/aliases.hpp> // includes seqan3::dna4q
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec = "ACTTTGATA"_dna4;
auto v = vec | seqan3::views::to_char;
seqan3::debug_stream << v << '\n'; // [A,C,T,T,T,G,A,T,A]
std::vector<seqan3::phred42> qvec{seqan3::phred42{}.assign_phred(0),
seqan3::phred42{}.assign_phred(7),
seqan3::phred42{}.assign_phred(5),
seqan3::phred42{}.assign_phred(3),
seqan3::phred42{}.assign_phred(7),
seqan3::phred42{}.assign_phred(4),
seqan3::phred42{}.assign_phred(30),
seqan3::phred42{}.assign_phred(16),
seqan3::phred42{}.assign_phred(23)};
auto v3 = qvec | seqan3::views::to_char;
seqan3::debug_stream << v3 << '\n'; // [!,(,&,$,(,%,?,1,8]
std::vector<seqan3::dna4q> qcvec{{'C'_dna4, '!'_phred42},
{'A'_dna4, '('_phred42},
{'G'_dna4, '&'_phred42},
{'T'_dna4, '$'_phred42},
{'G'_dna4, '('_phred42},
{'A'_dna4, '%'_phred42},
{'C'_dna4, '?'_phred42},
{'T'_dna4, '1'_phred42},
{'A'_dna4, '8'_phred42}};
auto v4 = qcvec | seqan3::views::to_char;
seqan3::debug_stream << v4 << '\n'; // [C,A,G,T,G,A,C,T,A]
}
seqan3::views::to_char
auto const to_char
A view that calls seqan3::to_char() on each element in the input range.
Definition to_char.hpp:60
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/quality/aliases.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/views/to_rank.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec = "ACTTTGATA"_dna4;
auto v = vec | seqan3::views::to_rank;
seqan3::debug_stream << v << '\n'; // [0,1,3,3,3,2,0,3,0]
std::vector<seqan3::phred42> qvec{seqan3::phred42{}.assign_phred(0),
seqan3::phred42{}.assign_phred(7),
seqan3::phred42{}.assign_phred(5),
seqan3::phred42{}.assign_phred(3),
seqan3::phred42{}.assign_phred(7),
seqan3::phred42{}.assign_phred(4),
seqan3::phred42{}.assign_phred(30),
seqan3::phred42{}.assign_phred(16),
seqan3::phred42{}.assign_phred(23)};
auto v3 = qvec | seqan3::views::to_rank;
seqan3::debug_stream << v3 << '\n'; // [0,7,5,3,7,4,30,16,23]
std::vector<seqan3::dna4q> qcvec{{'C'_dna4, '!'_phred42},
{'A'_dna4, '('_phred42},
{'G'_dna4, '&'_phred42},
{'T'_dna4, '$'_phred42},
{'G'_dna4, '('_phred42},
{'A'_dna4, '%'_phred42},
{'C'_dna4, '?'_phred42},
{'T'_dna4, '1'_phred42},
{'A'_dna4, '8'_phred42}};
auto v4 = qcvec | seqan3::views::to_rank;
seqan3::debug_stream << v4 << '\n'; // [42,7,89,129,91,4,72,142,23]
}
seqan3::views::to_rank
auto const to_rank
A view that calls seqan3::to_rank() on each element in the input range.
Definition to_rank.hpp:63
to_rank.hpp
Provides seqan3::views::to_rank.
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/views/rank_to.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
std::vector<int> vec{0, 1, 3, 3, 3, 2, 0, 3, 0};
seqan3::debug_stream << (vec | seqan3::views::rank_to<seqan3::dna4>) << '\n'; // ACTTTGATA
seqan3::debug_stream << (vec | seqan3::views::rank_to<seqan3::dna5>) << '\n'; // ACNNNGANA
}
seqan3::views::rank_to
auto const rank_to
A view over an alphabet, given a range of ranks.
Definition rank_to.hpp:63
rank_to.hpp
Provides seqan3::views::rank_to.
// 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 <iostream>
#include <seqan3/alphabet/adaptation/char.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
using namespace seqan3::literals;
auto char_to_char = seqan3::to_char('A'); // calls seqan3::custom::to_char('A')
auto dna5_to_char = seqan3::to_char('A'_dna5); // calls .to_char() member
std::cout << char_to_char << '\n'; // A
std::cout << dna5_to_char << '\n'; // A
}
// 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 <iostream>
#include <seqan3/alphabet/adaptation/char.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
int main()
{
using namespace seqan3::literals;
auto char_to_rank = seqan3::to_rank('A'); // calls seqan3::custom::to_rank('A')
static_assert(std::same_as<decltype(char_to_rank), uint8_t>);
std::cout << static_cast<uint16_t>(char_to_rank) << '\n'; // 65
auto dna5_to_rank = seqan3::to_rank('A'_dna5); // calls .to_char() member
static_assert(std::same_as<decltype(dna5_to_rank), uint8_t>);
std::cout << static_cast<uint16_t>(dna5_to_rank) << '\n'; // 0
}
// 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/dna5.hpp>
#include <seqan3/alphabet/views/complement.hpp>
#include <seqan3/alphabet/views/translate.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector vec{"ACGTACGTACGTA"_dna5};
// Default (first forward frame)
auto v1 = vec | seqan3::views::translate_single;
// == [T,Y,V,R]
seqan3::debug_stream << v1[1] << '\n';
// First forward frame
auto v2 = vec | seqan3::views::translate_single(seqan3::translation_frames::forward_frame0);
// == [T,Y,V,R]
// First reverse frame
auto v3 = vec | seqan3::views::translate_single(seqan3::translation_frames::reverse_frame0);
// == [Y,V,R,T]
// Second forward frame
auto v4 = vec | seqan3::views::translate_single(seqan3::translation_frames::forward_frame1);
// == [R,T,Y,V]
// Second reverse frame
auto v5 = vec | seqan3::views::translate_single(seqan3::translation_frames::reverse_frame1);
// == [T,Y,V,R]
// Third forward frame
auto v6 = vec | seqan3::views::translate_single(seqan3::translation_frames::forward_frame2);
// == [V,R,T]
// Third reverse frame
auto v7 = vec | seqan3::views::translate_single(seqan3::translation_frames::reverse_frame2);
// == [R,T,Y]
// function syntax
auto v8 = seqan3::views::translate_single(vec, seqan3::translation_frames::forward_frame0);
// == [T,Y,V,R]
// combinability
auto v9 =
vec | seqan3::views::complement | seqan3::views::translate_single(seqan3::translation_frames::reverse_frame0);
// == [M,H,A,C]
// combinability with default parameter
auto v10 = vec | seqan3::views::complement | seqan3::views::translate_single;
// == [C,M,H,A]
// combinability with default parameter
auto v11 = vec | seqan3::views::complement | seqan3::views::translate_single();
// == [C,M,H,A]
}
seqan3::views::translate_single
constexpr auto translate_single
A view that translates nucleotide into aminoacid alphabet for one of the six frames.
Definition translate.hpp:520
seqan3::translation_frames::forward_frame2
@ forward_frame2
The third forward frame starting at position 2.
Definition translate.hpp:62
seqan3::translation_frames::forward_frame0
@ forward_frame0
The first forward frame starting at position 0.
Definition translate.hpp:60
seqan3::translation_frames::reverse_frame0
@ reverse_frame0
The first reverse frame starting at position 0.
Definition translate.hpp:63
seqan3::translation_frames::reverse_frame2
@ reverse_frame2
The third reverse frame starting at position 2.
Definition translate.hpp:65
seqan3::translation_frames::forward_frame1
@ forward_frame1
The second forward frame starting at position 1.
Definition translate.hpp:61
seqan3::translation_frames::reverse_frame1
@ reverse_frame1
The second reverse frame starting at position 1.
Definition translate.hpp:64
translate.hpp
Provides seqan3::views::translate and seqan3::views::translate_single.
// 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 <iostream>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/char_to.hpp>
#include <seqan3/alphabet/views/translate_join.hpp>
#include <seqan3/core/debug_stream.hpp>
using namespace seqan3::literals;
int main()
{
// Input range needs to be two-dimensional
std::vector<std::vector<seqan3::dna4>> vec{"ACGTACGTACGTA"_dna4, "TCGAGAGCTTTAGC"_dna4};
// Translation with default parameters
auto v1 = vec | seqan3::views::translate_join;
seqan3::debug_stream << v1 << "\n"; // [TYVR,RTYV,VRT,YVRT,TYVR,RTY,SRAL,REL*,ESFS,AKAL,LKLS,*SSR]
// Access the third forward frame (index_frame 2) of the second input sequence (index_seq 1)
// Required frames per sequence s = 6
// n = (index_seq * s) + j
// = 1 * 6 + 2
// = 8
auto third_frame_second_seq = v1[1 * 6 + 2];
seqan3::debug_stream << third_frame_second_seq << "\n"; // ESFS
// Translation with custom translation frame
auto v2 = vec | seqan3::views::translate_join(seqan3::translation_frames::forward_frame0);
seqan3::debug_stream << v2 << "\n"; // [TYVR,SRAL]
return 0;
}
seqan3::views::translate_join
constexpr auto translate_join
A view that translates nucleotide into aminoacid alphabet with 1, 2, 3 or 6 frames....
Definition translate_join.hpp:378
translate_join.hpp
Provides seqan3::views::translate_join.
// 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/dna5.hpp>
#include <seqan3/alphabet/views/complement.hpp>
#include <seqan3/alphabet/views/translate.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector vec{"ACGTACGTACGTA"_dna5};
// default frame translation
auto v1 = vec | seqan3::views::translate;
seqan3::debug_stream << v1 << '\n'; // [TYVR,RTYV,VRT,YVRT,TYVR,RTY]
// single frame translation
auto v2 = vec | seqan3::views::translate(seqan3::translation_frames::forward_frame0);
seqan3::debug_stream << v2 << '\n'; // [TYVR]
// reverse translation
auto v3 = vec | seqan3::views::translate(seqan3::translation_frames::forward_reverse0);
seqan3::debug_stream << v3 << '\n'; // [TYVR,YVRT]
// forward frames translation
auto v4 = vec | seqan3::views::translate(seqan3::translation_frames::forward_frames);
seqan3::debug_stream << v4 << '\n'; // [TYVR,RTYV,VRT]
// six frame translation
auto v5 = vec | seqan3::views::translate(seqan3::translation_frames::six_frames);
seqan3::debug_stream << v5 << '\n'; // [TYVR,RTYV,VRT,YVRT,TYVR,RTY]
// function syntax
auto v6 = seqan3::views::translate(vec, seqan3::translation_frames::forward_reverse0);
seqan3::debug_stream << v6 << '\n'; // [TYVR,YVRT]
// combinability
auto v7 = vec | seqan3::views::complement | seqan3::views::translate(seqan3::translation_frames::forward_reverse0);
seqan3::debug_stream << v7 << '\n'; // [CMHA,MHAC]
}
seqan3::translation_frames::forward_frames
@ forward_frames
All forward frames.
Definition translate.hpp:69
seqan3::translation_frames::six_frames
@ six_frames
All frames.
Definition translate.hpp:71
seqan3::translation_frames::forward_reverse0
@ forward_reverse0
The first forward and first reverse frame.
Definition translate.hpp:66
// 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 <string>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/quality/aliases.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/alphabet/views/trim_quality.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna5q> vec{{'A'_dna5, 'I'_phred42},
{'G'_dna5, 'I'_phred42},
{'G'_dna5, '?'_phred42},
{'A'_dna5, '5'_phred42},
{'T'_dna5, '+'_phred42}};
// trim by phred_value
auto v1 = vec | seqan3::views::trim_quality(20u);
seqan3::debug_stream << v1 << '\n'; // AGGA
// trim by quality character; in this case the nucleotide part of the character is irrelevant
auto v2 = vec | seqan3::views::trim_quality(seqan3::dna5q{'C'_dna5, '5'_phred42});
seqan3::debug_stream << v2 << '\n'; // AGGA
// combinability
auto v3 = seqan3::views::trim_quality(vec, 20u) | seqan3::views::to_char;
seqan3::debug_stream << v3 << '\n'; // AGGA
}
seqan3::views::trim_quality
constexpr auto trim_quality
A view that does quality-threshold trimming on a range of seqan3::quality_alphabet.
Definition trim_quality.hpp:126
seqan3::dna5q
qualified< dna5, phred42 > dna5q
An alphabet that stores a seqan3::dna5 letter and an seqan3::phred42 letter at each position.
Definition aliases.hpp:38
trim_quality.hpp
Provides seqan3::views::trim_quality.
// 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 <string>
#include <vector>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/alphabet/views/trim_quality.hpp>
#include <seqan3/core/debug_stream.hpp>
using namespace seqan3::literals;
int main()
{
std::vector<seqan3::phred42> vec{"II?5+"_phred42};
// trim by phred_value
auto v1 = vec | seqan3::views::trim_quality(20u);
seqan3::debug_stream << v1 << '\n'; // II?5
// trim by quality character
auto v2 = vec | seqan3::views::trim_quality('I'_phred42);
seqan3::debug_stream << v2 << '\n'; // II
// function syntax
auto v3 = seqan3::views::trim_quality(vec, '5'_phred42);
seqan3::debug_stream << v3 << '\n'; // II?5
// combinability
auto v4 = seqan3::views::trim_quality(vec, 20u) | seqan3::views::to_char;
seqan3::debug_stream << v4 << '\n'; // II?5
}
// 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/views/validate_char_for.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
std::string_view str{"ACTTTGATAN"};
try
{
seqan3::debug_stream << (str | seqan3::views::validate_char_for<seqan3::dna4>); // ACTTTGATA
}
catch (seqan3::invalid_char_assignment const &)
{
seqan3::debug_stream << "\n[ERROR] Invalid char!\n"; // Will throw on parsing 'N'
}
}
seqan3::views::validate_char_for
auto const validate_char_for
An identity view that throws if an encountered character is not valid for the given alphabet.
Definition validate_char_for.hpp:70
validate_char_for.hpp
Provides seqan3::views::validate_char_for.
// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char ** argv)
{
seqan3::argument_parser myparser{"Grade-Average", argc, argv}; // initialize
std::string name{"Max Muster"}; // define default values directly in the variable.
bool bonus{false};
std::vector<double> grades{}; // you can also specify a vector that is treated as a list option.
myparser.add_option(name, 'n', "name", "Please specify your name.");
myparser.add_flag(bonus, 'b', "bonus", "Please specify if you got the bonus.");
myparser.add_positional_option(grades, "Please specify your grades.");
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << '\n'; // customize your error message
return -1;
}
if (bonus)
grades.push_back(1.0); // extra good grade
double avg{0};
for (auto g : grades)
avg += g;
avg = avg / grades.size();
seqan3::debug_stream << name << " has an average grade of " << avg << '\n';
return 0;
}
// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char ** argv)
{
seqan3::argument_parser myparser{"The-Age-App", argc, argv}; // initialize
int age{30}; // define default values directly in the variable
myparser.add_option(age, 'a', "user-age", "Please specify your age.");
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "The-Age-App - [PARSER ERROR] " << ext.what() << '\n'; // customize your error message
return -1;
}
seqan3::debug_stream << "integer given by user: " << age << '\n';
return 0;
}
// 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/argument_parser/all.hpp>
int main(int argc, char ** argv)
{
seqan3::argument_parser myparser{"Penguin_Parade", argc, argv}; // initialize
myparser.info.version = "2.0.0";
myparser.info.date = "12.01.2017";
myparser.info.short_description = "Organize your penguin parade";
myparser.info.description.push_back("First Paragraph.");
myparser.info.description.push_back("Second Paragraph.");
myparser.info.examples.push_back("./penguin_parade Skipper Kowalski Rico Private -d 10 -m 02 -y 2017");
int d{01}; // day
int m{01}; // month
int y{2050}; // year
myparser.add_option(d, 'd', "day", "Please specify your preferred day.");
myparser.add_option(m, 'm', "month", "Please specify your preferred month.");
myparser.add_option(y, 'y', "year", "Please specify your preferred year.");
std::vector<std::string> penguin_names;
myparser.add_positional_option(penguin_names, "Specify the names of the penguins.");
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << ext.what() << "\n";
return -1;
}
// organize ...
return 0;
}
seqan3::argument_parser_meta_data::date
std::string date
The date that the application was last updated. Keep this updated, ! since it will tell your users th...
Definition auxiliary.hpp:305
seqan3::argument_parser_meta_data::examples
std::vector< std::string > examples
Provide some examples on how to use your tool and what standard parameters might be appropriate in di...
Definition auxiliary.hpp:336
// 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/argument_parser/all.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv};
std::string myvar{"Example"};
myparser.add_option(myvar, 's', "special-op", "You know what you doin'?", seqan3::option_spec::advanced);
}
seqan3::advanced
@ advanced
Definition auxiliary.hpp:256
// 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 <ranges>
#include <system_error>
#include <seqan3/argument_parser/all.hpp>
namespace seqan3::custom
{
// Specialise the seqan3::custom::argument_parsing data structure to enable parsing of std::errc.
template <>
struct argument_parsing<std::errc>
{
// Specialise a mapping from an identifying string to the respective value of your type Foo.
static inline std::unordered_map<std::string_view, std::errc> const enumeration_names{
{"no_error", std::errc{}},
{"timed_out", std::errc::timed_out},
{"invalid_argument", std::errc::invalid_argument},
{"io_error", std::errc::io_error}};
};
} // namespace seqan3::custom
int main(int argc, char const * argv[])
{
std::errc value{};
seqan3::argument_parser parser{"my_program", argc, argv};
// Because of the argument_parsing struct and
// the static member function enumeration_names
// you can now add an option that takes a value of type std::errc:
parser.add_option(value,
'e',
"errc",
"Give me a std::errc value.",
seqan3::option_spec::standard,
seqan3::value_list_validator{(seqan3::enumeration_names<std::errc> | std::views::values)});
try
{
parser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
return 0;
}
seqan3::value_list_validator
A validator that checks whether a value is inside a list of valid values.
Definition validators.hpp:199
std::errc
seqan3::enumeration_names
auto const enumeration_names
Return a conversion map from std::string_view to option_type.
Definition auxiliary.hpp:162
seqan3::custom
A namespace for third party and standard library specialisations of SeqAn customisation points.
Definition char.hpp:40
std
SeqAn specific customisations in the standard namespace.
system_error
std::unordered_map
// 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/argument_parser/all.hpp>
namespace foo
{
enum class bar
{
one,
two,
three
};
// Specialise a mapping from an identifying string to the respective value of your type bar.
auto enumeration_names(bar)
{
return std::unordered_map<std::string_view, bar>{{"one", bar::one}, {"two", bar::two}, {"three", bar::three}};
}
} // namespace foo
int main(int argc, char const * argv[])
{
foo::bar value{};
seqan3::argument_parser parser{"my_program", argc, argv};
// Because of the enumeration_names function
// you can now add an option that takes a value of type bar:
parser.add_option(value,
'f',
"foo",
"Give me a foo value.",
seqan3::option_spec::standard,
seqan3::value_list_validator{(seqan3::enumeration_names<foo::bar> | std::views::values)});
try
{
parser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
}
// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char ** argv)
{
seqan3::argument_parser myparser{"awesome-app", argc, argv}; // initialize
int a{3};
myparser.add_option(a, 'a', "awesome-parameter", "Please specify an integer.");
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << '\n'; // customize your error message
return -1;
}
if (myparser.is_option_set('a'))
seqan3::debug_stream << "The user set option -a on the command line.\n";
if (myparser.is_option_set("awesome-parameter"))
seqan3::debug_stream << "The user set option --awesome-parameter on the command line.\n";
// Asking for an option identifier that was not used before throws an error:
// myparser.is_option_set("foo"); // throws seqan3::design_error
return 0;
}
seqan3::argument_parser::is_option_set
bool is_option_set(id_type const &id) const
Checks whether the option identifier (id) was set on the command line by the user.
Definition argument_parser.hpp:476
// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
int myint;
seqan3::arithmetic_range_validator my_validator{2, 10};
myparser.add_option(myint, 'i', "integer", "Give me a number.", seqan3::option_spec::standard, my_validator);
// an exception will be thrown if the user specifies an integer
// that is not in range [2,10] (e.g. "./test_app -i 15")
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "integer given by user passed validation: " << myint << "\n";
return 0;
}
seqan3::arithmetic_range_validator
A validator that checks whether a number is inside a given range.
Definition validators.hpp:124
// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
int myint;
seqan3::value_list_validator my_validator{2, 4, 6, 8, 10};
myparser.add_option(myint, 'i', "integer", "Give me a number.", seqan3::option_spec::standard, my_validator);
// an exception will be thrown if the user specifies an integer
// that is not one of [2,4,6,8,10] (e.g. "./test_app -i 3")
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "integer given by user passed validation: " << myint << "\n";
return 0;
}
// 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 <filesystem>
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::filesystem::path myfile;
myparser.add_option(myfile,
'f',
"file",
"Give me a filename.",
seqan3::option_spec::standard,
seqan3::input_file_validator{{"fa", "fasta"}});
// an exception will be thrown if the user specifies a filename
// that does not have one of the extensions ["fa","fasta"],
// does not exists, or is not readable.
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "filename given by user passed validation: " << myfile << "\n";
return 0;
}
filesystem
// 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/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::string my_string;
seqan3::regex_validator my_validator{"[a-zA-Z]+@[a-zA-Z]+\\.com"};
myparser.add_option(my_string, 's', "str", "Give me a string.", seqan3::option_spec::standard, my_validator);
// an exception will be thrown if the user specifies a string
// that is no email address ending on .com
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "email address given by user passed validation: " << my_string << "\n";
return 0;
}
seqan3::regex_validator
A validator that checks if a matches a regular expression pattern.
Definition validators.hpp:931
// 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 <filesystem>
#include <seqan3/argument_parser/all.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::string file_name;
seqan3::regex_validator absolute_path_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"};
seqan3::input_file_validator my_file_ext_validator{{"sa", "so"}};
myparser.add_option(file_name,
'f',
"file",
"Give me a file name with an absolute path.",
seqan3::option_spec::standard,
absolute_path_validator | my_file_ext_validator);
// an exception will be thrown if the user specifies a file name
// that is not an absolute path or does not have one of the file extension [sa,so]
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
std::cout << "filename given by user passed validation: " << file_name << "\n";
return 0;
}
// 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 <filesystem>
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::filesystem::path mydir{};
myparser.add_option(mydir,
'd',
"dir",
"The directory containing the input files.",
seqan3::option_spec::standard,
seqan3::input_directory_validator{});
// an exception will be thrown if the user specifies a directory that does not exists or has insufficient
// read permissions.
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "directory given by user passed validation: " << mydir << "\n";
return 0;
}
seqan3::input_directory_validator
A validator that checks if a given path is a valid input directory.
Definition validators.hpp:766
// 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 <filesystem>
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::filesystem::path myfile{};
myparser.add_option(myfile,
'f',
"file",
"The input file containing the sequences.",
seqan3::option_spec::standard,
seqan3::input_file_validator{{"fa", "fasta"}});
// an exception will be thrown if the user specifies a filename
// that does not have one of the extensions ["fa","fasta"] or if the file does not exist/is not readable.
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "filename given by user passed validation: " << myfile << "\n";
return 0;
}
// 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/argument_parser/validators.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
int main()
{
// Default constructed validator has an empty extension list.
seqan3::input_file_validator validator1{};
seqan3::debug_stream << validator1.get_help_page_message() << '\n';
// Specify your own extensions for the input file.
seqan3::input_file_validator validator2{std::vector{std::string{"exe"}, std::string{"fasta"}}};
seqan3::debug_stream << validator2.get_help_page_message() << '\n';
// Give the seqan3 file type as a template argument to get all valid extensions for this file.
seqan3::input_file_validator<seqan3::sequence_file_input<>> validator3{};
seqan3::debug_stream << validator3.get_help_page_message() << '\n';
return 0;
}
seqan3::input_file_validator::get_help_page_message
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:602
validators.hpp
Provides some standard validators for (positional) options.
// 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 <filesystem>
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::filesystem::path mydir{};
myparser.add_option(mydir,
'd',
"dir",
"The output directory for storing the files.",
seqan3::option_spec::standard,
seqan3::output_directory_validator{});
// an exception will be thrown if the user specifies a directory that cannot be created by the filesystem either
// because the parent path does not exists or the path has insufficient write permissions.
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "directory given by user passed validation: " << mydir << "\n";
return 0;
}
seqan3::output_directory_validator
A validator that checks if a given path is a valid output directory.
Definition validators.hpp:842
// 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 <filesystem>
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::filesystem::path myfile{};
// Use the seqan3::output_file_open_options to indicate that you allow overwriting existing output files, ...
myparser.add_option(
myfile,
'f',
"file",
"Output file containing the processed sequences.",
seqan3::option_spec::standard,
seqan3::output_file_validator{seqan3::output_file_open_options::open_or_create, {"fa", "fasta"}});
// ... or that you will throw a seqan3::validation_error if the user specified output file already exists
myparser.add_option(myfile,
'g',
"file2",
"Output file containing the processed sequences.",
seqan3::option_spec::standard,
seqan3::output_file_validator{seqan3::output_file_open_options::create_new, {"fa", "fasta"}});
// an exception will be thrown if the user specifies a filename
// that does not have one of the extensions ["fa","fasta"],
// if the file already exists, or if the file is not writable.
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "filename given by user passed validation: " << myfile << "\n";
return 0;
}
seqan3::output_file_open_options::create_new
@ create_new
Forbid overwriting the output file.
Definition validators.hpp:614
seqan3::output_file_open_options::open_or_create
@ open_or_create
Allow to overwrite the output file.
Definition validators.hpp:612
// 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/argument_parser/validators.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
// Default constructed validator has an empty extension list.
seqan3::output_file_validator validator1{seqan3::output_file_open_options::create_new};
seqan3::debug_stream << validator1.get_help_page_message() << '\n';
// Specify your own extensions for the output file.
seqan3::output_file_validator validator2{seqan3::output_file_open_options::create_new,
std::vector{std::string{"exe"}, std::string{"fasta"}}};
seqan3::debug_stream << validator2.get_help_page_message() << '\n';
// Give the seqan3 file type as a template argument to get all valid extensions for this file.
seqan3::output_file_validator<seqan3::sequence_file_output<>> validator3{
seqan3::output_file_open_options::create_new};
seqan3::debug_stream << validator3.get_help_page_message() << '\n';
return 0;
}
seqan3::output_file_validator::get_help_page_message
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:735
// 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 <iostream>
#include <seqan3/core/add_enum_bitwise_operators.hpp>
enum class my_enum
{
VAL1 = 1,
VAL2 = 2,
COMB = 3
};
template <>
constexpr bool seqan3::add_enum_bitwise_operators<my_enum> = true;
int main()
{
using seqan3::operator|;
my_enum e = my_enum::VAL1;
my_enum e2 = e | my_enum::VAL2;
std::cout << std::boolalpha << (e2 == my_enum::COMB) << '\n'; // true
}
add_enum_bitwise_operators.hpp
Provides seqan3::add_enum_bitwise_operators.
// 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
#if SEQAN3_HAS_CEREAL
# include <fstream>
# include <vector>
# include <seqan3/core/debug_stream.hpp>
# include <seqan3/test/tmp_directory.hpp>
# include <cereal/archives/binary.hpp> // includes the cereal::BinaryInputArchive and cereal::BinaryOutputArchive
# include <cereal/types/vector.hpp> // includes cerealisation support for std::vector
// Written for std::vector, other types also work.
void load(std::vector<int16_t> & data, std::filesystem::path const & tmp_file)
{
std::ifstream is(tmp_file, std::ios::binary); // Where input can be found.
cereal::BinaryInputArchive archive(is); // Create an input archive from the input stream.
archive(data); // Load data.
}
// Written for std::vector, other types also work.
void store(std::vector<int16_t> const & data, std::filesystem::path const & tmp_file)
{
std::ofstream os(tmp_file, std::ios::binary); // Where output should be stored.
cereal::BinaryOutputArchive archive(os); // Create an output archive from the output stream.
archive(data); // Store data.
}
int main()
{
// The following example is for a std::vector but any seqan3 data structure that is documented as serialisable
// could be used, e.g. fm_index.
seqan3::test::tmp_directory tmp{};
auto tmp_file = tmp.path() / "data.out"; // this is a temporary file path, use any other filename.
std::vector<int16_t> vec{1, 2, 3, 4};
store(vec, tmp_file); // Calls store on a std::vector.
// This vector is needed to load the information into it.
std::vector<int16_t> vec2;
load(vec2, tmp_file); // Calls load on a std::vector.
seqan3::debug_stream << vec << '\n'; // Prints [1,2,3,4].
return 0;
}
#endif // SEQAN3_HAS_CEREAL
// 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/alignment/configuration/align_config_band.hpp>
#include <seqan3/alignment/configuration/align_config_method.hpp>
#include <seqan3/core/configuration/configuration.hpp>
#include <seqan3/core/configuration/pipeable_config_element.hpp>
int main()
{
// Here we use the global and banded alignment configurations to show how they can be combined.
seqan3::configuration my_cfg = seqan3::align_cfg::method_global{}
| seqan3::align_cfg::band_fixed_size{seqan3::align_cfg::lower_diagonal{-4},
seqan3::align_cfg::upper_diagonal{4}};
}
pipeable_config_element.hpp
Provides seqan3::pipeable_config_element.
// 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/core/configuration/configuration.hpp>
enum struct my_id : int
{
bar_id,
foo_id
};
namespace seqan3::detail
{
template <>
inline constexpr std::array<std::array<int, 2>, 2> compatibility_table<my_id>{{{0, 1}, {1, 0}}};
} // namespace seqan3::detail
std::array
// 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/alignment/configuration/align_config_band.hpp>
#include <seqan3/alignment/configuration/align_config_gap_cost_affine.hpp>
#include <seqan3/core/configuration/configuration.hpp>
#include <seqan3/core/configuration/pipeable_config_element.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using seqan3::get;
seqan3::configuration my_cfg =
seqan3::align_cfg::gap_cost_affine{seqan3::align_cfg::open_score{-10}, seqan3::align_cfg::extension_score{-1}}
| seqan3::align_cfg::band_fixed_size{seqan3::align_cfg::lower_diagonal{-4},
seqan3::align_cfg::upper_diagonal{4}};
// my_cfg is now of type configuration<gap_cost_affine, band_fixed_size>
seqan3::debug_stream << get<1>(my_cfg).lower_diagonal << '\n'; // prints -4
seqan3::debug_stream << get<seqan3::align_cfg::band_fixed_size>(my_cfg).upper_diagonal << '\n'; // prints 4
seqan3::debug_stream << get<seqan3::align_cfg::gap_cost_affine>(my_cfg).extension_score << '\n'; // prints -1
}
// 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/core/configuration/configuration.hpp>
#include <seqan3/core/configuration/pipeable_config_element.hpp>
#include <seqan3/core/debug_stream.hpp>
// Initial setup used in the actual example:
enum struct my_id : int
{
bar_id,
foo_id
};
struct bar : private seqan3::pipeable_config_element
{
public:
float value{};
bar() = default;
bar(bar const &) = default;
bar(bar &&) = default;
bar & operator=(bar const &) = default;
bar & operator=(bar &&) = default;
~bar() = default;
bar(float v) : value{v}
{}
static constexpr my_id id{my_id::bar_id};
};
template <typename t>
class foo : private seqan3::pipeable_config_element
{
public:
t value{};
foo() = default;
foo(foo const &) = default;
foo(foo &&) = default;
foo & operator=(foo const &) = default;
foo & operator=(foo &&) = default;
~foo() = default;
foo(t v) : value{std::move(v)}
{}
static constexpr my_id id{my_id::foo_id};
};
template <typename t>
foo(t) -> foo<t>;
int main()
{
seqan3::configuration my_cfg{foo{1}}; // Only foo<int> is present.
seqan3::debug_stream << my_cfg.get_or(foo{std::string{"hello"}}).value << '\n'; // finds foo<int> -> prints: 1
seqan3::debug_stream << my_cfg.get_or(bar{2.4}).value << '\n'; // bar not present -> prints: 2.4
}
seqan3::configuration::get_or
constexpr decltype(auto) get_or(alternative_t &&alternative) &noexcept
Returns the stored configuration element if present otherwise the given alternative.
Definition configuration.hpp:117
seqan3::pipeable_config_element
Adds pipe interface to configuration elements.
Definition pipeable_config_element.hpp:29
// 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/core/configuration/configuration.hpp>
#include <seqan3/core/configuration/pipeable_config_element.hpp>
enum struct my_id : int
{
bar_id,
foo_id
};
class bar : private seqan3::pipeable_config_element
{
public:
bar() = default;
bar(bar const &) = default;
bar(bar &&) = default;
bar & operator=(bar const &) = default;
bar & operator=(bar &&) = default;
~bar() = default;
static constexpr my_id id{my_id::bar_id};
};
template <typename t>
struct foo : private seqan3::pipeable_config_element
{
public:
foo() = default;
foo(foo const &) = default;
foo(foo &&) = default;
foo & operator=(foo const &) = default;
foo & operator=(foo &&) = default;
~foo() = default;
static constexpr my_id id{my_id::foo_id};
};
template <typename t>
foo(t) -> foo<t>;
// 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/core/debug_stream.hpp>
int main()
{
uint8_t i = 71;
seqan3::debug_stream << '\'' << i << "'\n"; // prints '71' (because flag is set by default)
seqan3::debug_stream.unsetf(seqan3::fmtflags2::small_int_as_number); // unsets the flag
seqan3::debug_stream << '\'' << i << "'\n"; // prints 'G'
seqan3::debug_stream << seqan3::fmtflags2::small_int_as_number << '\'' << i << "'\n"; // prints '71' again
// instead of formatting the stream "inline", one can also call .setf()
}
seqan3::fmtflags2::small_int_as_number
@ small_int_as_number
Definition debug_stream_type.hpp:35
// 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 <sstream>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
std::ostringstream o;
seqan3::debug_stream.set_underlying_stream(o);
seqan3::debug_stream << "ACGT"_dna5;
o.flush();
seqan3::debug_stream << o.str(); // prints the string stream's buffer: "ACGT"
}
std::ostringstream
std::ostringstream::flush
T flush(T... args)
std::ostringstream::str
T str(T... args)
// 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 <sstream>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
std::ostringstream o;
seqan3::debug_stream_type my_stream{o};
my_stream << "ACGT"_dna5;
o.flush();
seqan3::debug_stream << o.str() << '\n'; // prints the string stream's buffer: "ACGT"
}
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
// 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 <iostream>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/views/to_rank.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
// The alphabet normally needs to be converted to char explicitly:
std::cout << seqan3::to_char('C'_dna5) << '\n'; // prints 'C'
// The debug_stream, on the other hand, does this automatically:
seqan3::debug_stream << 'C'_dna5 << '\n'; // prints 'C'
// The debug_stream can also print all types that model std::ranges::input_range:
std::vector<seqan3::dna5> vec{"ACGT"_dna5};
seqan3::debug_stream << vec << '\n'; // prints "ACGT"
// ranges of non-alphabets are printed comma-separated:
seqan3::debug_stream << (vec | seqan3::views::to_rank) << '\n'; // prints "[0,1,2,3]"
}
// 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 <concepts>
#include <vector>
#include <seqan3/core/detail/customisation_point.hpp>
namespace seqan3::detail::adl_only
{
// Poison-pill overload to prevent non-ADL forms of unqualified lookup.
template <typename... args_t>
void begin(args_t...) = delete;
struct begin_cpo : public detail::customisation_point_object<begin_cpo, 1>
{
using base_t = detail::customisation_point_object<begin_cpo, 1>;
// Only this class is allowed to import the constructors from base_t. (CRTP safety idiom)
using base_t::base_t;
// range.begin(), member access
template <typename range_t>
requires true // further constraints
static constexpr auto SEQAN3_CPO_OVERLOAD(seqan3::detail::priority_tag<1>, range_t && range)(
/*return*/ std::forward<range_t>(range).begin() /*;*/
);
// begin(range), ADL access
template <typename range_t>
static constexpr auto SEQAN3_CPO_OVERLOAD(seqan3::detail::priority_tag<0>, range_t && range)(
/*return*/ begin(std::forward<range_t>(range)) /*;*/
);
};
} // namespace seqan3::detail::adl_only
namespace seqan3
{
// CPO is a normal function object that can be called via seqan3::begin(...)
inline constexpr auto begin = detail::adl_only::begin_cpo{};
} // namespace seqan3
namespace other_library
{
struct foo
{
friend int begin(foo const &) // ADL begin, as friend
{
return 0;
}
};
} // namespace other_library
// seqan3::begin CPO that will call the "begin" member function
std::vector<int> vec{};
static_assert(std::same_as<decltype(seqan3::begin(vec)), decltype(vec.begin())>); // same iterator type
static_assert(noexcept(vec.begin())); // is noexcept
static_assert(noexcept(seqan3::begin(vec)) == noexcept(vec.begin())); // perfect noexcept-forwarding
// seqan3::begin CPO that will call the "begin" function per ADL
other_library::foo foo{};
static_assert(std::same_as<decltype(seqan3::begin(foo)), decltype(begin(foo))>); // same value type
static_assert(!noexcept(begin(foo))); // isn't noexcept
static_assert(noexcept(seqan3::begin(foo)) == noexcept(begin(foo))); // perfect noexcept-forwarding
auto cpo_is_sfinae_friendly(...) -> void;
template <typename range_t>
auto cpo_is_sfinae_friendly(range_t && range) -> decltype(seqan3::begin(range));
// seqan3::begin itself is SFINAE friendly, i.e. no-hard compiler errors, if no cpo overload matches
static_assert(std::same_as<decltype(cpo_is_sfinae_friendly(0)), void>);
static_assert(std::same_as<decltype(cpo_is_sfinae_friendly(vec)), decltype(vec.begin())>);
std::begin
T begin(T... args)
customisation_point.hpp
Helper utilities for defining customisation point objects (CPOs).
SEQAN3_CPO_OVERLOAD
#define SEQAN3_CPO_OVERLOAD(...)
A macro that helps to define a seqan3::detail::customisation_point_object.
Definition customisation_point.hpp:106
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
// 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 <string>
#include <type_traits>
#include <seqan3/core/detail/deferred_crtp_base.hpp>
// Defines a crtp_base class with an additional value type.
template <typename derived_t, int value>
class base1
{
public:
int func1() const
{
return value;
}
};
// Defines a crtp_base class with an additional value type and a parameter type.
template <typename derived_t, typename value_t, typename parameter_t>
class base2
{
public:
value_t func2(parameter_t const p) const
{
return static_cast<value_t>(p);
}
};
// The derived class that inherits from a variadic crtp pattern, which are augmented with additional trait types.
// These types must be wrapped in a deferred layer, otherwise the compilation fails as incomplete types are not allowed.
// But during the definition of the base classes, the derived class cannot be known.
// In addition the deferred type must be invoked with the derived class using the `invoke_deferred_crtp_base` helper
// template to instantiate the correct crtp base type.
// Note that it is possible to define base classes with type template parameters (see base2) or
// non-type template parameters (see base1), but non-type and type template parameters cannot be mixed in one
// base class definition.
template <typename... deferred_bases_t>
class derived : public seqan3::detail::invoke_deferred_crtp_base<deferred_bases_t, derived<deferred_bases_t...>>...
{};
int main()
{
// Define deferred base with non-type template parameter
using deferred_base1 = seqan3::detail::deferred_crtp_base_vargs<base1, 10>;
// Define deferred base with type template parameter.
using deferred_base2 = seqan3::detail::deferred_crtp_base<base2, uint8_t, uint32_t>;
// Instantiate the derived class with the deferred crtp base classes.
derived<deferred_base1, deferred_base2> d{};
// Check the inherited interfaces.
static_assert(std::is_same_v<decltype(d.func1()), int>, "Return type must be int");
static_assert(std::is_same_v<decltype(d.func2(10u)), uint8_t>, "Return type must be uint8_t");
}
deferred_crtp_base.hpp
Provides seqan3::detail::deferred_crtp_base.
std::is_same_v
T is_same_v
type_traits
// 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 <type_traits>
#include <seqan3/alignment/aligned_sequence/aligned_sequence_concept.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/core/detail/is_class_template_declarable.hpp>
template <typename t>
requires std::is_integral_v<t>
struct foo
{
t value;
};
// foo is declarable with int, i.e. foo<int> is a valid expression
static_assert(seqan3::detail::is_class_template_declarable_with_v<foo, int>);
// foo is not declarable with double, because it does not fulfil the requires clause of foo.
static_assert(!seqan3::detail::is_class_template_declarable_with_v<foo, double>);
// This also works with std::enable_if and producing a substitution failure.
template <typename t, typename = std::enable_if_t<std::is_same_v<t, int>>>
struct bar
{
t value;
};
// bar is declarable with int, i.e. bar<int> is a valid expression
static_assert(seqan3::detail::is_class_template_declarable_with_v<bar, int>);
// bar is not declarable with double, because it produces an substitution failure (SFINAE).
static_assert(!seqan3::detail::is_class_template_declarable_with_v<bar, double>);
// is_class_template_declarable_with_v works well with lazy_conditional_t
template <typename t>
using maybe_foo_t = seqan3::detail::
lazy_conditional_t<seqan3::detail::is_class_template_declarable_with_v<foo, t>, seqan3::detail::lazy<foo, t>, t>;
int main()
{
foo<int> a = maybe_foo_t<int>{10}; // foo is instantiable with int, thus use foo<int>
seqan3::debug_stream << "a: " << a.value << '\n'; // prints 10
float b = maybe_foo_t<float>{0.4f}; // foo is not instantiable with float, thus use float directly
seqan3::debug_stream << "b: " << b << '\n'; // prints 0.4
return 0;
}
is_class_template_declarable.hpp
Provides a type trait for verifying valid template declarations.
std::is_integral_v
T is_integral_v
// 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/core/detail/strong_type.hpp>
using seqan3::operator|;
struct error :
seqan3::detail::strong_type<uint8_t,
error,
seqan3::detail::strong_type_skill::decrement
| seqan3::detail::strong_type_skill::increment>
{
using seqan3::detail::strong_type<uint8_t,
error,
seqan3::detail::strong_type_skill::decrement
| seqan3::detail::strong_type_skill::increment>::strong_type;
};
int main()
{
error e{4u};
--e;
++e;
}
strong_type.hpp
Provides basic data structure for strong types.
// 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/core/detail/strong_type.hpp>
struct error : seqan3::detail::strong_type<uint8_t, error>
{
using seqan3::detail::strong_type<uint8_t, error>::strong_type;
};
struct window_size : seqan3::detail::strong_type<uint8_t, window_size>
{
using seqan3::detail::strong_type<uint8_t, window_size>::strong_type;
};
seqan3::window_size
strong_type for the window_size.
Definition minimiser_hash.hpp:29
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/detail/strong_type.hpp>
struct error : seqan3::detail::strong_type<unsigned, error>
{
using seqan3::detail::strong_type<unsigned, error>::strong_type;
};
struct window_size : seqan3::detail::strong_type<unsigned, window_size>
{
using seqan3::detail::strong_type<unsigned, window_size>::strong_type;
};
namespace detail
{
template <std::ranges::forward_range fwd_rng_type>
bool do_find(fwd_rng_type const &, uint8_t const, uint8_t const)
{
return true;
}
} // namespace detail
template <std::ranges::forward_range fwd_rng_type>
bool search(fwd_rng_type const & rng, window_size const window_size, error const error)
{
return detail::do_find(rng, window_size.get(), error.get());
}
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> range = "ACGTT"_dna4;
search(range, window_size{4u}, error{2u});
return 0;
}
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
namespace detail
{
template <std::ranges::forward_range fwd_rng_type>
bool do_find(fwd_rng_type const &, uint8_t const, uint8_t const)
{
return true;
}
} // namespace detail
template <std::ranges::forward_range fwd_rng_type>
bool search(fwd_rng_type const & rng, uint8_t const window_size, uint8_t const error)
{
return detail::do_find(rng, window_size, error);
}
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> range = "ACGTT"_dna4;
search(range, 4u, 2u);
return 0;
}
// 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 <tuple>
#include <seqan3/core/detail/template_inspection.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
int main()
{
using list_to_transfer = seqan3::type_list<int, char, double>;
using resulting_t = seqan3::detail::transfer_template_args_onto_t<list_to_transfer, std::tuple>;
static_assert(std::same_as<resulting_t, std::tuple<int, char, double>>);
}
template_inspection.hpp
Provides type traits for working with templates.
tuple
type_list.hpp
Provides seqan3::type_list.
// 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 <vector>
#include <seqan3/core/detail/template_inspection.hpp>
int main()
{
using my_type = std::vector<int>;
if constexpr (seqan3::detail::is_type_specialisation_of_v<my_type, std::vector>) // Note: std::vector has no <> !
{
// ...
}
}
// 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 <vector>
#include <seqan3/core/detail/template_inspection.hpp>
int main()
{
using my_type = std::vector<int>;
if constexpr (seqan3::detail::template_specialisation_of<my_type, std::vector>) // Note: std::vector has no <> !
{
// ...
}
}
// 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 <string>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/io/detail/record.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
int main()
{
using types = seqan3::type_list<std::string, seqan3::dna4_vector, std::vector<seqan3::phred42>>;
using types_as_ids = seqan3::fields<seqan3::field::id, seqan3::field::seq, seqan3::field::qual>;
using selected_ids = seqan3::fields<seqan3::field::qual, seqan3::field::id>;
using selected_types = seqan3::detail::select_types_with_ids_t<types, types_as_ids, selected_ids>;
// resolves to type_list<std::vector<phred42>, std::string>
static_assert(std::same_as<selected_types, seqan3::type_list<std::vector<seqan3::phred42>, std::string>>);
}
// 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 <sstream>
#include <seqan3/io/stream/detail/fast_ostreambuf_iterator.hpp>
int main()
{
std::string id{"seq1"};
std::string sequence{"ACTGACTGACTGACTAGCATGACTAGCATGC"};
// construct iterator from stream buffer
std::ostringstream ostr{};
auto stream_it = seqan3::detail::fast_ostreambuf_iterator{*ostr.rdbuf()};
// You can do anything you could do with a regular std::ostreambuf_iterator
stream_it = '>'; // writes '>' to stream
*stream_it = ' '; // writes ' ' to stream
// Additionally, there is an efficient write_range member function
// Example 1: Write a range completely
stream_it.write_range(id); // return value can be ignored
// Example 2: Write a range in chunks of 10
auto it = std::ranges::begin(sequence);
while (it != std::ranges::end(sequence))
{
/* Note that you need cannot use stream_it.write_range(rng | std::views::take(10)) here
* because the returned iterator is not of the correct type.
*/
auto current_end = it;
size_t steps = std::ranges::advance(current_end, 10u, std::ranges::end(sequence));
using subrange_t =
std::ranges::subrange<decltype(it), decltype(current_end), std::ranges::subrange_kind::sized>;
// Be aware that your range_type must model std::ranges::borrowed_range in order to use the return value!
it = stream_it.write_range(subrange_t{it, current_end, 10u - steps});
stream_it = ' ';
}
}
fast_ostreambuf_iterator.hpp
Provides seqan3::detail::fast_ostreambuf_iterator.
std::ostringstream::rdbuf
T rdbuf(T... args)
// 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 <filesystem>
#include <fstream>
#include <seqan3/io/detail/safe_filesystem_entry.hpp>
int main()
{
std::filesystem::path my_file = std::filesystem::temp_directory_path() / "dummy.txt";
std::ifstream file{my_file}; // Create the file.
seqan3::detail::safe_filesystem_entry file_guard{my_file}; // Safe cleanup in case of errors.
// Do something on the file, that can possibly throw.
// If an unhandled exception is thrown, the file guard destructor safely removes the file from the filesystem.
file_guard.remove(); // Explicitly remove the file.
}
safe_filesystem_entry.hpp
Provides seqan3::detail::safe_filesystem_entry.
std::filesystem::temp_directory_path
T temp_directory_path(T... args)
// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/record.hpp>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/io/sequence_file/output.hpp>
auto input = R"(> TEST1
ACGT
> Test2
AGGCTGA
> Test3
GGAGTATAATATATATATATATAT)";
int main()
{
// specify custom field combination/order to file:
seqan3::sequence_file_input fin{std::istringstream{input},
seqan3::format_fasta{},
seqan3::fields<seqan3::field::id, seqan3::field::seq>{}};
auto record = fin.front(); // get current record, in this case the first
auto & id = record.id();
seqan3::debug_stream << id << '\n'; // TEST1
auto & seq = record.sequence();
seqan3::debug_stream << seq << '\n'; // ACGT
}
seqan3::sequence_file_input::front
reference front() noexcept
Return the record we are currently at in the file.
Definition sequence_file/input.hpp:463
seqan3::field::seq
@ seq
The "sequence", usually a range of nucleotides or amino acids.
Definition record.hpp:62
record.hpp
Provides the seqan3::record template and the seqan3::field enum.
// 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 <string>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/io/record.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
int main()
{
using namespace seqan3::literals;
// The order of the types below represent a mapping between the type and the key.
using types = seqan3::type_list<seqan3::dna4_vector, std::string, std::vector<seqan3::phred42>>;
using types_as_ids = seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::qual>;
using record_type = seqan3::record<types, types_as_ids>;
// record_type now mimics std::tuple<std::string, dna4_vector, std::vector<phred42>>,
// the order also depends on selected_ids
record_type my_record{};
std::get<1>(my_record) = "the most important sequence in the database"; // access via index
std::get<std::string>(my_record) = "the least important sequence in the database"; // access via type
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
auto stream_it = fout.begin();
std::string id;
seqan3::dna5_vector seq;
// ...
// assign to file iterator
*stream_it = std::tie(seq, id);
// is the same as:
fout.push_back(std::tie(seq, id));
}
seqan3::sam_file_output
A class for writing SAM files, both SAM and its binary representation BAM are supported.
Definition io/sam_file/output.hpp:71
seqan3::sam_file_output::begin
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition io/sam_file/output.hpp:366
seqan3::sam_file_output::push_back
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition io/sam_file/output.hpp:409
seqan3::field::id
@ id
The identifier, usually a string.
Definition record.hpp:63
output.hpp
Provides seqan3::sam_file_output and corresponding traits classes.
// 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 <sstream>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
// I only want to print the mapping position (field::ref_offset) and flag:
seqan3::sam_file_output fout{std::ostringstream{},
seqan3::format_sam{},
seqan3::fields<seqan3::field::ref_offset, seqan3::field::flag>{}};
unsigned mapping_pos{1300};
seqan3::sam_flag flag{seqan3::sam_flag::none};
// ...
fout.emplace_back(mapping_pos, flag); // note that the order the arguments is now different, because
// or: you specified that REF_OFFSET should be first
fout.push_back(std::tie(mapping_pos, flag));
}
seqan3::sam_file_output::emplace_back
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition io/sam_file/output.hpp:499
seqan3::sam_flag
sam_flag
An enum flag that describes the properties of an aligned read (given as a SAM record).
Definition sam_flag.hpp:73
seqan3::sam_flag::none
@ none
None of the flags below are set.
Definition sam_flag.hpp:74
// 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 <sstream>
#include <string>
#include <seqan3/io/sam_file/output.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
int main()
{
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
seqan3::record<seqan3::type_list<uint32_t, std::string>, seqan3::fields<seqan3::field::mapq, seqan3::field::id>> r;
// ...
fout.push_back(r);
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
std::string id;
seqan3::dna5_vector seq;
// ...
fout.push_back(std::tie(seq, id));
}
// 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 <sstream>
#include <string>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sam_file/output.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
int main()
{
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
std::string ref_id;
std::string read_id;
std::vector<seqan3::dna5> read;
// ... e.g. compute and alignment
using alignment_type =
std::pair<std::vector<seqan3::gapped<seqan3::dna5>>, std::vector<seqan3::gapped<seqan3::dna5>>>;
alignment_type dummy_alignment{}; // an empty dummy alignment
using types = seqan3::type_list<std::vector<seqan3::dna5>, std::string, alignment_type>;
using types_as_ids = seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::alignment>;
// the record type specifies the fields we want to write
using record_type = seqan3::record<types, types_as_ids>;
// initialize record
record_type rec{read, ref_id, dummy_alignment};
// Write the record
fout.push_back(rec);
// same as
fout.push_back(record_type{read, ref_id, dummy_alignment});
// as all our fields are empty so this would print an
}
seqan3::field::ref_id
@ ref_id
The identifier of the (reference) sequence that seqan3::field::seq was aligned to.
Definition record.hpp:79
// 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 <filesystem>
#include <sstream>
#include <tuple>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
// I only want to print the mapping position (field::ref_offset) and flag:
seqan3::sam_file_output fout{std::ostringstream{},
seqan3::format_sam{},
seqan3::fields<seqan3::field::ref_offset, seqan3::field::flag>{}};
unsigned mapping_pos{1300};
seqan3::sam_flag flag{seqan3::sam_flag::none};
// ...
fout.emplace_back(mapping_pos, flag); // note that the order the arguments is now different, because
// or: you specified that REF_OFFSET should be first
fout.push_back(std::tie(mapping_pos, flag));
}
// 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 <sstream>
#include <seqan3/io/sam_file/input.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
auto it = fin.begin();
// the following are equivalent:
auto & rec0 = *it;
auto & rec1 = fin.front();
std::cout << std::boolalpha << (rec0.id() == rec1.id()) << '\n'; // true
// Note: both become invalid after incrementing "it"!
}
seqan3::sam_file_input::begin
iterator begin()
Returns an iterator to current position in the file.
Definition sam_file/input.hpp:619
seqan3::sam_file_input::front
reference front() noexcept
Return the record we are currently at in the file.
Definition sam_file/input.hpp:672
input.hpp
Provides seqan3::sam_file_input and corresponding traits classes.
// 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 <filesystem>
#include <sstream>
#include <seqan3/io/sam_file/input.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
// Create the temporary file.
auto tmp_file = std::filesystem::temp_directory_path() / "my.sam";
std::ofstream tmp_stream{tmp_file};
tmp_stream << sam_file_raw;
tmp_stream.close();
seqan3::sam_file_input fin{tmp_file}; // SAM format assumed, regular std::ifstream taken as stream
std::filesystem::remove(tmp_file);
}
std::ofstream::close
T close(T... args)
std::filesystem::remove
T remove(T... args)
// 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 <sstream>
#include <seqan3/io/sam_file/input.hpp>
auto input = R"(@HD VN:1.6 SO:coordinate
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{input}, seqan3::format_sam{}};
// ^ no need to specify the template arguments
}
// 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 <sstream>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto input = R"(@HD VN:1.6 SO:coordinate
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *)";
int main()
{
// The default types; you can adjust this list if you don't want to read all this data.
using default_fields = seqan3::fields<seqan3::field::seq,
seqan3::field::id,
seqan3::field::ref_id,
seqan3::field::ref_offset,
seqan3::field::cigar,
seqan3::field::mapq,
seqan3::field::qual,
seqan3::field::flag,
seqan3::field::mate,
seqan3::field::tags,
seqan3::field::header_ptr>;
// The expected format:
using sam_file_input_t = seqan3::sam_file_input<seqan3::sam_file_input_default_traits<>,
default_fields,
// Which formats are allowed:
seqan3::type_list<seqan3::format_sam>>;
sam_file_input_t fin{std::istringstream{input}, seqan3::format_sam{}};
}
seqan3::field::ref_offset
@ ref_offset
Sequence (seqan3::field::ref_seq) relative start position (0-based), unsigned value.
Definition record.hpp:81
seqan3::field::cigar
@ cigar
The cigar vector (std::vector<seqan3::cigar>) representing the alignment in SAM/BAM format.
Definition record.hpp:87
seqan3::field::mapq
@ mapq
The mapping quality of the seqan3::field::seq alignment, usually a Phred-scaled score.
Definition record.hpp:86
seqan3::field::mate
@ mate
The mate pair information given as a std::tuple of reference name, offset and template length.
Definition record.hpp:85
seqan3::field::header_ptr
@ header_ptr
A pointer to the seqan3::sam_file_header object storing header information.
Definition record.hpp:82
seqan3::field::tags
@ tags
The optional tags in the SAM format, stored in a dictionary.
Definition record.hpp:88
seqan3::field::qual
@ qual
The qualities, usually in Phred score notation.
Definition record.hpp:64
// 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 <sstream>
#include <seqan3/io/sam_file/input.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
auto rec = std::move(fin.front()); // rec now stores the data permanently
}
// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
// access the header information
seqan3::debug_stream << fin.header().format_version << '\n'; // 1.6
seqan3::debug_stream << fin.header().ref_dict << '\n'; // [(ref,(45,))] (this only works with seqan3::debug_stream!)
}
seqan3::sam_file_header::ref_dict
std::unordered_map< key_type, int32_t, key_hasher, detail::view_equality_fn > ref_dict
The mapping of reference id to position in the ref_ids() range and the ref_id_info range.
Definition header.hpp:163
seqan3::sam_file_header::format_version
std::string format_version
The file format version. Note: this is overwritten by our formats on output.
Definition header.hpp:68
seqan3::sam_file_input::header
header_type & header()
Access the file's header.
Definition sam_file/input.hpp:693
// 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 <sstream>
#include <seqan3/alphabet/container/bitpacked_sequence.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
struct my_traits : seqan3::sam_file_input_default_traits<>
{
using sequence_alphabet = seqan3::dna4; // instead of dna5
template <typename alph>
using sequence_container = seqan3::bitpacked_sequence<alph>; // must be defined as a template!
};
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
// ... within main you can then use:
int main()
{
seqan3::sam_file_input<my_traits> fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
}
sequence_container
A more refined container concept than seqan3::container.
seqan3::sam_file_input_default_traits
The default traits for seqan3::sam_file_input.
Definition sam_file/input.hpp:168
// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw},
seqan3::format_sam{},
seqan3::fields<seqan3::field::flag, seqan3::field::mapq>{}};
for (auto & rec : fin)
{
seqan3::debug_stream << "flag: " << rec.flag() << '\n';
seqan3::debug_stream << "mapping quality: " << rec.mapping_quality() << '\n';
}
}
// 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 <ranges>
#include <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
auto minimum_length10_filter = std::views::filter(
[](auto const & rec)
{
return std::ranges::size(rec.sequence()) >= 10;
});
for (auto & rec : fin | minimum_length10_filter) // only records with sequence length >= 10 will "appear"
seqan3::debug_stream << rec.id() << '\n';
}
// 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 <sstream>
#include <utility>
#include <vector>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
using record_type = typename decltype(fin)::record_type;
std::vector<record_type> records{}; // store all my records in a vector
for (auto & rec : fin)
records.push_back(std::move(rec));
}
// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
for (auto & rec : fin)
{
seqan3::debug_stream << "id: " << rec.id() << '\n';
seqan3::debug_stream << "read sequence: " << rec.sequence() << '\n';
seqan3::debug_stream << "mapping position: " << rec.reference_position() << '\n';
seqan3::debug_stream << "mapping quality: " << rec.mapping_quality() << '\n';
// there are more fields read on default
}
}
// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw},
seqan3::format_sam{},
seqan3::fields<seqan3::field::flag, seqan3::field::mapq>{}};
for (auto & [flag, mapq] : fin) // the order is the same as specified in fields!
{
seqan3::debug_stream << "flag: " << flag << '\n';
seqan3::debug_stream << "mapping quality: " << mapq << '\n';
}
}
// 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 <iostream>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
seqan3::sam_file_output fout{std::cout, seqan3::format_sam{}};
}
// 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 <filesystem>
#include <sstream>
#include <seqan3/io/sam_file/all.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 6H5M * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
// fin uses custom fields, fout uses the default fields.
seqan3::sam_file_input fin{std::istringstream{sam_file_raw},
seqan3::format_sam{},
seqan3::fields<seqan3::field::ref_offset, seqan3::field::flag>{}};
// output doesn't have to match the configuration of the input
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
for (auto & r : fin)
fout.push_back(r); // copy all the records.
}
// 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 <filesystem>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
auto tmp_file = std::filesystem::temp_directory_path() / "my.sam";
seqan3::sam_file_output fout{tmp_file}; // SAM format detected, std::ofstream opened for file
std::filesystem::remove(tmp_file);
}
// 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 <filesystem>
#include <string>
#include <vector>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
auto tmp_file = std::filesystem::temp_directory_path() / "my.sam";
std::vector<std::string> ref_ids{"ref1", "ref2"};
std::vector<size_t> ref_lengths{1234, 5678};
seqan3::sam_file_output fout{tmp_file, ref_ids, ref_lengths};
std::filesystem::remove(tmp_file);
}
// 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 <sstream>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
// no need to specify the template arguments <...> for format specialization:
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}, seqan3::fields<seqan3::field::mapq>{}};
}
// 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 <sstream>
#include <seqan3/io/sam_file/all.hpp>
auto sam_file_raw = R"(First 0 * 0 0 * * 0 0 ACGT *
2nd 0 * 0 0 * * 0 0 NATA *
Third 0 * 0 0 * * 0 0 GATA *
)";
int main()
{
// copying a file in one line:
seqan3::sam_file_output{std::ostringstream{}, seqan3::format_sam{}} =
seqan3::sam_file_input{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
// with seqan3::sam_file_output as a variable:
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
fout = fin;
// or in pipe notation:
seqan3::sam_file_input{std::istringstream{sam_file_raw}, seqan3::format_sam{}}
| seqan3::sam_file_output{std::ostringstream{}, seqan3::format_sam{}};
}
// 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/core/platform.hpp>
#include <ranges>
#include <sstream>
#include <seqan3/io/sam_file/all.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 * = 37 39 TTAGATAAAGGATACTG *
r003 0 ref 29 30 * * 0 0 GCCTAAGCTAA * SA:Z:ref,29,-,6H5M,17,0;
r003 2064 ref 29 17 * * 0 0 TAGGC * SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 * = 7 -39 CAGCGGCAT * NM:i:1
)";
int main()
{
auto input_file = seqan3::sam_file_input{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
input_file | std::views::take(3) // take only the first 3 records
| seqan3::sam_file_output{std::ostringstream{}, seqan3::format_sam{}};
}
platform.hpp
Provides platform and dependency checks.
// 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 <sstream>
#include <string>
#include <vector>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
std::vector<std::string> ref_ids{"ref1", "ref2"};
std::vector<size_t> ref_lengths{1234, 5678};
// always give reference information if you want to have your header properly initialised
seqan3::sam_file_output fout{std::ostringstream{}, ref_ids, ref_lengths, seqan3::format_sam{}};
// add information to the header of the file.
fout.header().comments.push_back("This is a comment");
}
seqan3::sam_file_output::header
auto & header()
Access the file's header.
Definition io/sam_file/output.hpp:602
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sam_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sam_file_output fout{std::ostringstream{}, seqan3::format_sam{}};
std::vector<std::tuple<seqan3::dna5_vector, std::string>> range{{"ACGT"_dna5, "First"},
{"NATA"_dna5, "2nd"},
{"GATA"_dna5, "Third"}}; // a range of "records"
fout = range; // will iterate over the records and write them
// equivalent to:
range | fout;
}
// 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 <iostream>
#include <sstream>
#include <seqan3/io/sam_file/all.hpp>
auto sam_file_raw = R"(@HD VN:1.6 SO:coordinate GO:none
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG !!!!!!!!!!!!!!!!!
r003 0 ref 29 30 5S6M * 0 0 GCCTAAGCTAA !!!!!!!!!!! SA:Z:ref,29,-,6H5M,17,0;
r003 4 * 29 17 * * 0 0 TAGGC @@@@@ SA:Z:ref,9,+,5S6M,30,1;
r001 147 ref 237 30 9M = 7 -39 CAGCGGCAT !!!!!!!!! NM:i:1
)";
int main()
{
seqan3::sam_file_input fin{std::istringstream{sam_file_raw}, seqan3::format_sam{}};
for (auto & rec : fin)
{
// Check if a certain flag value (bit) is set:
if (static_cast<bool>(rec.flag() & seqan3::sam_flag::unmapped))
std::cout << "Read " << rec.id() << " is unmapped\n";
if (rec.base_qualities()[0] < seqan3::assign_char_to('@', seqan3::phred42{})) // low quality
{
// Set a flag value (bit):
rec.flag() |= seqan3::sam_flag::failed_filter;
// Note that this does not affect other flag values (bits),
// e.g. `rec.flag() & seqan3::sam_flag::unmapped` may still be true
}
// Unset a flag value (bit):
rec.flag() &= ~seqan3::sam_flag::duplicate; // not marked as a duplicate anymore
}
}
seqan3::sam_flag::duplicate
@ duplicate
The read is marked as a PCR duplicate or optical duplicate.
Definition sam_flag.hpp:85
seqan3::sam_flag::failed_filter
@ failed_filter
The read alignment failed a filter, e.g. quality controls.
Definition sam_flag.hpp:84
seqan3::sam_flag::unmapped
@ unmapped
The read is not mapped to a reference (unaligned).
Definition sam_flag.hpp:77
// 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/core/debug_stream.hpp>
#include <seqan3/io/sam_file/sam_tag_dictionary.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sam_tag_dictionary dict{}; // initialise empty dictionary
dict.get<"NM"_tag>() = 3; // set SAM tag 'NM' to 3 (integer type)
dict.get<"CO"_tag>() = "comment"; // set SAM tag 'CO' to "comment" (string type)
auto nm = dict.get<"NM"_tag>(); // get SAM tag 'NM' (note: type is int32_t)
auto co = dict.get<"CO"_tag>(); // get SAM tag 'CO' (note: type is std::string)
seqan3::debug_stream << nm << '\n'; // will print '3'
seqan3::debug_stream << co << '\n'; // will print "comment"
}
seqan3::sam_tag_dictionary
The SAM tag dictionary class that stores all optional SAM fields.
Definition sam_tag_dictionary.hpp:327
seqan3::sam_tag_dictionary::get
auto & get() &
Uses std::map::operator[] for access and default initializes new keys.
Definition sam_tag_dictionary.hpp:354
sam_tag_dictionary.hpp
Provides the seqan3::sam_tag_dictionary class and auxiliaries.
// 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/io/sam_file/sam_tag_dictionary.hpp>
using namespace seqan3::literals;
template <> // no template parameter since the tag is known
struct seqan3::sam_tag_type<"XX"_tag> // here comes your tag
{
using type = int32_t; // specify the type of your tag
};
#include <seqan3/io/sam_file/sam_tag_dictionary.hpp>
using namespace seqan3::literals;
// ...
uint16_t tag_id = "NM"_tag; // tag_id = 10061
#include <seqan3/io/sam_file/sam_tag_dictionary.hpp>
using namespace seqan3::literals;
// ...
using nm_tag_type = seqan3::sam_tag_type_t<"NM"_tag>;
#include <seqan3/io/sam_file/sam_tag_dictionary.hpp>
using namespace seqan3::literals;
// ...
using nm_tag_type2 = seqan3::sam_tag_type<"NM"_tag>::type;
seqan3::sam_tag_type
The generic base class.
Definition sam_tag_dictionary.hpp:165
seqan3::sam_tag_type::type
detail::sam_tag_variant type
The type for all unknown tags with no extra overload defaults to a std::variant.
Definition sam_tag_dictionary.hpp:167
// 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 <variant> // for std::visit
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sam_file/sam_tag_dictionary.hpp>
#include <seqan3/utility/container/concept.hpp> // for the seqan3::container
// a lambda helper function that prints every type in the std::variant<...allowed SAM tag types...>
auto print_fn = [](auto && arg)
{
using T = std::remove_cvref_t<decltype(arg)>; // the type T of arg.
if constexpr (!seqan3::container<T>) // If T is not a container,
{
seqan3::debug_stream << arg << '\n'; // just print arg directly.
}
else // If T is a container,
{
for (auto const & arg_v : arg) // print every value in arg.
seqan3::debug_stream << arg_v << ",";
seqan3::debug_stream << '\n';
}
};
int main()
{
using namespace seqan3::literals;
seqan3::sam_tag_dictionary dict{}; // initialise empty dictionary
// ! there is no get function for unknown tags !
// dict.get<"XZ"_tag>() = 3;
// but you can use the operator[]
dict["XZ"_tag] = 3; // set unknown SAM tag 'XZ' to 3 (type int32_t)
// ! there is no get function for unknown tags !
// auto nm = dict.get<"XZ"_tag>();
// but you can use the operator[] again
auto xz = dict["XZ"_tag]; // get SAM tag 'XZ' (type std::variant<...allowed SAM tag types...>)
// ! you cannot print a std::variant directly !
// seqan3::debug_stream << nm << '\n';
// but you can use visit:
std::visit(print_fn, xz); // prints 3
}
concept.hpp
Adaptations of concepts from the standard library.
variant
std::visit
T visit(T... args)
// 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 <sstream>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input<seqan3::sequence_file_input_default_traits_aa> fin{std::istringstream{input},
seqan3::format_fasta{}};
}
// 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 <sstream>
#include <utility>
#include <vector>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
using record_type = typename decltype(fin)::record_type;
std::vector<record_type> records{};
for (auto & rec : fin)
records.push_back(std::move(rec));
}
// 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 <sstream>
#include <vector>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
using seqan3::get;
seqan3::sequence_file_input fin{std::istringstream{input},
seqan3::format_fasta{},
seqan3::fields<seqan3::field::id, seqan3::field::seq, seqan3::field::qual>{}};
for (auto & [id, seq, qual] : fin) // the order is now different, "id" comes first, because it was specified first
{
seqan3::debug_stream << "ID: " << id << '\n';
seqan3::debug_stream << "SEQ: " << seq << '\n';
seqan3::debug_stream << "QUAL: " << qual << '\n';
}
}
// 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/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
for (auto & [sequence, id, quality] : fin)
{
seqan3::debug_stream << "ID: " << id << '\n';
seqan3::debug_stream << "SEQ: " << sequence << '\n';
seqan3::debug_stream << "EMPTY QUAL." << quality << '\n'; // quality is empty for FASTA files
}
}
// 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 <ranges>
#include <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{}, seqan3::format_fasta{}};
auto minimum_length5_filter = std::views::filter(
[](auto const & rec)
{
return std::ranges::size(rec.sequence()) >= 5;
});
for (auto & rec : fin | minimum_length5_filter) // only record with sequence length >= 5 will "appear"
{
seqan3::debug_stream << "IDs of seq_length >= 5: " << rec.id() << '\n';
// ...
}
}
// 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 <sstream>
#include <utility>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
// ^ no need to specify the template arguments
}
// 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 <sstream>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
for (auto & record : fin)
{
seqan3::debug_stream << "ID: " << record.id() << '\n';
seqan3::debug_stream << "SEQ: " << record.sequence() << '\n';
// a quality field also exists, but is not printed, because we know it's empty for FASTA files.
}
}
// 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 <sstream>
#include <utility>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
auto rec0 = std::move(fin.front());
}
// 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 <sstream>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
auto it = std::ranges::begin(fin);
// the following are equivalent:
auto & rec0 = *it;
auto & rec1 = fin.front();
std::cout << std::boolalpha << (rec0.id() == rec1.id()) << '\n'; // true
// Note: rec0 and rec1 are references and become invalid after incrementing "it"!
}
// 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/test/snippet/create_temporary_snippet_file.hpp>
// std::filesystem::current_path() / "my.fasta" will be deleted after the execution
seqan3::test::create_temporary_snippet_file my_fasta{"my.fasta", ""};
#include <filesystem>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
using namespace seqan3::literals;
auto fasta_file = std::filesystem::current_path() / "my.fasta";
{
// Create a ./my.fasta file.
seqan3::sequence_file_output fout{fasta_file};
fout.emplace_back("ACGT"_dna4, "TEST1");
fout.emplace_back("AGGCTGA"_dna4, "Test2");
fout.emplace_back("GGAGTATAATATATATATATATAT"_dna4, "Test3");
}
// FASTA with DNA sequences assumed, regular std::ifstream taken as stream
seqan3::sequence_file_input fin{fasta_file};
}
seqan3::sequence_file_output::emplace_back
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition io/sequence_file/output.hpp:336
std::filesystem::current_path
T current_path(T... args)
// 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 <sstream>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
// ... input had amino acid sequences
auto input = R"(>TEST1
FQTWE
>Test2
KYRTW
>Test3
EEYQTWEEFARAAEKLYLTDPMKV)";
int main()
{ // Use amino acid traits below
using sequence_file_input_type =
seqan3::sequence_file_input<seqan3::sequence_file_input_default_traits_aa,
seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::qual>,
seqan3::type_list<seqan3::format_fasta>>;
sequence_file_input_type fin{std::istringstream{input}, seqan3::format_fasta{}};
}
seqan3::sequence_file_input_default_traits_aa
A traits type that specifies input as amino acids.
Definition sequence_file/input.hpp:166
// 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 <sstream>
#include <seqan3/alphabet/container/bitpacked_sequence.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/io/sequence_file/input.hpp>
auto input = R"(>TEST1
ACGT
>Test2
AGGCTGA
>Test3
GGAGTATAATATATATATATATAT)";
struct my_traits : seqan3::sequence_file_input_default_traits_dna
{
using sequence_alphabet = seqan3::dna4; // instead of dna5
template <typename alph>
using sequence_container = seqan3::bitpacked_sequence<alph>; // must be defined as a template!
};
int main()
{
seqan3::sequence_file_input<my_traits> fin{std::istringstream{input}, seqan3::format_fasta{}};
}
seqan3::sequence_file_input_default_traits_dna
The default traits for seqan3::sequence_file_input.
Definition sequence_file/input.hpp:130
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
std::vector<std::tuple<seqan3::dna5_vector, std::string>> range{{"ACGT"_dna5, "First"},
{"NATA"_dna5, "2nd"},
{"GATA"_dna5, "Third"}}; // a range of "records"
fout = range;
// the same as:
range | fout;
}
// 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 <sstream>
#include <string>
#include <seqan3/alphabet/container/concatenated_sequences.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/io/sequence_file/format_fasta.hpp>
#include <seqan3/io/sequence_file/output.hpp>
#include <seqan3/utility/views/zip.hpp>
using namespace seqan3::literals;
struct data_storage_t
{
seqan3::concatenated_sequences<seqan3::dna4_vector> sequences{"ACGT"_dna4, "AAA"_dna4};
seqan3::concatenated_sequences<std::string> ids{std::string{"ID1"}, std::string{"ID2"}};
};
int main()
{
data_storage_t data_storage{};
// ... in your file writing function:
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
fout = seqan3::views::zip(data_storage.sequences, data_storage.ids);
}
format_fasta.hpp
// 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/io/sequence_file/output.hpp>
int main()
{
seqan3::sequence_file_output fout{std::cout, seqan3::format_fasta{}};
// ^ no need to specify the template arguments
}
// 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 <filesystem>
#include <sstream>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/io/sequence_file/output.hpp>
auto input = R"(@TEST1
ACGT
+
##!#
@Test2
AGGCTGA
+
##!#!!!
@Test3
GGAGTATAATATATATATATATAT
+
##!###!###!###!###!###!#)";
int main()
{
// file format conversion in one line:
seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}} =
seqan3::sequence_file_input{std::istringstream{input}, seqan3::format_fastq{}};
// with seqan3::sequence_file_output as a variable:
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fastq{}};
fout = fin;
// or in pipe notation:
seqan3::sequence_file_input{std::istringstream{input}, seqan3::format_fastq{}}
| seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}};
}
seqan3::format_fastq
The FASTQ format.
Definition format_fastq.hpp:77
// 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 <sstream>
#include <string>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
for (int i = 0; i < 5; ++i) // some criteria
{
std::string id{"test_id"};
seqan3::dna5_vector seq{"ACGT"_dna5};
// ...
fout.emplace_back(seq, id);
}
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/quality/qualified.hpp>
#include <seqan3/io/sequence_file/output.hpp>
#include <seqan3/utility/views/elements.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{},
seqan3::format_fastq{},
seqan3::fields<seqan3::field::id, seqan3::field::seq, seqan3::field::qual>{}};
for (int i = 0; i < 5; i++)
{
std::string id{"test_id"};
// vector of combined data structure:
std::vector<seqan3::qualified<seqan3::dna5, seqan3::phred42>> seq_qual{{'N'_dna5, '7'_phred42},
{'A'_dna5, '1'_phred42},
{'C'_dna5, '3'_phred42}};
auto view_on_seq = seqan3::views::elements<0>(seq_qual);
auto view_on_qual = seqan3::views::elements<1>(seq_qual);
// ...
// Note that the order of the arguments is different from the default `seq, id, qual`,
// because you specified that ID should be first in the fields template argument.
fout.emplace_back(id, view_on_seq, view_on_qual);
// or:
fout.push_back(std::tie(id, view_on_seq, view_on_qual));
}
}
elements.hpp
Provides seqan3::views::elements.
seqan3::views::elements
constexpr auto elements
A view calling get on each element in a range.
Definition elements.hpp:77
// 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 <sstream>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/io/sequence_file/output.hpp>
auto input = R"(@TEST1
ACGT
+
##!#
@Test2
AGGCTGA
+
##!#!!!
@Test3
GGAGTATAATATATATATATATAT
+
##!###!###!###!###!###!#)";
int main()
{
seqan3::sequence_file_input fin{std::istringstream{input},
seqan3::format_fastq{},
seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::qual>{}};
seqan3::sequence_file_output fout{std::ostringstream{},
seqan3::format_fastq{}}; // doesn't have to match the configuration
for (auto & r : fin)
{
if (true) // r fulfills some criterium
fout.push_back(r);
}
}
// 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 <sstream>
#include <string>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
for (int i = 0; i < 5; ++i) // some criteria
{
seqan3::record<seqan3::type_list<seqan3::dna5_vector, std::string>,
seqan3::fields<seqan3::field::seq, seqan3::field::id>>
r{"ACGT"_dna5, "ID1"};
// ...
fout.push_back(r);
}
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
for (int i = 0; i < 5; ++i) // some criteria
{
std::string id{"test_id"};
seqan3::dna5_vector seq{"ACGT"_dna5};
// ...
fout.push_back(std::tie(seq, id));
}
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
auto it = fout.begin();
for (int i = 0; i < 5; ++i) // some criteria
{
std::string id{"test_id"};
seqan3::dna5_vector seq{"ACGT"_dna5};
// ...
// assign to iterator
*it = std::tie(seq, id);
// is the same as:
fout.push_back(std::tie(seq, id));
}
}
seqan3::sequence_file_output::begin
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition io/sequence_file/output.hpp:230
// 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 <sstream>
#include <string>
#include <tuple>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
for (int i = 0; i < 5; ++i) // ...
{
std::string id{"test_id"};
seqan3::dna5_vector seq{"ACGT"_dna5};
// ...
fout.emplace_back(seq, id); // as individual variables
// or:
fout.push_back(std::tie(seq, id)); // as a tuple
}
}
// 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/test/snippet/create_temporary_snippet_file.hpp>
// std::filesystem::current_path() / "my.fasta" will be deleted after the execution
seqan3::test::create_temporary_snippet_file my_fasta{"my.fasta", ""};
#include <filesystem>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
auto fasta_file = std::filesystem::current_path() / "my.fasta";
// FASTA format detected, std::ofstream opened for file
seqan3::sequence_file_output fin{fasta_file};
}
// 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/core/platform.hpp>
#include <iterator>
#include <ranges>
#include <sstream>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/io/sequence_file/output.hpp>
auto input = R"(@TEST1
ACGT
+
##!#
@Test2
AGGCTGA
+
##!#!!!
@Test3
GGAGTATAATATATATATATATAT
+
##!###!###!###!###!###!#)";
int main()
{
// minimum_average_quality_filter and minimum_sequence_length_filter need to be implemented first
auto minimum_sequence_length_filter = std::views::filter(
[](auto rec)
{
return std::ranges::distance(rec.sequence()) >= 50;
});
auto minimum_average_quality_filter = std::views::filter(
[](auto const & record)
{
double qual_sum{0}; // summation of the qualities
for (auto chr : record.base_qualities())
qual_sum += seqan3::to_phred(chr);
// check if average quality is greater than 20.
return qual_sum / (std::ranges::distance(record.base_qualities())) >= 20;
});
auto input_file = seqan3::sequence_file_input{std::istringstream{input}, seqan3::format_fastq{}};
input_file | minimum_average_quality_filter | minimum_sequence_length_filter | std::views::take(3)
| seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}};
}
iterator
// 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 <sstream>
#include <seqan3/io/structure_file/input.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input<seqan3::structure_file_input_default_traits_rna> fin{std::istringstream{input},
seqan3::format_vienna{}};
}
seqan3::format_vienna
The Vienna format (dot bracket notation) for RNA sequences with secondary structure.
Definition format_vienna.hpp:83
seqan3::structure_file_input
A class for reading structured sequence files, e.g. Stockholm, Connect, Vienna, ViennaRNA bpp matrix ...
Definition structure_file/input.hpp:358
input.hpp
Provides seqan3::structure_file_input and corresponding traits classes.
// 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 <filesystem>
#include <sstream>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/io/structure_file/output.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
auto tmp_file = std::filesystem::temp_directory_path() / "my.dbn";
using namespace seqan3::literals;
// First, make /tmp/input.dbn
{
seqan3::structure_file_output fout{tmp_file};
fout.emplace_back("GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA"_rna4,
"S.cerevisiae_tRNA-PHE M10740/1-73",
"(((((((..((((........)))).((((.........)))).....(((((.......))))))))))))."_wuss51);
fout.emplace_back("UUGGAGUACACAACCUGUACACUCUUUC"_rna4, "example", "..(((((..(((...)))..)))))..."_wuss51);
}
seqan3::structure_file_input sf{tmp_file}; // Vienna with RNA sequences assumed, use regular std::ifstream as stream
seqan3::structure_file_input fin{std::istringstream{input}, seqan3::format_vienna{}};
// ^ no need to specify the template arguments
std::filesystem::remove(tmp_file);
}
seqan3::structure_file_output
A class for writing structured sequence files, e.g. Stockholm, Connect, Vienna, ViennaRNA bpp matrix ...
Definition io/structure_file/output.hpp:60
seqan3::structure_file_output::emplace_back
void emplace_back(arg_t &&arg, arg_types &&... args)
Write a record to the file by passing individual fields.
Definition io/structure_file/output.hpp:363
output.hpp
Provides seqan3::structure_file_output and corresponding traits classes.
// 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 <sstream>
#include <utility>
#include <vector>
#include <seqan3/io/structure_file/input.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input fin{std::istringstream{input}, seqan3::format_vienna{}};
using record_type = typename decltype(fin)::record_type;
std::vector<record_type> records;
for (auto & rec : fin)
records.push_back(std::move(rec));
}
// 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 <ranges>
#include <sstream>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/structure_file/input.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input fin{std::istringstream{input}, seqan3::format_vienna{}};
auto minimum_length5_filter = std::views::filter(
[](auto const & rec)
{
return std::ranges::size(rec.sequence()) >= 5;
});
for (auto & rec : fin | minimum_length5_filter) // only record with sequence length >= 5 will "appear"
seqan3::debug_stream << (rec.sequence() | seqan3::views::to_char) << '\n';
}
// 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 <sstream>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/structure_file/input.hpp>
// Define custom traits
struct my_traits : seqan3::structure_file_input_default_traits_rna
{
using seq_alphabet = seqan3::rna4; // instead of rna5
};
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input<my_traits> fin{std::istringstream{input}, seqan3::format_vienna{}};
}
seqan3::structure_file_input_default_traits_rna
The default traits for seqan3::structure_file_input.
Definition structure_file/input.hpp:219
// 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 <sstream>
#include <utility>
#include <seqan3/io/structure_file/input.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input fin{std::istringstream{input}, seqan3::format_vienna{}};
auto rec0 = std::move(fin.front());
}
seqan3::structure_file_input::front
reference front() noexcept
Return the record we are currently at in the file.
Definition structure_file/input.hpp:642
// 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 <sstream>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
ACEWACEW
HGEBHHHH
> example
ACEWACEWACEWACEW
HGEBHHHHHGEBHHHH)";
int main()
{
using structure_file_input_t =
seqan3::structure_file_input<seqan3::structure_file_input_default_traits_aa,
seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::structure>,
seqan3::type_list<seqan3::format_vienna>>;
structure_file_input_t fin{std::istringstream{input}, seqan3::format_vienna{}};
for (auto & rec : fin)
{
seqan3::debug_stream << "ID: " << rec.id() << '\n';
// sequence and structure are converted to char on-the-fly
seqan3::debug_stream << "SEQ: " << (rec.sequence() | seqan3::views::to_char) << '\n';
seqan3::debug_stream << "STRUCTURE: " << (rec.sequence_structure() | seqan3::views::to_char) << '\n';
}
}
seqan3::structure_file_input_default_traits_aa
A traits type that specifies input as amino acids.
Definition structure_file/input.hpp:318
// 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 <sstream>
#include <seqan3/io/structure_file/input.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input fin{std::istringstream{input}, seqan3::format_vienna{}};
auto it = std::ranges::begin(fin);
// the following are equivalent:
auto & rec0 = *it;
auto & rec1 = fin.front();
std::cout << std::boolalpha << (rec0.id() == rec1.id()) << '\n'; // true
// both become invalid after incrementing "it"!
}
// 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 <sstream>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/utility/views/elements.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
using seqan3::get;
seqan3::structure_file_input fin{std::istringstream{input},
seqan3::format_vienna{},
seqan3::fields<seqan3::field::id, seqan3::field::structured_seq>{}};
// note that the order is now different, "id" comes first, because it was specified first
for (auto & [id, struc_seq] : fin)
{
seqan3::debug_stream << "ID: " << id << '\n';
// sequence and structure are part of the same vector, of type std::vector<structured_rna<rna5, wuss51>>
// sequence and structure strings are extracted and converted to char on-the-fly
seqan3::debug_stream << "SEQ: " << (struc_seq | seqan3::views::elements<0> | seqan3::views::to_char) << '\n';
seqan3::debug_stream << "STRUCTURE: " << (struc_seq | seqan3::views::elements<1> | seqan3::views::to_char)
<< '\n';
}
}
// 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 <sstream>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
ACEWACEW
HGEBHHHH
> example
ACEWACEWACEWACEW
HGEBHHHHHGEBHHHH)";
int main()
{
using seqan3::get;
using structure_file_input_t =
seqan3::structure_file_input<seqan3::structure_file_input_default_traits_aa,
seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::structure>,
seqan3::type_list<seqan3::format_vienna>>;
structure_file_input_t fin{std::istringstream{input}, seqan3::format_vienna{}};
for (auto & [seq, id, structure] : fin)
{
seqan3::debug_stream << "ID: " << id << '\n';
// sequence and structure are converted to char on-the-fly
seqan3::debug_stream << "SEQ: " << (seq | seqan3::views::to_char) << '\n';
seqan3::debug_stream << "STRUCTURE: " << (structure | seqan3::views::to_char) << '\n';
}
}
seqan3::field::structure
@ structure
Fixed interactions, usually a string of structure alphabet characters.
Definition record.hpp:70
// 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 <sstream>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
ACEWACEW
HGEBHHHH
> example
ACEWACEWACEWACEW
HGEBHHHHHGEBHHHH)";
int main()
{
// ... input had amino acid sequences
seqan3::structure_file_input<seqan3::structure_file_input_default_traits_aa,
seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::structure>,
seqan3::type_list<seqan3::format_vienna>>
fin{std::istringstream{input}, seqan3::format_vienna{}};
}
// 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 <sstream>
#include <string>
#include <vector>
#include <seqan3/alphabet/container/concatenated_sequences.hpp>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
#include <seqan3/utility/views/zip.hpp>
using namespace seqan3::literals;
struct data_storage_t
{
seqan3::concatenated_sequences<seqan3::rna5_vector> sequences{"AACGUU"_rna5};
seqan3::concatenated_sequences<std::string> ids{std::string{"seq1"}};
seqan3::concatenated_sequences<std::vector<seqan3::wuss51>> structures{".(())."_wuss51};
};
int main()
{
data_storage_t data_storage{}; // a global or globally used variable in your program
// ... in your file writing function:
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
fout = seqan3::views::zip(data_storage.sequences, data_storage.ids, data_storage.structures);
}
// 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 <sstream>
#include <string>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
for (int i = 0; i < 10; i++) // ...
{
std::string id{"test_id"};
seqan3::rna5_vector seq{"AGGGUU"_rna5};
std::vector<seqan3::wuss51> structure{"..().."_wuss51};
// ...
fout.emplace_back(seq, id, structure);
}
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
std::vector<std::tuple<seqan3::rna5_vector, std::string, std::vector<seqan3::wuss51>>> range{
{"ACGT"_rna5, "First", "...."_wuss51},
{"NATA"_rna5, "2nd", "...."_wuss51},
{"GATA"_rna5, "Third", "...."_wuss51}}; // a range of "records"
fout = range; // will iterate over the records and write them
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
for (int i = 0; i < 10; i++) // ...
{
std::string id{"test_id"};
seqan3::rna5_vector seq{"ACGU"_rna5};
std::vector<seqan3::wuss51> structure{".()."_wuss51};
// ...
fout.emplace_back(seq, id, structure); // as individual variables
// or:
fout.push_back(std::tie(seq, id, structure)); // as a tuple
}
}
seqan3::structure_file_output::push_back
void push_back(record_t &&r)
Write a seqan3::record to the file.
Definition io/structure_file/output.hpp:286
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
std::vector<std::tuple<seqan3::rna5_vector, std::string, std::vector<seqan3::wuss51>>> range{
{"ACGT"_rna5, "First", "...."_wuss51},
{"NATA"_rna5, "2nd", "...."_wuss51},
{"GATA"_rna5, "Third", "...."_wuss51}}; // a range of "records"
fout = range; // will iterate over the records and write them
}
// 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 <sstream>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/io/structure_file/output.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
bool criteria = true;
seqan3::structure_file_input fin{std::istringstream{input},
seqan3::format_vienna{},
seqan3::fields<seqan3::field::id, seqan3::field::seq, seqan3::field::structure>{}};
// the output doesn't have to match the configuration of the input
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
for (auto & r : fin)
{
if (criteria) // r fulfills some filter criterium
fout.push_back(r);
}
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
std::vector<std::tuple<seqan3::rna5_vector, std::string, std::vector<seqan3::wuss51>>> range{
{"ACGT"_rna5, "First", "...."_wuss51},
{"NATA"_rna5, "2nd", "...."_wuss51},
{"GATA"_rna5, "Third", "...."_wuss51}}; // a range of "records"
range | fout;
// the same as:
fout = range;
}
// 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 <sstream>
#include <seqan3/io/structure_file/input.hpp>
#include <seqan3/io/structure_file/output.hpp>
auto input = R"(> S.cerevisiae_tRNA-PHE M10740/1-73
GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUUUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCA
(((((((..((((........)))).((((.........)))).....(((((.......)))))))))))). (-17.50)
> example
UUGGAGUACACAACCUGUACACUCUUUC
..(((((..(((...)))..)))))... (-3.71))";
int main()
{
seqan3::structure_file_input my_in{std::istringstream{input}, seqan3::format_vienna{}};
my_in | std::views::take(2) | seqan3::structure_file_output{std::ostringstream{}, seqan3::format_vienna{}};
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
auto it = fout.begin();
for (int i = 0; i < 10; i++) // ...
{
std::string id{"test_id"};
seqan3::rna5_vector seq{"AGGGUU"_rna5};
std::vector<seqan3::wuss51> structure{"..().."_wuss51};
// ...
// assign to iterator
*it = std::tie(seq, id, structure);
// is the same as:
fout.push_back(std::tie(seq, id, structure));
}
}
seqan3::structure_file_output::begin
iterator begin() noexcept
Returns an iterator to current position in the file.
Definition io/structure_file/output.hpp:243
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::ostringstream{}, seqan3::format_vienna{}};
for (int i = 0; i < 10; i++) // ...
{
std::string id{"test_id"};
seqan3::rna5_vector seq{"AGGGUU"_rna5};
std::vector<seqan3::wuss51> structure{"..().."_wuss51};
// ...
fout.push_back(std::tie(seq, id, structure));
}
}
// 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 <filesystem>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
auto tmp_file = std::filesystem::temp_directory_path() / "my.dbn";
seqan3::structure_file_output fout{tmp_file}; // Vienna format detected, std::ofstream opened for file
std::filesystem::remove(tmp_file);
}
// 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 <sstream>
#include <string>
#include <tuple>
#include <vector>
#include <seqan3/alphabet/nucleotide/rna5.hpp>
#include <seqan3/alphabet/structure/structured_rna.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structured_rna<seqan3::rna5, seqan3::wuss51> sr{'G'_rna5, '.'_wuss51};
seqan3::structure_file_output fout{std::ostringstream{},
seqan3::format_vienna{},
seqan3::fields<seqan3::field::id, seqan3::field::structured_seq>{}};
for (int i = 0; i < 10; i++) // ...
{
std::string id{"test_id"};
// vector of combined data structure
std::vector<seqan3::structured_rna<seqan3::rna5, seqan3::wuss51>> structured_sequence{sr, sr, sr, sr};
// ...
// note also that the order the arguments is now different, because
// you specified that `seqan3::field::id` should be first in the fields template argument
fout.emplace_back(id, structured_sequence);
// or:
fout.push_back(std::tie(id, structured_sequence));
}
}
// 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 <iostream>
#include <seqan3/alphabet/nucleotide/rna4.hpp>
#include <seqan3/alphabet/structure/wuss.hpp>
#include <seqan3/io/structure_file/output.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::structure_file_output fout{std::cout, seqan3::format_vienna{}};
// ^ no need to specify the template arguments
fout.emplace_back("AACGUU"_rna4, "example_id", ".(())."_wuss51); // default order for vienna: SEQ, ID, STRUCTURE
}
// 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 <cstdlib> // std::rand
#include <future> // std::async
#include <string> // std::string
#include <seqan3/core/debug_stream.hpp> // seqan3::debug_stream
#include <seqan3/io/sequence_file/input.hpp> // seqan3::sequence_file_input
#include <seqan3/io/views/async_input_buffer.hpp> // seqan3::views::async_input_buffer
std::string fasta_file =
R"(> seq1
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq2
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq3
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq4
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq5
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq6
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq7
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq8
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq9
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq10
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq11
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
> seq12
ACGACTACGACGATCATCGATCGATCGATCGATCGATCGATCGATCGTACTACGATCGATCG
)";
int main()
{
// initialise random number generator, only needed for demonstration purposes
std::srand(std::time(nullptr));
// create an input file from the string above
seqan3::sequence_file_input fin{std::istringstream{fasta_file}, seqan3::format_fasta{}};
// create the async buffer around the input file
// spawns a background thread that tries to keep four records in the buffer
auto v = fin | seqan3::views::async_input_buffer(4);
// create a lambda function that iterates over the async buffer when called
// (the buffer gets dynamically refilled as soon as possible)
auto worker = [&v]()
{
for (auto & record : v)
{
// pretend we are doing some work
std::this_thread::sleep_for(std::chrono::milliseconds(std::rand() % 1000));
// print current thread and sequence ID
seqan3::debug_stream << "Thread: " << std::this_thread::get_id() << '\t' << "Seq: " << record.id()
<< '\n';
}
};
// launch two threads and pass the lambda function to both
auto f0 = std::async(std::launch::async, worker);
auto f1 = std::async(std::launch::async, worker);
}
async_input_buffer.hpp
Provides seqan3::views::async_input_buffer.
std::async
T async(T... args)
cstdlib
std::chrono::milliseconds
future
std::this_thread::get_id
T get_id(T... args)
seqan3::views::async_input_buffer
constexpr auto async_input_buffer
A view adapter that returns a concurrent-queue-like view over the underlying range.
Definition async_input_buffer.hpp:478
std::rand
T rand(T... args)
std::this_thread::sleep_for
T sleep_for(T... args)
std::srand
T srand(T... args)
std::time
T time(T... args)
// 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 <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/views/detail/take_exactly_view.hpp>
int main()
{
std::string vec{"foobar"};
auto v = vec | seqan3::detail::take_exactly(3); // or seqan3::detail::take_exactly_or_throw
seqan3::debug_stream << v << '\n'; // "foo"
seqan3::debug_stream << std::ranges::size(v) << '\n'; // 3
auto v2 = vec | seqan3::detail::take_exactly(9);
seqan3::debug_stream << std::ranges::size(v2) << '\n'; // 9 <- here be dragons! (undefined behaviour)
}
take_exactly_view.hpp
Provides seqan3::views::take_exactly and seqan3::views::take_exactly_or_throw.
// 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 <ranges>
#include <string>
#include <seqan3/core/debug_stream.hpp>
int main()
{
auto v = std::views::take_while(
[](auto const & l)
{
return (l != '\r') && (l != '\n');
});
}
// 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 <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/views/detail/take_line_view.hpp>
int main()
{
std::string vec{"foo\nbar"};
auto v = vec | seqan3::detail::take_line;
seqan3::debug_stream << v << '\n'; // [f,o,o]
auto v2 = vec | std::views::reverse | seqan3::detail::take_line;
seqan3::debug_stream << v2 << '\n'; // [r,a,b]
seqan3::debug_stream << v2 << '\n'; // [r,a,b] (parsing it again gives us the same result)
}
take_line_view.hpp
Provides seqan3::detail::take_line and seqan3::detail::take_line_or_throw.
// 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/core/debug_stream.hpp>
#include <seqan3/io/views/detail/take_line_view.hpp>
#include <seqan3/utility/views/single_pass_input.hpp>
int main()
{
std::string vec{"foo\nbar"};
auto v = vec | seqan3::views::single_pass_input | seqan3::detail::take_line;
seqan3::debug_stream << v << '\n'; // [f,o,o]
seqan3::debug_stream << v << '\n'; // [b,a,r] (parsing it again gives us the next line)
}
seqan3::views::single_pass_input
constexpr auto single_pass_input
A view adapter that decays most of the range properties and adds single pass behavior.
Definition single_pass_input.hpp:346
single_pass_input.hpp
Provides seqan3::views::single_pass_input.
// 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 <ranges> // for std::views::reverse
#include <string>
#include <seqan3/core/debug_stream.hpp> // for debug_stream
#include <seqan3/io/views/detail/take_until_view.hpp> // for detail::take_until*
#include <seqan3/utility/char_operations/predicate.hpp> // for is_char
#include <seqan3/utility/views/single_pass_input.hpp> // for views::single_pass_input
int main()
{
// regular usage
std::string vec{"foo\nbar"};
auto v = vec | seqan3::detail::take_until(seqan3::is_char<'\n'>); // or use a lambda
seqan3::debug_stream << v << '\n'; // "foo"
auto v2 = vec | std::views::reverse | seqan3::detail::take_until(seqan3::is_char<'\n'>);
seqan3::debug_stream << v2 << '\n'; // "rab"
// consuming behaviour
std::string vec2{"foo bar"}; // ← multiple spaces
auto vin = vec2 | seqan3::views::single_pass_input;
auto v3 = vin | seqan3::detail::take_until_and_consume(seqan3::is_blank);
seqan3::debug_stream << v3 << '\n'; // "foo"
seqan3::debug_stream << *std::ranges::begin(vin) << '\n'; // "b", the spaces where skipped
}
seqan3::is_blank
constexpr auto is_blank
Checks whether c is a blank character.
Definition predicate.hpp:139
seqan3::is_char
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition predicate.hpp:60
predicate.hpp
Provides character predicates for tokenisation.
take_until_view.hpp
Provides seqan3::views::take_until and seqan3::views::take_until_or_throw.
// 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/core/range/detail/random_access_iterator.hpp>
template <typename range_type>
class my_random_access_iterator :
public seqan3::detail::random_access_iterator_base<range_type, seqan3::detail::random_access_iterator>
{
//...
};
int main()
{}
random_access_iterator.hpp
Provides the seqan3::detail::random_access_iterator class.
// 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 <ranges>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/complement.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec{"ACGGTC"_dna4};
// views can be composed iteratively
auto vec_view3 = vec | std::views::reverse;
auto vec_view4 = vec_view3 | seqan3::views::complement;
// or in one line similar to the unix command line
auto vec_view5 = vec | seqan3::views::complement | std::views::reverse;
// vec_view4 and vec_view5 are the reverse complement of "ACGGTC": "GACCGT"
seqan3::debug_stream << vec_view4 << '\n'; // GACCGT
seqan3::debug_stream << vec_view5 << '\n'; // GACCGT
}
// 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 <algorithm>
#include <iostream>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/complement.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec{"ACGGTC"_dna4};
// these are synonymous:
auto vec_view1 = vec | seqan3::views::complement;
auto vec_view2 = seqan3::views::complement(vec);
std::cout << std::boolalpha << (std::ranges::equal(vec_view1, vec_view2)) << '\n'; // true
// both views "behave" like a collection of the elements 'T', 'G', 'C', 'C', 'A', 'G'
// but can be copied cheaply et cetera
}
algorithm
// 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 <ranges>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/complement.hpp>
#include <seqan3/utility/range/to.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector vec{"ACGGTC"_dna4};
auto vec_view2 = seqan3::views::complement(vec);
// re-convert to container
seqan3::dna4_vector complemented = vec_view2 | seqan3::ranges::to<seqan3::dna4_vector>();
assert(complemented == "TGCCAG"_dna4);
// also possible in one step
seqan3::dna4_vector reversed = vec | std::views::reverse | seqan3::ranges::to<seqan3::dna4_vector>();
assert(reversed == "CTGGCA"_dna4);
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/alphabet/views/complement.hpp>
#include <seqan3/alphabet/views/translate.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna5_vector sequence{"ACGTACGTACGTA"_dna5};
// pipe the vector through two view adaptors:
auto aminoacid_sequence = sequence | seqan3::views::complement | seqan3::views::translate_single;
// aminoacid_sequence is a view of length 4, accessing the elements on-demand will return
seqan3::debug_stream << aminoacid_sequence << '\n'; // "CMHA"
}
// 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/io/sequence_file/input.hpp>
#include <seqan3/io/sequence_file/output.hpp>
int main()
{
seqan3::sequence_file_input{"input.fastq"} | seqan3::sequence_file_output{"output.fasta"};
// no variables are created here, all input is immediately streamed to the output
// the format is converted on-the-fly
}
#include <seqan3/test/snippet/create_temporary_snippet_file.hpp>
// std::filesystem::current_path() / "input.fastq" will be deleted after the execution
seqan3::test::create_temporary_snippet_file input_fastq{"input.fastq", "\n"};
// std::filesystem::current_path() / "output.fasta" will be deleted after the execution
seqan3::test::create_temporary_snippet_file output_fasta{"output.fasta", ""};
// 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/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
int main()
{
seqan3::sequence_file_input fin{"my.fasta"};
// iterate over every record in the file and split it into fields:
for (auto & [seq, id, qual] : fin)
{
// print the fields:
seqan3::debug_stream << "ID: " << id << '\n';
seqan3::debug_stream << "SEQ: " << seq << '\n';
seqan3::debug_stream << "QUAL:" << qual << '\n'; // qual is empty for FASTA files
}
}
#include <seqan3/test/snippet/create_temporary_snippet_file.hpp>
// std::filesystem::current_path() / "my.fasta" will be deleted after the execution
seqan3::test::create_temporary_snippet_file my_fastq{"my.fasta", "\n"};
// 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 <iostream>
#include <seqan3/alignment/pairwise/all.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
int main()
{
using seqan3::operator""_dna4;
auto sequence1{"ACCA"_dna4};
auto sequence2{"ATTA"_dna4};
seqan3::configuration alignment_config =
seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme | seqan3::align_cfg::parallel{4};
for (auto const & res : seqan3::align_pairwise(std::tie(sequence1, sequence2), alignment_config))
std::cout << "Score: " << res.score() << '\n';
}
all.hpp
Meta-header for the Alignment / Pairwise submodule .
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/configuration/hit.hpp>
#include <seqan3/search/configuration/max_error.hpp>
#include <seqan3/search/fm_index/fm_index.hpp>
#include <seqan3/search/search.hpp>
int main()
{
using seqan3::operator""_dna4;
std::vector<seqan3::dna4_vector> text{"CGCTGTCTGAAGGATGAGTGTCAGCCAGTGTA"_dna4,
"ACCCGATGAGCTACCCAGTAGTCGAACTG"_dna4,
"GGCCAGACAACCCGGCGCTAATGCACTCA"_dna4};
seqan3::dna4_vector query{"GCT"_dna4};
seqan3::fm_index index{text};
// Use the dynamic hit configuration to set hit_all_best mode.
seqan3::configuration search_config = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}}
| seqan3::search_cfg::hit{seqan3::search_cfg::hit_all_best{}};
seqan3::debug_stream << "All single best hits:\n";
for (auto && hit : search(query, index, search_config)) // Find all best hits:
seqan3::debug_stream << hit << '\n';
// Change the hit configuration to the strata mode with a stratum of 1.
using seqan3::get;
get<seqan3::search_cfg::hit>(search_config).hit_variant = seqan3::search_cfg::hit_strata{1};
seqan3::debug_stream << "\nAll x+1 hits:\n";
for (auto && hit : search(query, index, search_config)) // Find all strata hits.
seqan3::debug_stream << hit << '\n';
}
seqan3::search_cfg::hit_all_best
Configuration element to receive all hits with the lowest number of errors within the error bounds.
Definition hit.hpp:56
seqan3::search_cfg::hit_strata
Configuration element to receive all hits with the best number of errors plus the given stratum....
Definition hit.hpp:107
seqan3::search_cfg::hit
A dynamic configuration element to configure the hit strategy at runtime.
Definition hit.hpp:140
seqan3::search_cfg::max_error_total
Configuration element that represents the number or rate of total errors.
Definition max_error.hpp:34
hit.hpp
Provides the configuration to define the hit strategies "hit_strata", "hit_all", "hit_all_best",...
max_error.hpp
Provides the configuration for maximum number of errors for all error types.
seqan3::search_cfg::error_count
A strong type of underlying type uint8_t that represents the number of errors.
Definition max_error_common.hpp:29
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/configuration/hit.hpp>
#include <seqan3/search/configuration/max_error.hpp>
#include <seqan3/search/fm_index/fm_index.hpp>
#include <seqan3/search/search.hpp>
int main()
{
using seqan3::operator""_dna4;
std::vector<seqan3::dna4_vector> text{"CGCTGTCTGAAGGATGAGTGTCAGCCAGTGTA"_dna4,
"ACCCGATGAGCTACCCAGTAGTCGAACTG"_dna4,
"GGCCAGACAACCCGGCGCTAATGCACTCA"_dna4};
seqan3::dna4_vector query{"GCT"_dna4};
seqan3::configuration const search_config =
seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}} | seqan3::search_cfg::hit_all_best{};
// Always provide a unified interface over the found hits independent of the index its text layout.
seqan3::debug_stream << "Search in text collection:\n";
seqan3::fm_index index_collection{text};
for (auto && hit : search(query, index_collection, search_config)) // Over a text collection.
seqan3::debug_stream << hit << '\n';
seqan3::debug_stream << "\nSearch in single text:\n";
seqan3::fm_index index_single{text[0]};
for (auto && hit : search(query, index_single, search_config)) // Over a single text.
seqan3::debug_stream << hit << '\n';
}
// 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 <mutex>
#include <vector>
#include <seqan3/alignment/configuration/align_config_edit.hpp>
#include <seqan3/alignment/configuration/align_config_method.hpp>
#include <seqan3/alignment/configuration/align_config_on_result.hpp>
#include <seqan3/alignment/configuration/align_config_parallel.hpp>
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
// Generate some sequences.
using seqan3::operator""_dna4;
using sequence_pair_t = std::pair<seqan3::dna4_vector, seqan3::dna4_vector>;
std::vector<sequence_pair_t> sequences{100, {"AGTGCTACG"_dna4, "ACGTGCGACTAG"_dna4}};
std::mutex write_to_debug_stream{}; // Need mutex to synchronise the output.
// Use edit distance with 4 threads.
auto const alignment_config =
seqan3::align_cfg::method_global{} | seqan3::align_cfg::edit_scheme | seqan3::align_cfg::parallel{4}
| seqan3::align_cfg::on_result{[&](auto && result)
{
std::lock_guard sync{write_to_debug_stream}; // critical section
seqan3::debug_stream << result << '\n';
}};
// Compute the alignments in parallel, and output them unordered using the callback (order is not deterministic).
seqan3::align_pairwise(sequences, alignment_config); // seqan3::align_pairwise is now declared void.
}
// 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/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/input.hpp>
int main()
{
seqan3::sequence_file_input fin{"my.fastq"};
for (auto && record : fin)
{
seqan3::debug_stream << "id: " << record.id() << '\n';
seqan3::debug_stream << "sequence: " << record.sequence() << '\n';
seqan3::debug_stream << "base_qualities: " << record.base_qualities() << '\n';
}
}
#include <seqan3/test/snippet/create_temporary_snippet_file.hpp>
// std::filesystem::current_path() / "my.fastq" will be deleted after the execution
seqan3::test::create_temporary_snippet_file input_fastq{"my.fastq", "\n"};
// 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>
int main()
{
using namespace seqan3::literals;
seqan3::dna4 ade = 'A'_dna4;
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> genome{"ATCGATCGAAGGCTAGCTAGCTAAGGGA"_dna4};
seqan3::bi_fm_index index{genome}; // build the index
auto cur = index.cursor(); // create a cursor
cur.extend_right("GG"_dna4); // search the pattern "GG"
cur.extend_left("AA"_dna4); // search the pattern "AAGG"
seqan3::debug_stream << "Number of hits: " << cur.count() << '\n'; // outputs: 2
seqan3::debug_stream << "Positions in the genome: ";
for (auto && pos : cur.locate()) // outputs: (0, 8), (0, 22)
seqan3::debug_stream << pos << ' ';
seqan3::debug_stream << '\n';
return 0;
}
seqan3::bi_fm_index_cursor::extend_right
bool extend_right() noexcept
Tries to extend the query by the smallest possible character to the right such that the query is foun...
Definition bi_fm_index_cursor.hpp:327
seqan3::bi_fm_index
The SeqAn Bidirectional FM Index.
Definition bi_fm_index.hpp:58
seqan3::bi_fm_index::cursor
cursor_type cursor() const noexcept
Returns a seqan3::bi_fm_index_cursor on the index that can be used for searching. .
Definition bi_fm_index.hpp:253
all.hpp
Meta-header for the Search / FM Index submodule .
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<std::vector<seqan3::dna4>> genomes{"ATCTGACGAAGGCTAGCTAGCTAAGGGA"_dna4,
"TAGCTGAAGCCATTGGCATCTGATCGGACT"_dna4,
"ACTGAGCTCGTC"_dna4,
"TGCATGCACCCATCGACTGACTG"_dna4,
"GTACGTACGTTACG"_dna4};
seqan3::bi_fm_index index{genomes}; // build the index
auto cur = index.cursor(); // create a cursor
cur.extend_right("GA"_dna4); // search the pattern "GA"
cur.extend_left("CT"_dna4); // search the pattern "CTGA"
seqan3::debug_stream << "Number of hits: " << cur.count() << '\n'; // outputs: 5
seqan3::debug_stream << "Positions in the genomes: ";
for (auto && pos : cur.locate()) // outputs: (3,16) (2,1) (1,3) (0,2) (1,19)
seqan3::debug_stream << pos << ' ';
seqan3::debug_stream << '\n';
return 0;
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/bi_fm_index.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::debug_stream << "Example cycle_back() and cycle_front()\n";
seqan3::dna4_vector genome{"GAATTAATGAAC"_dna4};
seqan3::bi_fm_index index{genome}; // build the bidirectional index
auto cur = index.cursor(); // create a cursor
// cur.cycle_back(); // cycle_back / cycle_front on begin() is undefined behaviour!
cur.extend_right("AAC"_dna4); // search the sequence "AAC"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "AAC"
seqan3::debug_stream << cur.last_rank() << '\n'; // outputs 1
// cur.cycle_front(); // undefined behaviour! only cycle_back() is allowed after extend_right()
cur.cycle_back(); // search the sequence "AAT"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "AAT"
seqan3::debug_stream << cur.last_rank() << '\n'; // outputs 3
cur.extend_left('G'_dna4); // search the sequence "GAAT"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "GAAT"
seqan3::debug_stream << cur.last_rank() << '\n'; // outputs 2
// cur.cycle_back(); // undefined behaviour! only cycle_front() is allowed after extend_left()
cur.cycle_front(); // search the sequence "TAAT"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "TAAT"
seqan3::debug_stream << cur.last_rank() << '\n'; // outputs 3
cur.cycle_front(); // search the sequence "TAAT"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "TAAT"
seqan3::debug_stream << cur.last_rank() << '\n'; // outputs 3
}
bi_fm_index.hpp
Provides the bidirectional seqan3::bi_fm_index.
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/bi_fm_index.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::debug_stream << "Example extend_left(seq)\n";
seqan3::dna4_vector genome{"GAATTAATGAAC"_dna4};
seqan3::bi_fm_index index{genome}; // build the bidirectional index
auto cur = index.cursor(); // create a cursor
cur.extend_right("AAC"_dna4); // search the sequence "AAC"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "AAC"
cur.extend_left("ATG"_dna4); // extend the query to "ATGAAC"
// The rightmost character of "ATG" is extended to the left first.
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "ATGAAC"
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/bi_fm_index.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::debug_stream << "Example to_fwd_cursor()\n";
seqan3::dna4_vector genome{"GAATTAACGAAC"_dna4};
seqan3::bi_fm_index index{genome}; // build the bidirectional index
auto cur = index.cursor(); // create a cursor
cur.extend_left("AAC"_dna4); // search the sequence "AAC"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // outputs "AAC"
auto uni_it = cur.to_fwd_cursor(); // unidirectional cursor on the text "GAATTAACGAAC"
seqan3::debug_stream << uni_it.path_label(genome) << '\n'; // outputs "AAC"
// Undefined behaviour! Cannot be called on the forward cursor if the last extension on the bidirectional
// cursor was to the left:
// cur.cycle_back();
// seqan3::debug_stream << cur.last_rank() << '\n';
uni_it.extend_right('G'_dna4); // search the sequence "AACG"
seqan3::debug_stream << uni_it.path_label(genome) << '\n'; // outputs "AACG"
seqan3::debug_stream << uni_it.last_rank() << '\n'; // outputs 2
uni_it.cycle_back(); // returns false since there is no sequence "AACT" in the text.
}
seqan3::bi_fm_index_cursor::extend_left
bool extend_left() noexcept
Tries to extend the query by the smallest possible character to the left such that the query is found...
Definition bi_fm_index_cursor.hpp:380
// 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/search/configuration/hit.hpp>
#include <seqan3/search/configuration/max_error.hpp>
#include <seqan3/search/configuration/output.hpp>
int main()
{
auto const zero_errors = seqan3::search_cfg::error_count{0};
// No errors, all hits as text position
seqan3::configuration const default_cfg =
seqan3::search_cfg::max_error_total{zero_errors} | seqan3::search_cfg::max_error_substitution{zero_errors}
| seqan3::search_cfg::max_error_insertion{zero_errors} | seqan3::search_cfg::max_error_deletion{zero_errors}
| seqan3::search_cfg::output_query_id{} | seqan3::search_cfg::output_reference_id{}
| seqan3::search_cfg::output_reference_begin_position{} | seqan3::search_cfg::hit_all{};
return 0;
}
seqan3::search_cfg::hit_all
Configuration element to receive all hits within the error bounds.
Definition hit.hpp:31
seqan3::search_cfg::max_error_deletion
Configuration element that represents the number or rate of deletion errors.
Definition max_error.hpp:170
seqan3::search_cfg::max_error_insertion
Configuration element that represents the number or rate of insertion errors.
Definition max_error.hpp:124
seqan3::search_cfg::max_error_substitution
Configuration element that represents the number or rate of substitution errors.
Definition max_error.hpp:79
seqan3::search_cfg::output_query_id
Include the query_id in the seqan3::search_result returned by a call to seqan3::search.
Definition search/configuration/output.hpp:28
seqan3::search_cfg::output_reference_begin_position
Include the reference_begin_position in the seqan3::search_result returned by a call to seqan3::searc...
Definition search/configuration/output.hpp:78
seqan3::search_cfg::output_reference_id
Include the reference_id in the seqan3::search_result returned by a call to seqan3::search.
Definition search/configuration/output.hpp:53
output.hpp
Provides the configuration for the content of the search result.
// 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/core/configuration/configuration.hpp>
#include <seqan3/search/configuration/max_error.hpp>
int main()
{
// Allow 1 error of any type.
seqan3::configuration const cfg1 = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
// Do not allow substitutions. Allow at most 1 error.
seqan3::configuration const cfg2 = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}}
| seqan3::search_cfg::max_error_substitution{seqan3::search_cfg::error_count{0}}
| seqan3::search_cfg::max_error_insertion{seqan3::search_cfg::error_count{1}}
| seqan3::search_cfg::max_error_deletion{seqan3::search_cfg::error_count{1}};
// Sets total errors to 2.
seqan3::configuration const cfg3 = seqan3::search_cfg::max_error_substitution{seqan3::search_cfg::error_count{0}}
| seqan3::search_cfg::max_error_insertion{seqan3::search_cfg::error_count{1}}
| seqan3::search_cfg::max_error_deletion{seqan3::search_cfg::error_count{1}};
// Allow 10% errors of any type.
seqan3::configuration const cfg4 = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_rate{0.1}};
// Do not allow substitutions. Allow at most 10% errors.
seqan3::configuration const cfg5 = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_rate{.1}}
| seqan3::search_cfg::max_error_substitution{seqan3::search_cfg::error_rate{.0}}
| seqan3::search_cfg::max_error_insertion{seqan3::search_cfg::error_rate{.1}}
| seqan3::search_cfg::max_error_deletion{seqan3::search_cfg::error_rate{.1}};
// Sets total errors to 20%.
seqan3::configuration const cfg6 = seqan3::search_cfg::max_error_substitution{seqan3::search_cfg::error_rate{.0}}
| seqan3::search_cfg::max_error_insertion{seqan3::search_cfg::error_rate{.1}}
| seqan3::search_cfg::max_error_deletion{seqan3::search_cfg::error_rate{.1}};
// Mixed error rate & count: Allow 2 insertions and or 2 deletions and 20% errors in total.
seqan3::configuration const cfg7 = seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_rate{.2}}
| seqan3::search_cfg::max_error_substitution{seqan3::search_cfg::error_count{0}}
| seqan3::search_cfg::max_error_insertion{seqan3::search_cfg::error_count{2}}
| seqan3::search_cfg::max_error_deletion{seqan3::search_cfg::error_count{2}};
return 0;
}
seqan3::search_cfg::error_rate
A strong type of underlying type double that represents the rate of errors.
Definition max_error_common.hpp:43
// 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/core/debug_stream.hpp>
#include <seqan3/search/configuration/on_result.hpp>
int main()
{
seqan3::search_cfg::on_result cfg{[](auto && result)
{
seqan3::debug_stream << result << '\n';
}};
return 0;
}
seqan3::search_cfg::on_result
Configuration element to provide a user defined callback function for the search.
Definition on_result.hpp:52
on_result.hpp
Provides seqan3::search_cfg::on_result.
// 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/search/configuration/max_error.hpp>
#include <seqan3/search/configuration/output.hpp>
int main()
{
// Only return the reference id where a query matched the reference:
seqan3::configuration const cfg1 = seqan3::search_cfg::output_reference_id{};
// Same as the default:
seqan3::configuration const cfg2 = seqan3::search_cfg::output_query_id{} | seqan3::search_cfg::output_reference_id{}
| seqan3::search_cfg::output_reference_begin_position{};
// Only return cursors of the index.
seqan3::configuration const cfg3 = seqan3::search_cfg::output_index_cursor{};
return 0;
}
seqan3::search_cfg::output_index_cursor
Include the index_cursor in the seqan3::search_result returned by a call to seqan3::search.
Definition search/configuration/output.hpp:104
// 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/core/configuration/configuration.hpp>
#include <seqan3/search/configuration/max_error.hpp>
#include <seqan3/search/configuration/parallel.hpp>
int main()
{
// Enable parallel execution of the search algorithm with 8 threads (and allow 1 error of any type).
seqan3::configuration cfg1 =
seqan3::search_cfg::parallel{8} | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
// Alternative solution: assign to the member variable of the parallel configuration
seqan3::search_cfg::parallel par_cfg{};
par_cfg.thread_count = 8;
seqan3::configuration cfg2 = par_cfg | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
return 0;
}
seqan3::search_cfg::parallel
seqan3::detail::parallel_mode< std::integral_constant< seqan3::detail::search_config_id, seqan3::detail::search_config_id::parallel > > parallel
Enables the parallel execution of the search algorithm if possible for the given configuration.
Definition parallel.hpp:31
parallel.hpp
Provides seqan3::search_cfg::parallel configuration.
// 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/core/debug_stream.hpp>
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
using namespace seqan3::literals;
int main()
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{8u},
seqan3::bin_size{8192u},
seqan3::hash_function_count{2u}};
auto const sequence1 = "ACTGACTGACTGATC"_dna4;
auto const sequence2 = "GTGACTGACTGACTCG"_dna4;
auto const sequence3 = "AAAAAAACGATCGACA"_dna4;
auto hash_adaptor = seqan3::views::kmer_hash(seqan3::ungapped{5u});
// Insert all 5-mers of sequence1 into bin 0
for (auto && value : sequence1 | hash_adaptor)
ibf.emplace(value, seqan3::bin_index{0u});
// Insert all 5-mers of sequence2 into bin 4
for (auto && value : sequence2 | hash_adaptor)
ibf.emplace(value, seqan3::bin_index{4u});
// Insert all 5-mers of sequence3 into bin 7
for (auto && value : sequence3 | hash_adaptor)
ibf.emplace(value, seqan3::bin_index{7u});
auto agent = ibf.counting_agent();
// Count all 5-mers of sequence1 for all bins
seqan3::debug_stream << agent.bulk_count(sequence1 | hash_adaptor) << '\n'; // [11,0,0,0,9,0,0,0]
// Search for specific values
std::vector<size_t> const values{92, 1238, 812, 81273};
seqan3::debug_stream << agent.bulk_count(values) << '\n'; // [0,0,0,0,0,0,0,0]
seqan3::debug_stream << agent.bulk_count(std::views::iota(0u, 1024u)) << '\n'; // [6,0,0,0,7,0,0,10]
// The default counters are 16 bit unsigned integer.
// An optional template parameter can be used to specify the counter type
auto agent2 = ibf.counting_agent<uint8_t>();
// The returned counts are now 8 bit unsigned integers.
seqan3::debug_stream << agent.bulk_count(sequence1 | hash_adaptor) << '\n'; // [11,0,0,0,9,0,0,0]
}
seqan3::interleaved_bloom_filter
The IBF binning directory. A data structure that efficiently answers set-membership queries for multi...
Definition interleaved_bloom_filter.hpp:98
seqan3::interleaved_bloom_filter::emplace
void emplace(size_t const value, bin_index const bin) noexcept
Inserts a value into a specific bin.
Definition interleaved_bloom_filter.hpp:261
seqan3::interleaved_bloom_filter::counting_agent
counting_agent_type< value_t > counting_agent() const
Returns a seqan3::interleaved_bloom_filter::counting_agent_type to be used for counting.
Definition interleaved_bloom_filter.hpp:418
seqan3::views::kmer_hash
constexpr auto kmer_hash
Computes hash values for each position of a range via a given shape.
Definition kmer_hash.hpp:766
interleaved_bloom_filter.hpp
Provides seqan3::interleaved_bloom_filter.
kmer_hash.hpp
Provides seqan3::views::kmer_hash.
seqan3::bin_count
A strong type that represents the number of bins for the seqan3::interleaved_bloom_filter.
Definition bloom_filter_strong_types.hpp:31
seqan3::bin_index
A strong type that represents the bin index for the seqan3::interleaved_bloom_filter.
Definition bloom_filter_strong_types.hpp:52
seqan3::bin_size
A strong type that represents the number of bits for each bin in the seqan3::interleaved_bloom_filter...
Definition bloom_filter_strong_types.hpp:38
seqan3::hash_function_count
A strong type that represents the number of hash functions for the seqan3::interleaved_bloom_filter.
Definition bloom_filter_strong_types.hpp:45
seqan3::ungapped
A strong type of underlying type uint8_t that represents the ungapped shape size.
Definition shape.hpp:22
// 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/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
// Construct an Interleaved Bloom Filter to be used with the counting_agent.
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{43u},
seqan3::bin_size{8192u},
seqan3::hash_function_count{3}};
// The counting_agent can now be constructed by calling `counting_agent` on the Interleaved Bloom Filter.
auto agent = ibf.counting_agent();
// Calling `increase_bin_number_to` invalidates the agent.
ibf.increase_bin_number_to(seqan3::bin_count{60u});
// So make sure to construct a new counting_agent.
agent = ibf.counting_agent();
}
seqan3::interleaved_bloom_filter::increase_bin_number_to
void increase_bin_number_to(bin_count const new_bins_)
Increases the number of bins stored in the Interleaved Bloom Filter.
Definition interleaved_bloom_filter.hpp:346
// 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/core/debug_stream.hpp>
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{12u}, seqan3::bin_size{8192u}};
ibf.emplace(126, seqan3::bin_index{0u});
ibf.emplace(126, seqan3::bin_index{3u});
ibf.emplace(126, seqan3::bin_index{9u});
ibf.emplace(712, seqan3::bin_index{3u});
ibf.emplace(237, seqan3::bin_index{9u});
// The counting_vector must be at least as big as there are bins.
seqan3::counting_vector<uint8_t> counts(12, 0);
auto agent = ibf.membership_agent();
counts += agent.bulk_contains(712); // `counts` contains the number of occurrences of 712 in each bin.
seqan3::debug_stream << counts << '\n'; // prints [0,0,0,1,0,0,0,0,0,0,0,0]
counts += agent.bulk_contains(237); // `counts` contains the number of occurrences of 712 and 237 in each bin.
seqan3::debug_stream << counts << '\n'; // prints [0,0,0,1,0,0,0,0,0,1,0,0]
counts += agent.bulk_contains(126); // `counts` contains the number of occurrences of 712, 237 and 126 in each bin.
seqan3::debug_stream << counts << '\n'; // prints [1,0,0,2,0,0,0,0,0,2,0,0]
counts += counts; // multiple counts can also be added together
seqan3::debug_stream << counts << '\n'; // prints [2,0,0,4,0,0,0,0,0,4,0,0]
}
seqan3::counting_vector
A data structure that behaves like a std::vector and can be used to consolidate the results of multip...
Definition interleaved_bloom_filter.hpp:777
seqan3::interleaved_bloom_filter::membership_agent
membership_agent_type membership_agent() const
Returns a seqan3::interleaved_bloom_filter::membership_agent_type to be used for lookup.
Definition interleaved_bloom_filter.hpp:401
// 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/core/debug_stream.hpp>
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/utility/views/chunk.hpp>
using namespace seqan3::literals;
int main()
{
auto genome = "TTTTTTTTTTAAAAAAAAAATTTTTTTTTTGGGGGGGGGG"_dna4;
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{4u}, seqan3::bin_size{8192u}}; // reserve 4 buckets
// Fill buckets of the interleaved bloomm filter
auto genome_buckets = genome | seqan3::views::chunk(10); // divide genome into buckets of size 10
size_t bucket_idx{0};
for (auto bucket : genome_buckets)
{
for (auto kmer : bucket | seqan3::views::kmer_hash(seqan3::ungapped{2})) // hash genome with k = 2
ibf.emplace(kmer, seqan3::bin_index{bucket_idx});
++bucket_idx;
}
auto ibf_agent = ibf.counting_agent(); // the membership_agent enables efficient kemr queries
auto query = "TTT"_dna4;
auto query_kmers = query | seqan3::views::kmer_hash(seqan3::ungapped{2}); // hash query with k = 2
seqan3::debug_stream << ibf_agent.bulk_count(query_kmers) << '\n'; // prints [2,0,2,0]
}
chunk.hpp
Provides seqan3::views::chunk.
seqan3::views::chunk
seqan::stl::views::chunk chunk
A view adaptor that divides a range into chunks. <dl class="no-api">This entity is not part of the Se...
Definition chunk.hpp:23
// 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/core/debug_stream.hpp>
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
using namespace seqan3::literals;
int main()
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{8u},
seqan3::bin_size{8192u},
seqan3::hash_function_count{2u}};
auto const sequence1 = "ACTGACTGACTGATC"_dna4;
auto const sequence2 = "GTGACTGACTGACTCG"_dna4;
auto const sequence3 = "AAAAAAACGATCGACA"_dna4;
auto hash_adaptor = seqan3::views::kmer_hash(seqan3::ungapped{5u});
// Insert all 5-mers of sequence1 into bin 0
for (auto && value : sequence1 | hash_adaptor)
ibf.emplace(value, seqan3::bin_index{0u});
// Insert all 5-mers of sequence2 into bin 4
for (auto && value : sequence2 | hash_adaptor)
ibf.emplace(value, seqan3::bin_index{4u});
// Insert all 5-mers of sequence3 into bin 7
for (auto && value : sequence3 | hash_adaptor)
ibf.emplace(value, seqan3::bin_index{7u});
auto agent = ibf.counting_agent();
// Count all 5-mers of sequence1 for all bins
seqan3::debug_stream << agent.bulk_count(sequence1 | hash_adaptor) << '\n'; // [11,0,0,0,9,0,0,0]
// Clear bin 0
ibf.clear(seqan3::bin_index{0u});
// After clearing, no 5-mers are found in bin 0
seqan3::debug_stream << agent.bulk_count(sequence1 | hash_adaptor) << '\n'; // [0,0,0,0,9,0,0,0]
// Search for specific values
seqan3::debug_stream << agent.bulk_count(std::views::iota(0u, 1024u)) << '\n'; // [0,0,0,0,7,0,0,10]
// Clear bin 4 and 7
ibf.clear(std::vector{seqan3::bin_index{4u}, seqan3::bin_index{7u}});
// After clearing, nothing is found
seqan3::debug_stream << agent.bulk_count(std::views::iota(0u, 1024u)) << '\n'; // [0,0,0,0,0,0,0,0]
}
seqan3::interleaved_bloom_filter::clear
void clear(bin_index const bin) noexcept
Clears a specific bin.
Definition interleaved_bloom_filter.hpp:285
// 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/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
// Construct an Interleaved Bloom Filter that contains 43 bins, each using 8192 bits, and 3 hash functions.
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{43u},
seqan3::bin_size{8192u},
seqan3::hash_function_count{3}};
// Construct an Interleaved Bloom Filter that contains 43 bins, each using 256 KiBits,
// and the default of 2 hash functions.
seqan3::interleaved_bloom_filter ibf2{seqan3::bin_count{43}, seqan3::bin_size{1ULL << 20}};
}
// 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/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
// Construct an uncompressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{4u}, seqan3::bin_size{128u}, seqan3::hash_function_count{3}};
// Fill `ibf` with data.
// Construct an immutable, compressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter<seqan3::data_layout::compressed> ibf2{ibf};
}
// 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/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
// Construct an uncompressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{9u}, seqan3::bin_size{128u}, seqan3::hash_function_count{3}};
// Insert the values `126`, `712` and `237` into bins `0`, `3` and `8` of the Interleaved Bloom Filter.
ibf.emplace(126, seqan3::bin_index{0u});
ibf.emplace(712, seqan3::bin_index{3u});
ibf.emplace(237, seqan3::bin_index{8u});
// Construct an immutable, compressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter<seqan3::data_layout::compressed> ibf_compressed{ibf};
// Decompress the compressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter ibf_decompressed{ibf_compressed};
}
// 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/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{12u}, seqan3::bin_size{8192u}};
// Insert the values `126`, `712` and `237` into bins `0`, `3` and `9` of the Interleaved Bloom Filter.
ibf.emplace(126, seqan3::bin_index{0u});
ibf.emplace(712, seqan3::bin_index{3u});
ibf.emplace(237, seqan3::bin_index{9u});
}
// 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/core/debug_stream.hpp>
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{12u}, seqan3::bin_size{8192u}};
ibf.emplace(126, seqan3::bin_index{0u});
ibf.emplace(712, seqan3::bin_index{3u});
ibf.emplace(237, seqan3::bin_index{9u});
ibf.increase_bin_number_to(seqan3::bin_count{18u});
// Be sure to get the agent after `increase_bin_number_to` as it invalidates all agents!
auto agent = ibf.membership_agent();
// The content of the bins which were already present before the resize does not change
seqan3::debug_stream << agent.bulk_contains(126) << '\n'; // prints [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
seqan3::debug_stream << agent.bulk_contains(712) << '\n'; // prints [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
seqan3::debug_stream << agent.bulk_contains(237) << '\n'; // prints [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0]
}
// 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/core/debug_stream.hpp>
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{12u}, seqan3::bin_size{8192u}};
ibf.emplace(126, seqan3::bin_index{0u});
ibf.emplace(712, seqan3::bin_index{3u});
ibf.emplace(237, seqan3::bin_index{9u});
// Query the Interleaved Bloom Filter. Note that there may be false positive results!
// A `1` at position `i` indicates the (probable) presence of the query in bin `i`.
// Capture the result by reference to avoid copies.
auto agent = ibf.membership_agent();
auto & result = agent.bulk_contains(712);
seqan3::debug_stream << result << '\n'; // prints [0,0,0,1,0,0,0,0,0,0,0,0]
// Calling `increase_bin_number_to` invalidates the agent.
ibf.increase_bin_number_to(seqan3::bin_count{60u});
// So make sure to construct a new membership_agent.
agent = ibf.membership_agent();
}
// 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/search/dream_index/interleaved_bloom_filter.hpp>
int main()
{
// Construct an Interleaved Bloom Filter to be used with the membership_agent.
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{43u},
seqan3::bin_size{8192u},
seqan3::hash_function_count{3}};
// The membership_agent can now be constructed by calling `membership_agent` on the Interleaved Bloom Filter.
auto agent = ibf.membership_agent();
// Calling `increase_bin_number_to` invalidates the agent.
ibf.increase_bin_number_to(seqan3::bin_count{60u});
// So make sure to construct a new membership_agent.
agent = ibf.membership_agent();
}
// 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/search/configuration/all.hpp>
int main()
{
// Default constructed: Has no hit strategy selected.
seqan3::search_cfg::hit dynamic_hit{};
// Select hit_all
dynamic_hit = seqan3::search_cfg::hit_all{};
// If condition is true choose strata strategy, otherwise find the single best hit.
if (true)
dynamic_hit = seqan3::search_cfg::hit_strata{4};
else
dynamic_hit = seqan3::search_cfg::hit_single_best{};
// Combine it with other configurations.
seqan3::configuration const cfg =
dynamic_hit | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
// Directly initialised.
seqan3::search_cfg::hit dynamic_hit2{seqan3::search_cfg::hit_all_best{}};
// You cannot combine the dynamic hit configuration with the static ones.
// auto fail = seqan3::search_cfg::hit_single_best{} | seqan3::search_cfg::hit; // doesn't compile
return 0;
}
seqan3::search_cfg::hit_single_best
Configuration element to receive a single best hit with the lowest number of errors within the error ...
Definition hit.hpp:81
all.hpp
Meta-header for the search configuration module .
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> genome{"ATCGATCGAAGGCTAGCTAGCTAAGGGA"_dna4};
seqan3::fm_index index{genome}; // build the index
auto cur = index.cursor(); // create a cursor
cur.extend_right("AAGG"_dna4); // search the pattern "AAGG"
seqan3::debug_stream << "Number of hits: " << cur.count() << '\n'; // outputs: 2
seqan3::debug_stream << "Positions in the genome: ";
for (auto && pos : cur.locate()) // outputs: (0, 8), (0, 22)
seqan3::debug_stream << pos << ' ';
seqan3::debug_stream << '\n';
return 0;
}
seqan3::fm_index_cursor::extend_right
bool extend_right() noexcept
Tries to extend the query by the smallest possible character to the right such that the query is foun...
Definition fm_index_cursor.hpp:256
seqan3::fm_index::cursor
cursor_type cursor() const noexcept
Returns a seqan3::fm_index_cursor on the index that can be used for searching. .
Definition fm_index.hpp:537
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<std::vector<seqan3::dna4>> genomes{"ATCTGACGAAGGCTAGCTAGCTAAGGGA"_dna4,
"TAGCTGAAGCCATTGGCATCTGATCGGACT"_dna4,
"ACTGAGCTCGTC"_dna4,
"TGCATGCACCCATCGACTGACTG"_dna4,
"GTACGTACGTTACG"_dna4};
seqan3::fm_index index{genomes}; // build the index
auto cur = index.cursor(); // create a cursor
cur.extend_right("CTGA"_dna4); // search the pattern "CTGA"
seqan3::debug_stream << "Number of hits: " << cur.count() << '\n'; // outputs: 5
seqan3::debug_stream << "Positions in the genomes: ";
for (auto && pos : cur.locate()) // outputs: (3,16) (2,1) (1,3) (0,2) (1,19)
seqan3::debug_stream << pos << ' ';
seqan3::debug_stream << '\n';
return 0;
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4> genome{"AATAATAAC"_dna4};
seqan3::fm_index index{genome}; // build the index
auto cur = index.cursor(); // create a cursor
// cur.cycle_back(); // cycle_back on begin() is undefined behaviour!
cur.extend_right("AAC"_dna4); // search the sequence "AAC"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // prints "AAC"
seqan3::debug_stream << cur.last_rank() << '\n'; // prints 1
seqan3::debug_stream << cur.query_length() << '\n'; // prints 3
auto [left_bound, right_bound] = cur.suffix_array_interval(); // Get the half-open suffix array interval.
seqan3::debug_stream << '[' << left_bound << ',' << right_bound << ")\n"; // prints "[7,8)"
cur.cycle_back(); // search the sequence "AAT"
seqan3::debug_stream << cur.path_label(genome) << '\n'; // prints "AAT"
seqan3::debug_stream << cur.last_rank() << '\n'; // prints 3
seqan3::debug_stream << cur.query_length() << '\n'; // prints 3
auto interval = cur.suffix_array_interval(); // Get the half-open suffix array interval.
seqan3::debug_stream << '[' << interval.begin_position << ',' << interval.end_position << ")\n"; // prints "[8,10)"
cur.cycle_back(); // "cur" doesn't change because the rightmost char
// is already the largest dna4 char.
seqan3::debug_stream << cur.path_label(genome) << '\n'; // prints "AAT"
seqan3::debug_stream << cur.last_rank() << '\n'; // prints 3
seqan3::debug_stream << cur.query_length() << '\n'; // prints 3
auto && [lb, rb] = cur.suffix_array_interval(); // Get the half-open suffix array interval.
seqan3::debug_stream << '[' << lb << ',' << rb << ")\n"; // prints "[8,10)"
}
// 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/core/configuration/configuration.hpp>
#include <seqan3/search/configuration/hit.hpp>
#include <seqan3/search/configuration/max_error.hpp>
int main()
{
// Report all hits with 0 errors (maximum number of errors defaults to 0).
seqan3::configuration const cfg1 = seqan3::search_cfg::hit_all{};
// Report all hits with 0 and 1 errors.
seqan3::configuration const cfg2 =
seqan3::search_cfg::hit_all{} | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
// Report the single best hit with the least number of errors (up to 1 error is allowed).
seqan3::configuration const cfg3 =
seqan3::search_cfg::hit_single_best{} | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
// Report all hits with the least number of errors (either 0 or 1 errors).
seqan3::configuration const cfg4 =
seqan3::search_cfg::hit_all_best{} | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{1}};
// Report all hits with best + 1 error but no more than 2 (errors).
// E.g., if the best hit has 1 error, all hits with 1 and 2 errors are reported.
// E.g., if the best hit has 2 error, only hits with 2 errors are reported since 3 exceeds total.
seqan3::configuration const cfg5 =
seqan3::search_cfg::hit_strata{1} | seqan3::search_cfg::max_error_total{seqan3::search_cfg::error_count{2}};
// you must choose only one mode
// auto fail = seqan3::search_cfg::hit_single_best{} | seqan3::search_cfg::hit_all{}; // doesn't compile
return 0;
}
// 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 <ranges> // For std::ranges::size()
#include <seqan3/core/debug_stream.hpp> // For seqan3::debug_stream
#include <seqan3/search/kmer_index/shape.hpp> // For seqan3::shape
using namespace seqan3::literals;
int main()
{
seqan3::shape s0{seqan3::ungapped{5}}; // represents "11111", i.e. ungapped 5-mer
seqan3::debug_stream << s0 << '\n'; // prints "[1,1,1,1,1]"
seqan3::debug_stream << std::ranges::size(s0) << '\n'; // prints "5"
seqan3::shape s1{seqan3::bin_literal{0b101}}; // represents "101", i.e. gapped 3-mer
seqan3::debug_stream << s1 << '\n'; // prints "[1,0,1]"
seqan3::debug_stream << std::ranges::size(s1) << '\n'; // prints "3"
seqan3::shape s2{0b101_shape}; // Same as previous
seqan3::debug_stream << s2 << '\n'; // prints "[1,0,1]"
seqan3::debug_stream << std::ranges::size(s2) << '\n'; // prints "3"
}
seqan3::shape
A class that defines which positions of a pattern to hash.
Definition shape.hpp:57
shape.hpp
Provides seqan3::shape.
seqan3::bin_literal
A strong type of underlying type uint64_t that represents the shape in binary representation.
Definition shape.hpp:31
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
#include <seqan3/search/search.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4_vector> genomes{"CGCTGTCTGAAGGATGAGTGTCAGCCAGTGTA"_dna4,
"ACCCGATGAGCTACCCAGTAGTCGAACTG"_dna4,
"GGCCAGACAACCCGGCGCTAATGCACTCA"_dna4};
std::vector<seqan3::dna4_vector> queries{"GCT"_dna4, "ACCC"_dna4};
// build an FM index
seqan3::fm_index index{genomes};
auto results = seqan3::search(queries, index);
// search for the queries "GCT" and "ACCC"
for (auto && result : results)
seqan3::debug_stream << result << '\n';
// This should result in:
// <query_id:0, reference_id:0, reference_pos:1>
// <query_id:0, reference_id:1, reference_pos:9>
// <query_id:0, reference_id:2, reference_pos:16>
// <query_id:1, reference_id:1, reference_pos:0>
// <query_id:1, reference_id:1, reference_pos:12>
// <query_id:1, reference_id:2, reference_pos:9>
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/fm_index/all.hpp>
#include <seqan3/search/search.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna4_vector> genomes{"CGCTGTCTGAAGGATGAGTGTCAGCCAGTGTA"_dna4,
"ACCCGATGAGCTACCCAGTAGTCGAACTG"_dna4,
"GGCCAGACAACCCGGCGCTAATGCACTCA"_dna4};
std::vector<seqan3::dna4_vector> queries{"GCT"_dna4, "ACCC"_dna4};
// build an FM index
seqan3::fm_index index{genomes};
seqan3::configuration const config = seqan3::search_cfg::on_result{[](auto && result)
{
seqan3::debug_stream << result << '\n';
}};
// The following does not return anything but calls the lambda from above instead:
seqan3::search(queries, index, config);
// This results in:
// <query_id:0, reference_id:0, reference_pos:1>
// <query_id:0, reference_id:1, reference_pos:9>
// <query_id:0, reference_id:2, reference_pos:16>
// <query_id:1, reference_id:1, reference_pos:0>
// <query_id:1, reference_id:1, reference_pos:12>
// <query_id:1, reference_id:2, reference_pos:9>
}
// 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/core/debug_stream.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
using namespace seqan3::literals;
int main()
{
std::vector<seqan3::dna4> text{"ACGTAGC"_dna4};
auto hashes = text | seqan3::views::kmer_hash(seqan3::shape{seqan3::ungapped{3}});
seqan3::debug_stream << hashes << '\n'; // [6,27,44,50,9]
seqan3::debug_stream << (text | seqan3::views::kmer_hash(seqan3::ungapped{3})) << '\n'; // [6,27,44,50,9]
seqan3::debug_stream << (text | seqan3::views::kmer_hash(0b101_shape)) << '\n'; // [2,7,8,14,1]
// Attention: the Shape is defined from right to left!
// The mask 0b11111101 applied to "AGAAAATA" ("A.AAAATA") will yield
// the same hash value as mask 0b1111111 applied to "AAAAATA".
{
auto text1 = "AGAAAATA"_dna4;
auto text2 = "AAAAATA"_dna4;
seqan3::debug_stream << (text1 | seqan3::views::kmer_hash(0b1111'1101_shape)) << '\n'; // [12]
seqan3::debug_stream << (text2 | seqan3::views::kmer_hash(0b111'1111_shape)) << '\n'; // [12]
}
}
// 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/views/complement.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/search/views/minimiser.hpp>
using namespace seqan3::literals;
int main()
{
std::vector<seqan3::dna4> text{"ACGTAGC"_dna4};
auto hashes = text | seqan3::views::kmer_hash(seqan3::shape{seqan3::ungapped{3}});
seqan3::debug_stream << hashes << '\n'; // [6,27,44,50,9]
auto minimiser = hashes | seqan3::views::minimiser(4);
seqan3::debug_stream << minimiser << '\n'; // [6,9]
// kmer_hash with gaps, hashes: [2,7,8,14,1], minimiser: [2,1]
seqan3::debug_stream << (text | seqan3::views::kmer_hash(0b101_shape) | seqan3::views::minimiser(4)) << '\n';
/* Minimiser view with two ranges
* The second range defines the hash values from the reverse complement, the second reverse is necessary to put the
* hash values in the correct order. For the example here:
* ACGTAGC | seqan3::views::complement => TGCATCG
* | std::views::reverse => GCTACGT
* | seqan3::views::kmer_hash(seqan3::ungapped{3}) => [39 (for GCA), 28 (for CTA), 49 (for TAC),
* 6 (for ACG), 27 (for CGT)]
* "GCA" is not the reverse complement from the first k-mer in "ACGTAGC", which is "ACG", but "CGT" is.
* Therefore, a second reverse is necessary to find the smallest value between the original sequence and its
* reverse complement.
*/
auto reverse_complement_hashes = text | seqan3::views::complement | std::views::reverse
| seqan3::views::kmer_hash(seqan3::ungapped{3}) | std::views::reverse;
seqan3::debug_stream << reverse_complement_hashes << '\n'; // [27,6,49,28,39]
auto minimiser2 = seqan3::detail::minimiser_view{hashes, reverse_complement_hashes, 4};
seqan3::debug_stream << minimiser2 << '\n'; // [6,6]
}
seqan3::views::minimiser
constexpr auto minimiser
Computes minimisers for a range of comparable values. A minimiser is the smallest value in a window.
Definition minimiser.hpp:584
minimiser.hpp
Provides seqan3::views::minimiser.
// 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/core/debug_stream.hpp>
#include <seqan3/search/views/minimiser_hash.hpp>
using namespace seqan3::literals;
int main()
{
std::vector<seqan3::dna4> text{"CCACGTCGACGGTT"_dna4};
// Here a consecutive shape with size 4 (so the k-mer size is 4) and a window size of 8 is used. The seed is set
// to 0, so lexicographical ordering is used for demonstration purposes.
auto minimisers =
text
| seqan3::views::minimiser_hash(seqan3::shape{seqan3::ungapped{4}}, seqan3::window_size{8}, seqan3::seed{0});
seqan3::debug_stream << minimisers << '\n';
// This leads to [27,97,26,22,5] representing the k-mers [ACGT, CGAC, ACGG, accg, aacc], smaller case k-mers are
// coming from the reverse strand.
// Here a gapped shape with size 5 (and a k-mer size of 3) and a window size of 8 is used. The seed is set
// to 0, so lexicographical ordering is used for demonstration purposes.
auto minimisers2 = text | seqan3::views::minimiser_hash(0b1'0101_shape, seqan3::window_size{8}, seqan3::seed{0});
seqan3::debug_stream << minimisers2 << '\n';
// This leads to [9, 18, 7, 6] representing the k-mers [A.G.C, C.A.G, a.c.t, a.c.g]
}
seqan3::views::minimiser_hash
constexpr auto minimiser_hash
Computes minimisers for a range with a given shape, window size and seed.
Definition minimiser_hash.hpp:190
minimiser_hash.hpp
Provides seqan3::views::minimiser_hash.
seqan3::seed
strong_type for seed.
Definition minimiser_hash.hpp:22
// 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
int main()
{
return 0;
}
// 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 <ranges>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna4_vector s{"ACTTTGATAA"_dna4};
using iterator = seqan3::dna4_vector::iterator;
auto v1 = std::ranges::subrange<iterator, iterator>{std::ranges::begin(s) + 2, std::ranges::end(s)}
| seqan3::views::to_char; // == "TTTGATAA"
seqan3::debug_stream << v1 << '\n';
}
// 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 <gtest/gtest.h>
#include <seqan3/test/simd_utility.hpp>
#include <seqan3/utility/simd/all.hpp>
TEST(simd, simd_eq)
{
using int16x8_t = seqan3::simd::simd_type_t<int16_t, 8u>;
int16x8_t a{4, 3, 2, 1, 0, -1, -2, -3};
SIMD_EQ(a, int16x8_t{4, 3, 2, 1, 0, -1, -2, -3});
}
// 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 <gtest/gtest.h>
#include <fstream>
#include <seqan3/test/tmp_directory.hpp>
TEST(snippet_tmp_directory, tmp_directory_)
{
// create a directory folder
seqan3::test::tmp_directory tmp{};
// Some function that should creates temporary files and removes them again
{
std::ofstream ofs{tmp.path() / "somefile.txt"};
ofs << "Hello World!";
ofs.close();
std::filesystem::remove(tmp.path() / "somefile.txt");
}
// check that everything was cleanup properly
EXPECT_TRUE(tmp.empty());
}
// 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/utility/bloom_filter/bloom_filter.hpp>
int main()
{
// Construct a Bloom Filter that contains 8192 bits and 3 hash functions.
seqan3::bloom_filter bf{seqan3::bin_size{8192u}, seqan3::hash_function_count{3}};
// Construct a Bloom Filter that contains 256 KiBits and the default of 2
// hash functions.
seqan3::bloom_filter bf2{seqan3::bin_size{1ULL << 20}};
}
bloom_filter.hpp
Provides seqan3::bloom_filter.
seqan3::bloom_filter
The Bloom Filter. A data structure that efficiently answers set-membership queries.
Definition bloom_filter.hpp:86
// 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/utility/bloom_filter/bloom_filter.hpp>
int main()
{
// Construct an uncompressed Bloom Filter.
seqan3::bloom_filter bf{seqan3::bin_size{128u}, seqan3::hash_function_count{3}};
// Fill `bf` with data.
// Construct an immutable, compressed Bloom Filter.
seqan3::bloom_filter<seqan3::data_layout::compressed> bf2{bf};
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/bloom_filter/bloom_filter.hpp>
int main()
{
seqan3::bloom_filter bf{seqan3::bin_size{1024u}};
bf.emplace(126);
bf.emplace(712);
bf.emplace(237);
// Query the Bloom Filter.
// A return of `false` guarantees the query not being present in the Bloom Filter.
// A return of `true` indicates the (probable) presence of the query in the Bloom Filter.
// Note that there may be false positive results!
bool result = bf.contains(712);
seqan3::debug_stream << result << '\n'; // prints 1
}
seqan3::bloom_filter::contains
bool contains(size_t const value) const noexcept
Check whether a value is present in the Bloom Filter.
Definition bloom_filter.hpp:253
seqan3::bloom_filter::emplace
void emplace(size_t const value) noexcept
Inserts a value into the Bloom Filter.
Definition bloom_filter.hpp:209
// 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/core/debug_stream.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/utility/bloom_filter/bloom_filter.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::bloom_filter bf{seqan3::bin_size{8192u}, seqan3::hash_function_count{2u}};
auto const sequence1 = "ACTGACTGACTGATC"_dna4;
auto const sequence2 = "GTGACTGACTGACTCG"_dna4;
auto const sequence3 = "AAAAAAACGATCGACA"_dna4;
auto kmers = seqan3::views::kmer_hash(seqan3::ungapped{5u});
// Insert all 5-mers of sequence1
for (auto && value : sequence1 | kmers)
bf.emplace(value);
// Insert all 5-mers of sequence3
for (auto && value : sequence3 | kmers)
bf.emplace(value);
// Count all 5-mers of sequence2
seqan3::debug_stream << bf.count(sequence2 | kmers) << '\n'; // 9
}
seqan3::bloom_filter::count
size_t count(value_range_t &&values) const noexcept
Counts the occurrences for all values in a range.
Definition bloom_filter.hpp:285
// 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/utility/bloom_filter/bloom_filter.hpp>
int main()
{
seqan3::bloom_filter bf{seqan3::bin_size{8192u}};
// Insert the values `126`, `712` and `237` into the Bloom Filter.
bf.emplace(126);
bf.emplace(712);
bf.emplace(237);
}
// 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/core/debug_stream.hpp>
#include <seqan3/search/views/kmer_hash.hpp>
#include <seqan3/utility/bloom_filter/bloom_filter.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::bloom_filter bf{seqan3::bin_size{8192u}, seqan3::hash_function_count{2u}};
auto const sequence1 = "ACTGACTGACTGATC"_dna4;
auto const sequence2 = "GTGACTGACTGACTCG"_dna4;
auto const sequence3 = "AAAAAAACGATCGACA"_dna4;
auto kmers = seqan3::views::kmer_hash(seqan3::ungapped{5u});
// Insert all 5-mers of sequence1
for (auto && value : sequence1 | kmers)
bf.emplace(value);
// Insert all 5-mers of sequence3
for (auto && value : sequence3 | kmers)
bf.emplace(value);
// Count all 5-mers of sequence2
seqan3::debug_stream << bf.count(sequence2 | kmers) << '\n'; // 9
// Reset the Bloom Filter
bf.reset();
// After reset, no 5-mers are found
seqan3::debug_stream << bf.count(sequence2 | kmers) << '\n'; // 0
}
seqan3::bloom_filter::reset
void reset() noexcept
Remove all values from the Bloom Filter by setting all bits to 0.
Definition bloom_filter.hpp:232
// 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/utility/char_operations/predicate.hpp>
int main()
{
static_assert(seqan3::is_eof(EOF));
static_assert(!seqan3::is_eof('C'));
static_assert(seqan3::is_cntrl('\0'));
static_assert(seqan3::is_print(' '));
static_assert(seqan3::is_space('\n'));
static_assert(seqan3::is_blank('\t'));
static_assert(seqan3::is_graph('%'));
static_assert(seqan3::is_punct(':'));
static_assert(seqan3::is_alnum('9'));
static_assert(seqan3::is_alpha('z'));
static_assert(seqan3::is_upper('K'));
static_assert(seqan3::is_lower('a'));
static_assert(seqan3::is_digit('1'));
static_assert(seqan3::is_xdigit('e'));
}
seqan3::is_eof
constexpr auto is_eof
Checks whether a given letter is equal to the EOF constant defined in <cstdio>.
Definition predicate.hpp:72
seqan3::is_digit
constexpr auto is_digit
Checks whether c is a digital character.
Definition predicate.hpp:259
seqan3::is_alpha
constexpr auto is_alpha
Checks whether c is a graphic character.
Definition predicate.hpp:211
seqan3::is_print
constexpr auto is_print
Checks whether c is a printable character.
Definition predicate.hpp:101
seqan3::is_space
constexpr auto is_space
Checks whether c is a space character.
Definition predicate.hpp:122
seqan3::is_xdigit
constexpr auto is_xdigit
Checks whether c is a hexadecimal character.
Definition predicate.hpp:277
seqan3::is_upper
constexpr auto is_upper
Checks whether c is a upper case character.
Definition predicate.hpp:227
seqan3::is_cntrl
constexpr auto is_cntrl
Checks whether c is a control character.
Definition predicate.hpp:87
seqan3::is_lower
constexpr auto is_lower
Checks whether c is a lower case character.
Definition predicate.hpp:243
// 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/utility/char_operations/predicate.hpp>
int main()
{
seqan3::is_char<'C'>('C'); // returns true
constexpr auto my_check = seqan3::is_char<'C'>;
my_check('c'); // returns false, because case is different
}
// 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/utility/char_operations/predicate.hpp>
int main()
{
seqan3::is_in_interval<'A', 'G'>('C'); // returns true
constexpr auto my_check = seqan3::is_in_interval<'A', 'G'>;
my_check('H'); // returns false
}
seqan3::is_in_interval
constexpr auto is_in_interval
Checks whether a given letter is in the specified interval.
Definition predicate.hpp:44
// 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 <iostream>
#include <seqan3/utility/char_operations/predicate.hpp>
int main()
{
char chr{'1'};
constexpr auto my_cond = seqan3::is_char<'%'> || seqan3::is_digit;
bool is_percent = my_cond(chr);
std::cout << std::boolalpha << is_percent << '\n'; // true
}
// 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 <iostream>
#include <vector>
#include <seqan3/utility/container/aligned_allocator.hpp>
size_t memory_alignment(void * value, size_t alignment)
{
return (reinterpret_cast<size_t>(value) & (alignment - 1));
}
int main()
{
// 128-byte memory aligned and 16bit = 2byte address width for each element
std::vector<int16_t, seqan3::aligned_allocator<int16_t, 128u>> vec128{1, 2, 3, 4, 5};
// vector has no alignment and 16bit = 2byte address width for each element
std::vector<int16_t> vec_unaligned{1, 2, 3, 4, 5};
// 256-byte memory aligned and 32bit = 4byte address width for each element
std::vector<int32_t, seqan3::aligned_allocator<int32_t, 256u>> vec256{1, 2, 3, 4, 5};
for (auto && x : vec128)
std::cout << "Item: " << x << " (" << &x << ", 128-byte aligned offset: " << memory_alignment(&x, 128u)
<< ")\n";
for (auto && x : vec_unaligned)
std::cout << "Item: " << x << " (" << &x << ", unaligned start: " << memory_alignment(&x, 128u) << ")\n";
for (auto && x : vec256)
std::cout << "Item: " << x << " (" << &x << ", 256-byte aligned offset: " << memory_alignment(&x, 256u)
<< ")\n";
}
aligned_allocator.hpp
Provides seqan3::aligned_allocator.
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// begin() refers to the rightmost position.
for (auto it = t1.begin(); it != t1.end(); ++it)
seqan3::debug_stream << *it; // 1111'0001'1101
seqan3::debug_stream << '\n';
}
seqan3::dynamic_bitset
A constexpr bitset implementation with dynamic size at compile time.
Definition dynamic_bitset.hpp:53
seqan3::dynamic_bitset::end
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:581
seqan3::dynamic_bitset::begin
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:554
dynamic_bitset.hpp
A constexpr bitset implementation with dynamic size at compile time.
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
seqan3::dynamic_bitset const t2{0b1011'1000};
t1 &= t2;
seqan3::debug_stream << t1 << '\n'; // 1000'1000
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
seqan3::dynamic_bitset const t2{0b1011'1000};
t1 |= t2;
seqan3::debug_stream << t1 << '\n'; // 1011'1100
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
seqan3::dynamic_bitset const t2{0b1011'1000};
t1 ^= t2;
seqan3::debug_stream << t1 << '\n'; // 0011'0100
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"101110001111"}; // Use character literal.
seqan3::dynamic_bitset t2{"000010001111"}; // Leading zeros are kept.
seqan3::debug_stream << t1 << '\n'; // 1011'1000'1111
seqan3::debug_stream << t2 << '\n'; // 0000'1000'1111
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111}; // Use binary literal.
seqan3::dynamic_bitset t2{0b0000'1000'1111}; // Leading zeros are stripped.
seqan3::dynamic_bitset t3{832}; // Use a number.
seqan3::debug_stream << t1 << '\n'; // 1011'1000'1111
seqan3::debug_stream << t2 << '\n'; // 1000'1111
seqan3::debug_stream << t3 << '\n'; // 1101'0000'00
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset const t1{"10001100"};
seqan3::dynamic_bitset t2 = ~t1;
seqan3::debug_stream << t2 << '\n'; // 0111'0011
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.flip();
seqan3::debug_stream << t1 << '\n'; // 0111'0011
}
seqan3::dynamic_bitset::flip
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition dynamic_bitset.hpp:964
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.flip(0);
t1.flip(3);
seqan3::debug_stream << t1 << '\n'; // 1000'0101
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.reset();
seqan3::debug_stream << t1 << '\n'; // 0000'0000
}
seqan3::dynamic_bitset::reset
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition dynamic_bitset.hpp:912
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.reset(2);
t1.reset(3);
seqan3::debug_stream << t1 << '\n'; // 1000'0000
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"1100"};
t1.resize(8); // Enlarge to 8.
seqan3::debug_stream << t1 << '\n'; // 0000'1100
t1.resize(5); // Shrink to 5, last three bits (5, 6, 7) are set to false.
seqan3::debug_stream << t1 << '\n'; // 0110'0
t1.resize(10, true); // Enlarge to 10 and set new bits to true.
seqan3::debug_stream << t1 << '\n'; // 1111'1011'00
}
seqan3::dynamic_bitset::resize
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition dynamic_bitset.hpp:1588
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.set();
seqan3::debug_stream << t1 << '\n'; // 1111'1111
}
seqan3::dynamic_bitset::set
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition dynamic_bitset.hpp:856
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1.set(0);
t1.set(2, false);
seqan3::debug_stream << t1 << '\n'; // 1000'1001
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset const t1{"10001100"};
seqan3::dynamic_bitset t2 = t1 << 3;
seqan3::debug_stream << t2 << '\n'; // 0110'0000
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1 <<= 3;
seqan3::debug_stream << t1 << '\n'; // 0110'0000
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset const t1{"10001100"};
seqan3::dynamic_bitset t2 = t1 >> 3;
seqan3::debug_stream << t2 << '\n'; // 0001'0001
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"};
t1 >>= 3;
seqan3::debug_stream << t1 << '\n'; // 0001'0001
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{0b1011'1000'1111};
// Positions are 0-based and start at the rightmost bit.
for (size_t i = 0; i < t1.size(); ++i)
seqan3::debug_stream << t1[i]; // 1111'0001'1101
seqan3::debug_stream << '\n';
}
seqan3::dynamic_bitset::size
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition dynamic_bitset.hpp:1232
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/dynamic_bitset.hpp>
int main()
{
seqan3::dynamic_bitset t1{"10001100"}; // Construct from string.
seqan3::dynamic_bitset const t2{0b1011'1000}; // Construct from binary literal or integer.
seqan3::debug_stream << t1 << '\n'; // Debug printing inserts separators: 1000'1100
std::cout << t2 << '\n'; // Standard printing does not: 10111000
t1 &= t2; // Assign t1 the result of a binary AND of t1 and t2.
seqan3::debug_stream << t1 << '\n'; // 1000'1000
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/container/small_string.hpp>
int main()
{
constexpr seqan3::small_string sm{"hello"}; // construct from string literal at compile time!
static_assert(sm[0] == 'h'); // This way I can also test it at compile-time
seqan3::debug_stream << sm.size() << '\n'; // prints 5! (the null character is only stored internally)
// conversion to a normal string:
std::string sm_string{sm.str()};
// access data directly with a pointer to the underlying zero-terminated array:
char const * sm_cstr{sm.c_str()};
seqan3::debug_stream << sm << sm_string << sm_cstr << '\n'; // prints "hellohellohello"
}
seqan3::small_string
Implements a small string that can be used for compile time computations.
Definition small_string.hpp:43
seqan3::small_string::str
std::string str() const
Returns the content represented as std::string.
Definition small_string.hpp:325
seqan3::small_string::c_str
constexpr char const * c_str() const noexcept
Returns the content represented as 0-terminated c-style string.
Definition small_string.hpp:344
seqan3::small_vector::size
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition small_vector.hpp:571
small_string.hpp
A constexpr string implementation to manipulate string literals at compile time.
// 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/core/debug_stream.hpp>
#include <seqan3/utility/math.hpp>
int main()
{
// the same as std::ceil(std::log2(x)), but exact for unsigned integers
seqan3::debug_stream << "ceil_log2(2^0 + 0): " << seqan3::detail::ceil_log2(1u) << '\n'; // 0u
seqan3::debug_stream << "ceil_log2(2^1 + 0): " << seqan3::detail::ceil_log2(2u) << '\n'; // 1u
seqan3::debug_stream << "ceil_log2(2^1 + 1): " << seqan3::detail::ceil_log2(3u) << '\n'; // 2u
seqan3::debug_stream << "ceil_log2(2^2 + 0): " << seqan3::detail::ceil_log2(4u) << '\n'; // 2u
seqan3::debug_stream << "ceil_log2(2^2 + 1): " << seqan3::detail::ceil_log2(5u) << '\n'; // 3u
seqan3::debug_stream << "ceil_log2(2^2 + 2): " << seqan3::detail::ceil_log2(6u) << '\n'; // 3u
seqan3::debug_stream << "ceil_log2(2^2 + 3): " << seqan3::detail::ceil_log2(7u) << '\n'; // 3u
seqan3::debug_stream << "ceil_log2(2^3 + 0): " << seqan3::detail::ceil_log2(8u) << '\n'; // 3u
seqan3::debug_stream << "ceil_log2(2^3 + 1): " << seqan3::detail::ceil_log2(9u) << '\n'; // 4u
return 0;
}
math.hpp
Provides math related functionality.
// 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/core/debug_stream.hpp>
#include <seqan3/utility/math.hpp>
int main()
{
// the same as std::floor(std::log2(x)), but exact for unsigned integers
seqan3::debug_stream << "floor_log2(2^0 + 0): " << seqan3::detail::floor_log2(1u) << '\n'; // 0u
seqan3::debug_stream << "floor_log2(2^1 + 0): " << seqan3::detail::floor_log2(2u) << '\n'; // 1u
seqan3::debug_stream << "floor_log2(2^1 + 1): " << seqan3::detail::floor_log2(3u) << '\n'; // 1u
seqan3::debug_stream << "floor_log2(2^2 + 0): " << seqan3::detail::floor_log2(4u) << '\n'; // 2u
seqan3::debug_stream << "floor_log2(2^2 + 1): " << seqan3::detail::floor_log2(5u) << '\n'; // 2u
seqan3::debug_stream << "floor_log2(2^2 + 2): " << seqan3::detail::floor_log2(6u) << '\n'; // 2u
seqan3::debug_stream << "floor_log2(2^2 + 3): " << seqan3::detail::floor_log2(7u) << '\n'; // 2u
seqan3::debug_stream << "floor_log2(2^3 + 0): " << seqan3::detail::floor_log2(8u) << '\n'; // 3u
seqan3::debug_stream << "floor_log2(2^3 + 1): " << seqan3::detail::floor_log2(9u) << '\n'; // 3u
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/math.hpp>
int main()
{
// Uses specialisation for signed integers.
seqan3::debug_stream << seqan3::pow(2, 3u) << '\n'; // Prints 8
seqan3::debug_stream << seqan3::pow(-2, 3u) << '\n'; // Prints -8
// Uses specialisation for unsigned integers.
seqan3::debug_stream << seqan3::pow(2u, 3u) << '\n'; // Prints 8
// Uses `std::pow`.
seqan3::debug_stream << seqan3::pow(2, 3) << '\n'; // Prints 8
seqan3::debug_stream << seqan3::pow(2u, 3) << '\n'; // Prints 8
seqan3::debug_stream << seqan3::pow(2.0, 3) << '\n'; // Prints 8
// 5^25 should be 298023223876953125.
seqan3::debug_stream << seqan3::pow(5u, 25u) << '\n'; // Prints 298023223876953125
seqan3::debug_stream << static_cast<uint64_t>(std::pow(5u, 25u)) << '\n'; // Prints 298023223876953152 (wrong!)
}
seqan3::pow
base_t pow(base_t base, exp_t exp)
Computes the value of base raised to the power exp.
Definition math.hpp:120
std::pow
T pow(T... args)
// 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/utility/simd/detail/builtin_simd.hpp>
// 8x 16bit integers = 128bit
using int16x8_t = seqan3::detail::builtin_simd<int16_t, 8u>::type; // sse4
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
int main()
{
constexpr auto max_length = seqan3::detail::default_simd_max_length<seqan3::detail::default_simd_backend>;
using uint8_simd_t = seqan3::simd::simd_type_t<uint8_t, max_length == 0 ? 1 : max_length>;
uint8_simd_t a = seqan3::fill<uint8_simd_t>(4);
uint8_simd_t b = seqan3::fill<uint8_simd_t>(5);
uint8_simd_t c = a + b;
seqan3::debug_stream << c << "\n"; // [9,9,9,9,9,9,9,9]
return 0;
}
// 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/utility/simd/detail/builtin_simd.hpp>
using int8x16_t = seqan3::detail::builtin_simd<int8_t, 16>::type;
static_assert(seqan3::detail::is_builtin_simd<int8x16_t>::value);
static_assert(!seqan3::detail::is_builtin_simd<int8_t>::value);
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using uint16x8_t = seqan3::simd::simd_type_t<uint16_t, 8>;
int main()
{
uint16x8_t a = seqan3::fill<uint16x8_t>(4);
seqan3::debug_stream << a << "\n"; // [4,4,4,4,4,4,4,4]
// or:
uint16x8_t b = seqan3::simd::fill<uint16x8_t>(4);
seqan3::debug_stream << b << "\n"; // [4,4,4,4,4,4,4,4]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using uint16x8_t = seqan3::simd::simd_type_t<uint16_t, 8>;
int main()
{
uint16x8_t a = seqan3::iota<uint16x8_t>(1);
seqan3::debug_stream << a << "\n"; // [1,2,3,4,5,6,7,8]
// or:
uint16x8_t b = seqan3::simd::iota<uint16x8_t>(1);
seqan3::debug_stream << b << "\n"; // [1,2,3,4,5,6,7,8]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using uint16x8_t = seqan3::simd::simd_type_t<uint16_t, 8>;
int main()
{
uint16x8_t a = seqan3::fill<uint16x8_t>(4);
uint16x8_t b = seqan3::simd::fill<uint16x8_t>(5); // you can also explicitly use simd::
uint16x8_t c = a + b;
seqan3::debug_stream << c << "\n"; // [9,9,9,9,9,9,9,9]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using int16x8_t = seqan3::simd::simd_type_t<int16_t, 8>;
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using uint16x8_t = seqan3::simd::simd_type_t<uint16_t, 8>;
int main()
{
std::vector<uint16_t> memory{0, 1, 2, 3, 4, 5, 6, 7};
uint16x8_t a = seqan3::simd::load<uint16x8_t>(memory.data());
seqan3::debug_stream << a << '\n'; // [0,1,2,3,4,5,6,7]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
using uint16x8_t = seqan3::simd::simd_type_t<uint16_t, 8>;
int main()
{
uint16x8_t a = seqan3::simd::iota<uint16x8_t>(0);
std::vector<uint16_t> memory(seqan3::simd::simd_traits<uint16x8_t>::length);
seqan3::simd::store(memory.data(), a);
seqan3::debug_stream << memory << '\n'; // [0,1,2,3,4,5,6,7]
return 0;
}
// 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/utility/simd/all.hpp>
using uint16x8_t = seqan3::simd::simd_type_t<uint16_t, 8>;
static_assert(std::is_same_v<seqan3::simd::simd_traits<uint16x8_t>::scalar_type, uint16_t>);
static_assert(seqan3::simd::simd_traits<uint16x8_t>::length == 8);
static_assert(seqan3::simd::simd_traits<uint16x8_t>::max_length == 16);
// 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 <array>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using uint8x4_t = seqan3::simd::simd_type_t<uint8_t, 4>;
int main()
{
std::array<uint8x4_t, 4> matrix{
{uint8x4_t{0, 1, 2, 3}, uint8x4_t{0, 1, 2, 3}, uint8x4_t{0, 1, 2, 3}, uint8x4_t{0, 1, 2, 3}}};
seqan3::simd::transpose(matrix);
seqan3::debug_stream << matrix[0] << '\n'; // [0,0,0,0]
seqan3::debug_stream << matrix[1] << '\n'; // [1,1,1,1]
seqan3::debug_stream << matrix[2] << '\n'; // [2,2,2,2]
seqan3::debug_stream << matrix[3] << '\n'; // [3,3,3,3]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using int16x8_t = seqan3::simd::simd_type_t<int16_t, 8>;
using int32x4_t = seqan3::simd::simd_type_t<int32_t, 4>;
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int32x4_t b = seqan3::simd::upcast<int32x4_t>(a);
seqan3::debug_stream << b << '\n'; // [0,-1,2,-3]
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
// The simd type with 8 unsigned shorts.
using uint16x8_t = seqan3::simd_type_t<uint16_t, 8>;
int main()
{
// Generate ascending simd index.
for (auto && simd_id : seqan3::views::iota_simd<uint16x8_t>(0, 10))
seqan3::debug_stream << simd_id << '\n'; // [0, 0, ..., 0], [1, 1, ..., 1], ... [9, 9, ..., 9]
return 0;
}
// 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 <ranges>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
// The simd type with 8 unsigned shorts.
using uint16x8_t = seqan3::simd_type_t<uint16_t, 8>;
int main()
{
// Generate ascending simd index using a iota view in combination with a transform view.
auto simd_iota_view = std::views::iota(0, 10)
| std::views::transform(
[](uint16_t const idx)
{
return seqan3::simd::fill<uint16x8_t>(idx);
});
for (auto && simd_id : simd_iota_view)
seqan3::debug_stream << simd_id << '\n'; // [0, 0, ..., 0], [1, 1, ..., 1], ... [9, 9, ..., 9]
return 0;
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/simd/all.hpp>
#include <seqan3/utility/simd/detail/debug_stream_simd.hpp>
using uint16x8_t = seqan3::simd_type_t<uint16_t, 8>;
int main()
{
using namespace seqan3::literals;
// Adds 7 sequences. The eighth will be set to a default value.
std::vector<seqan3::dna4_vector> batch;
batch.push_back("ACGTACGTACGTACGATCG"_dna4);
batch.push_back("AGTGAGCTACGGACTAGCTACGACT"_dna4);
batch.push_back("GACTAGCACGAGCGAGATCG"_dna4);
batch.push_back("GGATCGACGGACTAGC"_dna4);
batch.push_back("ACGTACGACGGACGTACGAGCGAGCTACGAGC"_dna4);
batch.push_back("ACGATCGACGACTAGCGAC"_dna4);
batch.push_back("GTACGGATGGTAAACCGCACAT"_dna4);
// Applies lazy transformation using `8` as a padding symbol if a sequence ends early.
auto to_soa = batch | seqan3::views::to_simd<uint16x8_t>(8);
size_t chunk_count = 0;
for (auto && chunk : to_soa)
{
seqan3::debug_stream << "Chunk " << chunk_count++ << ":\n";
for (auto & vec : chunk)
seqan3::debug_stream << vec << '\n';
seqan3::debug_stream << '\n';
}
return 0;
}
// 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/core/debug_stream.hpp>
#include <seqan3/utility/tuple/pod_tuple.hpp>
int main()
{
seqan3::pod_tuple<int, float> tuple1{3, 4.7};
static_assert(std::is_standard_layout_v<seqan3::pod_tuple<int, float>>);
static_assert(seqan3::trivial<seqan3::pod_tuple<int, float>>);
seqan3::debug_stream << std::get<int>(tuple1) << '\n'; // 3
// template parameters are automatically deduced:
seqan3::pod_tuple tuple2{17, 3.7f, 19l};
seqan3::debug_stream << std::get<0>(tuple2) << '\n'; // 17
auto [i, f, l] = tuple2; // creates an int i with value 17, float f...
seqan3::debug_stream << i << ',' << f << ',' << l << '\n'; // 17,3.7,19
}
std::is_standard_layout_v
T is_standard_layout_v
pod_tuple.hpp
Provides seqan3::pod_tuple.
seqan3::pod_tuple
Definition pod_tuple.hpp:27
// 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 <string>
#include <seqan3/utility/tuple/split.hpp>
int main()
{
// Split at position 2.
std::tuple<int, char, float, std::string> t{1, 'c', 0.3, "hello"};
auto [left, right] = seqan3::tuple_split<2>(t);
static_assert(std::same_as<decltype(left), std::tuple<int, char>>);
static_assert(std::same_as<decltype(right), std::tuple<float, std::string>>);
// Split at position 0.
auto [left1, right1] = seqan3::tuple_split<0>(t);
static_assert(std::same_as<decltype(left1), std::tuple<>>);
static_assert(std::same_as<decltype(right1), std::tuple<int, char, float, std::string>>);
// Split at position 4.
auto [left2, right2] = seqan3::tuple_split<4>(t);
static_assert(std::same_as<decltype(left2), std::tuple<int, char, float, std::string>>);
static_assert(std::same_as<decltype(right2), std::tuple<>>);
}
seqan3::tuple_split
constexpr auto tuple_split(tuple_t< ts... > const &t)
Splits a tuple like data structure at the given position.
Definition split.hpp:87
split.hpp
Provides seqan3::tuple_split.
// 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 <type_traits>
#include <seqan3/utility/type_list/detail/type_list_algorithm.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
namespace incomplete
{
struct type;
} // namespace incomplete
// With c++20 you could also write it like this
// auto fn = []<typename type>(std::type_identity<type>)
// {
// ...
// };
auto fn = [](auto id)
{
// id is of type std::type_identity<type>
using id_t = decltype(id);
using type = typename id_t::type;
static_assert(std::is_same_v<id_t, std::type_identity<type>>, "id is of type std::type_identity<type>");
if constexpr (std::is_same_v<type, bool>)
return true;
else if constexpr (std::is_same_v<type, int>)
return true;
else if constexpr (std::is_same_v<type, float>)
return true;
else if constexpr (std::is_same_v<type, incomplete::type>)
return false;
};
static_assert(seqan3::detail::all_of<seqan3::type_list<int, float, bool>>(fn)); // evaluates to true
static_assert(!seqan3::detail::all_of<seqan3::type_list<int, float, bool, incomplete::type>>(fn)); // evaluates to false
type_list_algorithm.hpp
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
// 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 <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/type_list/detail/type_list_algorithm.hpp>
#include <seqan3/utility/type_list/type_list.hpp>
namespace incomplete
{
struct type;
} // namespace incomplete
int main()
{
// With c++20 you could also write it like this
// auto fn = []<typename type>(std::type_identity<type>)
// {
// ...
// };
auto fn = [](auto id)
{
// id is of type std::type_identity<type>
using id_t = decltype(id);
using type = typename id_t::type;
static_assert(std::is_same_v<id_t, std::type_identity<type>>, "id is of type std::type_identity<type>");
if constexpr (std::is_same_v<type, bool>)
seqan3::debug_stream << "bool";
else if constexpr (std::is_same_v<type, int>)
seqan3::debug_stream << "int";
else if constexpr (std::is_same_v<type, float>)
seqan3::debug_stream << "float";
else if constexpr (std::is_same_v<type, incomplete::type>)
seqan3::debug_stream << "incomplete::type";
seqan3::debug_stream << ", ";
};
// prints each type name, i.e. "int, float, bool, incomplete::type, \n"
using types = seqan3::type_list<int, float, bool, incomplete::type>;
seqan3::detail::for_each<types>(fn);
seqan3::debug_stream << "\n";
// is the same as explicitly writing
fn(std::type_identity<int>{});
fn(std::type_identity<float>{});
fn(std::type_identity<bool>{});
fn(std::type_identity<incomplete::type>{});
seqan3::debug_stream << "\n";
return 0;
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, double>;
// Look at the 2nd element.
static_assert(std::same_as<float, seqan3::list_traits::at<1, list_t>>);
// Look at the last element.
static_assert(std::same_as<double, seqan3::list_traits::at<-1, list_t>>);
}
seqan3::list_traits::at
typename decltype(detail::at< idx >(list_t{}))::type at
Return the type at given index from the type list.
Definition type_list/traits.hpp:276
traits.hpp
Provides traits for seqan3::type_list.
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int, float>;
// Access the last value (float) with seqan3::list_traits::back
static_assert(std::same_as<float, seqan3::list_traits::back<list_t>>);
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool>;
using list_t2 = seqan3::type_list<double, char, int>;
using list_t3 = seqan3::type_list<int, int>;
static_assert(std::same_as<seqan3::list_traits::concat<list_t, list_t2, list_t3>,
seqan3::type_list<int, float, bool, double, char, int, int, int>>);
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
static_assert(seqan3::list_traits::contains<double, list_t> == false); // Is type double in type_list list_t?
static_assert(seqan3::list_traits::contains<float, list_t> == true); // Is type float in type_list list_t?
}
seqan3::list_traits::contains
constexpr bool contains
Whether a type occurs in a type list or not.
Definition type_list/traits.hpp:249
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
// Count the number of type int in list_t.
static_assert(seqan3::list_traits::count<int, list_t> == 2);
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
// Drop the first two types in list_t.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::list_traits::drop<2, list_t>>);
}
seqan3::list_traits::drop
typename decltype(detail::split_after< i >(list_t{}))::second_type drop
Return a seqan3::type_list of the types in the input type list, except the first n.
Definition type_list/traits.hpp:392
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
static_assert(std::same_as<seqan3::type_list<float, bool, int>, seqan3::list_traits::drop_front<list_t>>);
}
seqan3::list_traits::drop_front
decltype(detail::drop_front(list_t{})) drop_front
Return a seqan3::type_list of all the types in the type list, except the first.
Definition type_list/traits.hpp:356
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
// Drop the last two types in list_t.
static_assert(std::same_as<seqan3::type_list<int, float>, seqan3::list_traits::drop_last<2, list_t>>);
}
seqan3::list_traits::drop_last
take< size< list_t > - i, list_t > drop_last
Return a seqan3::type_list of the types the input type list, except the last n.
Definition type_list/traits.hpp:428
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool>;
// Double is not in list_t so find returns -1. However, bool is in the type list so find will return 2.
static_assert(seqan3::list_traits::find<double, list_t> == -1);
static_assert(seqan3::list_traits::find<bool, list_t> == 2);
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, double>;
// None of the types in list_t is a pointer so find_if returns -1. However, int and bool are both integral,
// so find_if returns 0 for the first occurrence.
static_assert(seqan3::list_traits::find_if<std::is_pointer, list_t> == -1);
static_assert(seqan3::list_traits::find_if<std::is_integral, list_t> == 0);
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int, float>;
static_assert(std::same_as<int, seqan3::list_traits::front<list_t>>); // Check if the first value is int.
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, double>;
// Replace the second element with int.
static_assert(
std::same_as<seqan3::type_list<int, int, bool, double>, seqan3::list_traits::replace_at<int, 1, list_t>>);
}
seqan3::list_traits::replace_at
decltype(detail::replace_at< replace_t, i >(list_t{})) replace_at
Replace the type at the given index with the given type.
Definition type_list/traits.hpp:486
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
static_assert(seqan3::list_traits::size<list_t> == 4);
}
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, double, char, int>;
using split_t = seqan3::list_traits::split_after<3, list_t>;
// Use ::first_type and ::second_type to access the type lists after being split.
static_assert(std::same_as<seqan3::type_list<int, float, bool>, split_t::first_type>);
static_assert(std::same_as<seqan3::type_list<double, char, int>, split_t::second_type>);
}
seqan3::list_traits::split_after
decltype(detail::split_after< i >(list_t{})) split_after
Split a seqan3::type_list into two parts returned as a pair of seqan3::type_list.
Definition type_list/traits.hpp:446
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
// Take the first two types in list_t.
static_assert(std::same_as<seqan3::type_list<int, float>, seqan3::list_traits::take<2, list_t>>);
}
seqan3::list_traits::take
typename decltype(detail::split_after< i >(list_t{}))::first_type take
Return a seqan3::type_list of the first n types in the input type list.
Definition type_list/traits.hpp:374
// 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/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<int, float, bool, int>;
// Take the last two types in list_t.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::list_traits::take_last<2, list_t>>);
}
seqan3::list_traits::take_last
drop< size< list_t > - i, list_t > take_last
Return a seqan3::type_list of the last n types in the input type list.
Definition type_list/traits.hpp:410
// 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 <list>
#include <vector>
#include <seqan3/core/range/type_traits.hpp>
#include <seqan3/utility/type_list/traits.hpp>
int main()
{
using list_t = seqan3::type_list<std::vector<int>, std::vector<float>, std::list<bool>>;
// Transform the types into reference types.
static_assert(std::same_as<seqan3::list_traits::transform<std::ranges::range_reference_t, list_t>,
seqan3::type_list<int &, float &, bool &>>);
}
type_traits.hpp
Provides various transformation traits used by the range module.
list
// 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 <type_traits>
#include <seqan3/utility/type_pack/detail/type_pack_algorithm.hpp>
// With c++20 you could also write it like this
// auto fn = []<typename value_t>(value_t && value)
// {
// ...
// };
auto fn = [](auto value)
{
// id is the original type not wrapped in std::type_identity.
using value_t = decltype(value);
if constexpr (std::is_same_v<value_t, bool>)
return value == false;
else if constexpr (std::is_same_v<value_t, int>)
return value == 3;
else if constexpr (std::is_same_v<value_t, double>)
return value - 1.2 < 0.00001;
else
return false;
};
static_assert(seqan3::detail::all_of(fn, 3, 1.2, false)); // evaluates to true
static_assert(!seqan3::detail::all_of(fn, 3, 1.2, false, "something else")); // evaluates to false
type_pack_algorithm.hpp
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
// 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 <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/type_pack/detail/type_pack_algorithm.hpp>
int main()
{
auto fn = [](auto && a)
{
seqan3::debug_stream << a;
};
// prints each argument, i.e. "0, 1, 2, 3\n"
seqan3::detail::for_each(fn, 0, ", ", 1.0, ", ", std::string{"2, 3"}, '\n');
// is the same as explicitly writing
fn(0);
fn(", ");
fn(1.0);
fn(", ");
fn(std::string{"2, 3"});
fn('\n');
return 0;
}
// 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/utility/type_pack/traits.hpp>
int main()
{
// Look at the 2nd element.
static_assert(std::same_as<float, seqan3::pack_traits::at<1, int, float, bool, double>>);
// Look at the last element.
static_assert(std::same_as<double, seqan3::pack_traits::at<-1, int, float, bool, double>>);
}
seqan3::pack_traits::at
typename decltype(detail::at< idx, pack_t... >())::type at
Return the type at given index from the type pack.
Definition type_pack/traits.hpp:245
traits.hpp
Provides various traits for template packs.
// 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/utility/type_pack/traits.hpp>
int main()
{
// Check if the last value is float.
static_assert(std::same_as<float, seqan3::pack_traits::back<int, float, bool, int, float>>);
}
// 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/utility/type_pack/traits.hpp>
int main()
{
// Count the number of type int in the pack.
static_assert(seqan3::pack_traits::count<int, int, float, bool, int> == 2);
}
seqan3::pack_traits::count
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition type_pack/traits.hpp:161
// 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/utility/type_pack/traits.hpp>
int main()
{
// Drop the first two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::drop<2, float, double, bool, int>>);
}
seqan3::pack_traits::drop
typename decltype(detail::split_after< i, pack_t... >(type_list<>{}))::second_type drop
Return a seqan3::type_list of the types in the type pack, except the first n.
Definition type_pack/traits.hpp:367
// 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/utility/type_pack/traits.hpp>
int main()
{
// Return the a type list of the pack without the first type.
static_assert(
std::same_as<seqan3::type_list<float, bool, int>, seqan3::pack_traits::drop_front<int, float, bool, int>>);
}
seqan3::pack_traits::drop_front
typename decltype(detail::drop_front< pack_t... >())::type drop_front
Return a seqan3::type_list of all the types in the type pack, except the first.
Definition type_pack/traits.hpp:305
// 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/utility/type_pack/traits.hpp>
int main()
{
// Drop the last two types in the pack.
static_assert(
std::same_as<seqan3::type_list<int, float>, seqan3::pack_traits::drop_last<2, int, float, bool, int>>);
}
seqan3::pack_traits::drop_last
take< size< pack_t... > - i, pack_t... > drop_last
Return a seqan3::type_list of the types the type pack, except the last n.
Definition type_pack/traits.hpp:403
// 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/utility/type_pack/traits.hpp>
int main()
{
// Double is not in the pack so find returns -1. However, bool is in the pack so find will return 2.
static_assert(seqan3::pack_traits::find<double, int, float, bool> == -1);
static_assert(seqan3::pack_traits::find<bool, int, float, bool> == 2);
}
seqan3::pack_traits::find
constexpr ptrdiff_t find
Get the index of the first occurrence of a type in a pack.
Definition type_pack/traits.hpp:179
// 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/utility/type_pack/traits.hpp>
int main()
{
// None of the types in t is a pointer so find_if returns -1. However, int and bool are both integral,
// so find_if returns 0 for the first occurrence.
static_assert(seqan3::pack_traits::find_if<std::is_pointer, int, float, double> == -1);
static_assert(seqan3::pack_traits::find_if<std::is_integral, int, float, double> == 0);
}
seqan3::pack_traits::find_if
constexpr ptrdiff_t find_if
Get the index of the first type in a pack that satisfies the given predicate.
Definition type_pack/traits.hpp:202
// 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/utility/type_pack/traits.hpp>
int main()
{
// Check if the first value is int.
static_assert(std::same_as<int, seqan3::pack_traits::front<int, float, bool, int, float>>);
}
// 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/utility/type_pack/traits.hpp>
int main()
{
// Replace the second element of the type pack with int.
static_assert(std::same_as<seqan3::type_list<int, int, bool, double>,
seqan3::pack_traits::replace_at<int, 1, int, float, bool, double>>);
}
seqan3::pack_traits::replace_at
decltype(detail::replace_at< replace_t, i, pack_t... >(std::make_index_sequence< size< pack_t... > >{})) replace_at
Replace the type at the given index with the given type.
Definition type_pack/traits.hpp:440
// 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/utility/type_pack/traits.hpp>
int main()
{
// Get the size of the pack.
static_assert(seqan3::pack_traits::size<int, float, bool, int> == 4);
}
// 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/utility/type_pack/traits.hpp>
int main()
{
using split_t = seqan3::pack_traits::split_after<3, int, float, bool, double, char, int>;
// Use ::first_type and ::second_type to access the type lists after being split.
static_assert(std::same_as<seqan3::type_list<int, float, bool>, split_t::first_type>);
static_assert(std::same_as<seqan3::type_list<double, char, int>, split_t::second_type>);
}
seqan3::pack_traits::split_after
decltype(detail::split_after< i, pack_t... >(type_list<>{})) split_after
Split a type pack into two parts returned as a pair of seqan3::type_list.
Definition type_pack/traits.hpp:421
// 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/utility/type_pack/traits.hpp>
int main()
{
// Take the first two types in the pack.
static_assert(std::same_as<seqan3::type_list<int, float>, seqan3::pack_traits::take<2, int, float, bool, double>>);
}
seqan3::pack_traits::take
typename decltype(detail::split_after< i, pack_t... >(type_list<>{}))::first_type take
Return a seqan3::type_list of the first n types in the type pack.
Definition type_pack/traits.hpp:349
// 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/utility/type_pack/traits.hpp>
int main()
{
// Take the last two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::take_last<2, int, float, bool, int>>);
}
seqan3::pack_traits::take_last
drop< size< pack_t... > - i, pack_t... > take_last
Return a seqan3::type_list of the last n types in the type pack.
Definition type_pack/traits.hpp:385
// 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 <list>
#include <vector>
#include <seqan3/core/range/type_traits.hpp>
#include <seqan3/utility/type_pack/traits.hpp>
int main()
{
// Transform the types in the pack into reference types.
static_assert(std::same_as<
seqan3::pack_traits::
transform<std::ranges::range_reference_t, std::vector<int>, std::vector<float>, std::list<bool>>,
seqan3::type_list<int &, float &, bool &>>);
}
// 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 <cassert>
#include <string>
#include <seqan3/utility/type_traits/function_traits.hpp>
std::function my_caller = [](size_t position, std::string & sequence)
{
assert(position < sequence.size());
return sequence[position];
};
using my_function_t = decltype(my_caller);
static_assert(std::same_as<seqan3::function_traits<my_function_t>::result_type, char>);
static_assert(seqan3::function_traits<my_function_t>::argument_count == 2);
static_assert(std::same_as<seqan3::function_traits<my_function_t>::argument_type_at<0>, size_t>);
static_assert(std::same_as<seqan3::function_traits<my_function_t>::argument_type_at<1>, std::string &>);
cassert
function_traits.hpp
Provides various type traits for use on functions.
// 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
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <forward_list> // std::forward_list
#include <ranges> // std::ranges::input_range
#include <vector> // std::vector
#include <seqan3/core/range/type_traits.hpp> // seqan3::size_type_t
#include <seqan3/utility/type_traits/lazy_conditional.hpp> // seqan3::lazy_conditional_t
template <std::ranges::input_range rng_t>
void foobar(rng_t && range)
{
#if 0
// The following would fail to compile if rng_t is not sized,
// because std::ranges::range_size_t<rngt_t> needs to be valid
// (independent of whether the condition evaluates to true)
using size_type = std::conditional_t<std::ranges::sized_range<rng_t>,
std::ranges::range_size_t<rng_t>,
void>;
#endif
// This delays instantiation of std::ranges::range_size_t<rngt_t> until after the
// conditional-decision is made:
using size_type = seqan3::detail::lazy_conditional_t<std::ranges::sized_range<rng_t>,
seqan3::detail::lazy<std::ranges::range_size_t, rng_t>,
void>;
// DO SOMETHING with size_type
}
int main()
{
foobar(std::vector<int>{}); // sized
foobar(std::forward_list<int>{}); // not sized
}
#pragma GCC diagnostic pop
std::conditional_t
forward_list
lazy_conditional.hpp
Provides lazy template instantiation traits.
// 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/utility/type_traits/detail/transformation_trait_or.hpp>
template <typename T>
struct A;
template <>
struct A<int>
{
using type = int;
};
// A<unsigned>::type is not defined, thus falling back to `void`
static_assert(std::is_same_v<void, seqan3::detail::transformation_trait_or_t<A<unsigned>, void>>);
// A<int>::type is defined, use A<int>::type
static_assert(std::is_same_v<int, seqan3::detail::transformation_trait_or_t<A<int>, void>>);
transformation_trait_or.hpp
Provides seqan3::detail::transformation_trait_or.
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/chunk.hpp>
#include <seqan3/utility/views/single_pass_input.hpp>
int main()
{
using namespace seqan3::literals;
std::vector<int> sequences{1, 2, 3, 4, 5, 6, 7, 8};
seqan3::debug_stream << (sequences | seqan3::views::chunk(3)) << '\n'; // [[1,2,3],[4,5,6],[7,8]]
// Note the behaviour on pure input ranges:
// When incrementing the chunk view iterator, the former chunk is fully consumed by the iterator.
// In other words, it is ensured that you always start at the beginning of a new chunk.
auto input_view = sequences | seqan3::views::single_pass_input | seqan3::views::chunk(3);
for (auto && val : input_view)
seqan3::debug_stream << "first value in subrange: " << *val.begin() << '\n'; // only access first value of chunk
// prints:
// first value in subrange: 1
// first value in subrange: 4
// first value in subrange: 7
}
// 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/dna15.hpp>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
using namespace seqan3::literals;
seqan3::dna15_vector vec2{"ACYGTN"_dna15};
seqan3::debug_stream << (vec2 | seqan3::views::convert<seqan3::dna5>) << '\n'; // ACNGTN
}
// 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 <ranges>
#include <vector>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/range/to.hpp>
#include <seqan3/utility/views/convert.hpp>
int main()
{
// convert from int to bool
std::vector<int> vec{7, 5, 0, 5, 0, 0, 4, 8, -3};
// pipe notation
seqan3::debug_stream << (vec | seqan3::views::convert<bool>) << '\n'; // [1,1,0,1,0,0,1,1,1]
// combinability
seqan3::debug_stream << (vec | seqan3::views::convert<bool> | std::views::reverse) << '\n'; // [1,1,1,0,0,1,0,1,1]
// function notation and immediate conversion to vector again
auto bool_vec = seqan3::views::convert<bool>(vec) | seqan3::ranges::to<std::vector<bool>>();
seqan3::debug_stream << std::boolalpha << (bool_vec == std::vector<bool>{1, 1, 0, 1, 0, 0, 1, 1, 1})
<< '\n'; // true
}
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/deep.hpp>
namespace my
{
// You can create a permanent alias:
inline auto const deep_reverse = seqan3::views::deep{std::views::reverse};
} // namespace my
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna5_vector> sequences{"AAATTT"_dna5, "CCCGGG"_dna5};
seqan3::debug_stream << (sequences | std::views::reverse) << '\n'; // [CCCGGG,AAATTT]
// These two are equivalent:
seqan3::debug_stream << (sequences | my::deep_reverse) << '\n'; // [TTTAAA,GGGCCC]
seqan3::debug_stream << (sequences | seqan3::views::deep{std::views::reverse}) << '\n'; // [TTTAAA,GGGCCC]
}
seqan3::views::deep
A wrapper type around an existing view adaptor that enables "deep view" behaviour for that view.
Definition deep.hpp:101
deep.hpp
Provides seqan3::views::deep.
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/deep.hpp>
namespace my
{
inline auto const deep_take = seqan3::views::deep{std::views::take};
}
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna5_vector> sequences{"AAATTT"_dna5, "CCCGGG"_dna5};
int i = 3;
// takes `i` as a reference:
seqan3::debug_stream << (sequences | my::deep_take(i)) << '\n'; // [AAA,CCC]
}
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/deep.hpp>
namespace my
{
inline auto const deep_take = seqan3::views::deep{std::views::take};
}
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna5_vector> sequences{"AAATTT"_dna5, "CCCGGG"_dna5};
seqan3::debug_stream << (sequences | std::views::take(1)) << '\n'; // [A,A,A,T,T,T]
seqan3::debug_stream << (sequences | seqan3::views::deep{std::views::take(1)}) << '\n'; // [A,C]
// constructor arguments passed via {} and arguments to underlying view passed via ()
// In this case especially, an alias improves readability:
seqan3::debug_stream << (sequences | my::deep_take(1)) << '\n'; // [A,C]
}
// 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 <ranges>
#include <vector>
#include <seqan3/alphabet/nucleotide/dna5.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/deep.hpp>
namespace my
{
inline auto const deep_take1 = seqan3::views::deep{std::views::take(1)};
}
int main()
{
using namespace seqan3::literals;
std::vector<seqan3::dna5_vector> sequences{"AAATTT"_dna5, "CCCGGG"_dna5};
seqan3::debug_stream << (sequences | std::views::take(1)) << '\n'; // [A,A,A,T,T,T]
seqan3::debug_stream << (sequences | seqan3::views::deep{std::views::take(1)}) << '\n'; // [A,C]
// constructor arguments passed via {} and arguments to underlying view hardcoded inside
// or with an alias defined previously
seqan3::debug_stream << (sequences | my::deep_take1) << '\n'; // [A,C]
}
// 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 <vector>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/alphabet/quality/aliases.hpp> // includes seqan3::dna4q
#include <seqan3/alphabet/quality/phred42.hpp>
#include <seqan3/alphabet/views/to_char.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/elements.hpp>
int main()
{
using namespace seqan3::literals;
// Create a vector of dna4 quality composite alphabet.
std::vector<seqan3::dna4q> qv{{'A'_dna4, '0'_phred42},
{'C'_dna4, '1'_phred42},
{'G'_dna4, '2'_phred42},
{'T'_dna4, '3'_phred42}};
seqan3::debug_stream << (qv | seqan3::views::elements<0> | seqan3::views::to_char) << '\n'; // Prints [A,C,G,T]
seqan3::debug_stream << (qv | seqan3::views::elements<1> | seqan3::views::to_char) << '\n'; // Prints [!,",#,$]
}
// 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 <string>
#include <seqan3/alignment/decorator/gap_decorator.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/enforce_random_access.hpp>
int main()
{
using namespace seqan3::literals;
// A gap decorator is a pseudo random access range using logarithmic time complexity internally.
auto seq = "ACGTACGACT"_dna4;
seqan3::gap_decorator aligned_seq{seq};
// It does not fulfill random access semantics because it does not allow constant time access to arbitrary
// elements in the range. Thus, it is only a bidirectional range by default.
static_assert(std::ranges::bidirectional_range<decltype(aligned_seq)>);
static_assert(!std::ranges::random_access_range<decltype(aligned_seq)>);
// The default interface models at most std::bidirectional_range.
auto it = std::ranges::begin(aligned_seq); // Returned iterator models std::bidirectional_iterator.
std::ranges::advance(it, 3); // Advancing the iterator takes linear time.
seqan3::debug_stream << *it << '\n'; // "T"
// After adapting it with enforce_random_access, the returned range models std::random_access_range.
auto aligned_seq_ra = aligned_seq | seqan3::views::enforce_random_access;
// The pesudo_random_access wrapper returns a view that enforces random_access.
// Note that this does not mean that the semantic requirements have been changed. Only all syntactical
// interfaces for the std::ranges::random_access_range are modeled now by the returned view.
// Access time still depends on the underlying range.
static_assert(std::ranges::random_access_range<decltype(aligned_seq_ra)>);
auto it_ra = std::ranges::begin(aligned_seq_ra); // Returned iterator models std::random_access_iterator.
std::ranges::advance(it_ra, 3); // Advancing the iterator takes now logarithmic time instead linear.
seqan3::debug_stream << *it_ra << '\n'; // "T"
}
enforce_random_access.hpp
Provides seqan3::views::enforce_random_access.
seqan3::views::enforce_random_access
constexpr auto enforce_random_access
A view adaptor that converts a pseudo random access range to a std::ranges::random_access_range.
Definition enforce_random_access.hpp:351
// 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 <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/interleave.hpp>
int main()
{
std::string u{"FOOBARBAXBAT"};
std::string i{"in"};
size_t s = 3;
auto v = u | seqan3::views::interleave(s, i);
seqan3::debug_stream << v << '\n'; // prints FOOinBARinBAXinBAT
}
seqan3::views::interleave
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition interleave.hpp:374
interleave.hpp
Provides seqan3::views::interleave.
// 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 <vector>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/pairwise_combine.hpp>
int main()
{
std::vector vec{'a', 'b', 'c', 'a'};
for (auto res : vec | seqan3::views::pairwise_combine)
{
seqan3::debug_stream << res << '\n';
}
// Possible Output:
// (a,b)
// (a,c)
// (a,a)
// (b,c)
// (b,a)
// (c,a)
}
// 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 <ranges>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/repeat.hpp>
int main()
{
auto v = seqan3::views::repeat('A');
seqan3::debug_stream << *std::ranges::begin(v) << '\n'; // prints 'A'
seqan3::debug_stream << v[12355] << '\n'; // also prints 'A'. It always prints 'A'
v[1345] = 'C';
// Now it always prints 'C'
seqan3::debug_stream << *std::ranges::begin(v) << '\n'; // prints 'C'
seqan3::debug_stream << v[12355] << '\n'; // prints 'C'
}
seqan3::views::repeat
constexpr detail::repeat_fn repeat
A view factory that repeats a given value infinitely.
Definition repeat.hpp:344
repeat.hpp
Provides the seqan3::views::repeat.
// 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 <ranges>
#include <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/repeat_n.hpp>
int main()
{
auto v = seqan3::views::repeat_n(std::string{"foo"}, 5);
seqan3::debug_stream << v.size() << '\n'; // prints 5
seqan3::debug_stream << v << '\n'; // prints ["foo", "foo", "foo", "foo", "foo"]
v[0] = std::string{"foobar"};
// Now it always prints "foobar"
seqan3::debug_stream << *std::ranges::begin(v) << '\n'; // prints "foobar"
seqan3::debug_stream << v.size() << '\n'; // prints 5; Note: the size cannot be changed anymore
}
seqan3::views::repeat_n
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
repeat_n.hpp
Provides seqan3::views::repeat_n.
// 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 <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/single_pass_input.hpp>
int main()
{
std::string str{"hello"};
auto v = str | seqan3::views::single_pass_input;
auto b = v.begin();
seqan3::debug_stream << *b << '\n'; // prints 'h'
seqan3::debug_stream << *(++b) << '\n'; // prints 'e'
seqan3::debug_stream << *(++b) << '\n'; // prints 'l'
seqan3::debug_stream << *(++b) << '\n'; // prints 'l'
seqan3::debug_stream << *(++b) << '\n'; // prints 'o'
}
// 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 <ranges> // provides std::views::reverse
#include <string>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/slice.hpp> // provides views::slice
int main()
{
std::string s{"foobar"};
auto v = s | seqan3::views::slice(1, 4);
seqan3::debug_stream << v << '\n'; // "oob"
auto v2 = s | std::views::reverse | seqan3::views::slice(1, 4);
seqan3::debug_stream << v2 << '\n'; // "abo"
}
// 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 <string>
#include <vector>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/views/type_reduce.hpp>
int main()
{
std::string const vec{"foobar"};
auto v = vec | seqan3::views::type_reduce; // pipe notation; v is of type std::string_view
seqan3::debug_stream << v << '\n'; // "foobar"
std::vector vec2{1, 2, 3};
auto v2 = seqan3::views::type_reduce(vec2); // functional notation; v2 is of type std::span
seqan3::debug_stream << v2 << '\n'; // "[1, 2, 3]"
}
seqan3::views::type_reduce
constexpr auto type_reduce
A view adaptor that behaves like std::views::all, but type erases certain ranges.
Definition type_reduce.hpp:147
type_reduce.hpp
Provides seqan3::views::type_reduce.
Hide me