Loading...
Searching...
No Matches
Sequence Alignment

The alignment module contains concepts, algorithms and classes that are related to the computation of pairwise and multiple sequence alignments. More...

Collaboration diagram for Sequence Alignment:

## Topics

| Aligned Sequence
| Provides seqan3::aligned_sequence, as well as various ranges that model it.
| CIGAR Conversion
| The CIGAR Conversion submodule contains utility functions to convert a CIGAR to an alignment or vice versa.
| Configuration
| Provides configuration elements for the pairwise alignment configuration.
| Decorator
| The decorator submodule contains special SeqAn decorators.
| Matrix
| Provides data structures for representing alignment coordinates and alignments as a matrix.
| Pairwise Alignments
| Provides the algorithmic components for the computation of pairwise alignments.
| Scoring
| Provides the data structures used for scoring alphabets and sequences.

## Detailed Description

The alignment module contains concepts, algorithms and classes that are related to the computation of pairwise and multiple sequence alignments.

# Sequence Alignment

In bioinformatics, a sequence alignment is a way of arranging the sequences of DNA, RNA, or protein to identify regions of similarity that may be a consequence of functional, structural, or evolutionary relationships between the sequences. Aligned sequences of nucleotide or amino acid residues are typically represented as rows within a matrix. Gaps are inserted between the residues so that identical or similar characters are aligned in successive columns. Sequence alignments are also used for non-biological sequences, such as calculating the distance cost between strings in a natural language or in financial data. [1]

# Pairwise Sequence Alignment

SeqAn offers a generic multi-purpose alignment library comprising all widely known alignment algorithms as well as many special algorithms. These algorithms are all accessible through an easy to use alignment interface which is described in Pairwise Alignments.

The following code snippet demonstrates a simple use of the pairwise alignment interface.

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <utility>
#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;
seqan3::dna4_vector s1 = "ACGTGAACTGACT"_dna4;
seqan3::dna4_vector s2 = "ACGAAGACCGAT"_dna4;
// Configure the alignment kernel.
auto config =
seqan3::align_cfg::method_global{} | seqan3::align_cfg::scoring_scheme{seqan3::hamming_scoring_scheme{}};
// Invoke the pairwise alignment which returns a lazy range over alignment results.
auto results = seqan3::align_pairwise(std::tie(s1, s2), config);
auto & res = *results.begin();
seqan3::debug_stream << "Score: " << res.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::scoring_scheme
Sets the scoring scheme for the alignment algorithm.
Definition align_config_scoring_scheme.hpp:42
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
debug_stream.hpp
Provides seqan3::debug_stream and related types.
dna4.hpp
Provides seqan3::dna4, container aliases and string literals.
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::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38
hamming_scoring_scheme.hpp
Provides seqan3::hamming_scoring_scheme.
seqan3::literals
The SeqAn namespace for literals.
std::tie
T tie(T... args)
utility

# Multiple Sequence Alignment

The current version of SeqAn does not offer multiple sequence alignments (MSA). Please reach out to us with a specific use case we should consider in future versions.

# Alignments represented as CIGAR String used in SAM/BAM Files

A common file format to store (semi) alignments is the SAM/BAM format. In a SAM/BAM file, the alignment is represented as a CIGAR string. To allow back and forth conversion from a CIGAR string to the alignment representation in SeqAn, we provide the following functions:

- seqan3::alignment_from_cigar
- seqan3::cigar_from_alignment

For reading and writing SAM/BAM files, we provide the seqan3::sam_file_input and seqan3::sam_file_ouput.

# References

[1] https://en.wikipedia.org/wiki/Sequence_alignment

Hide me