| Example Program Global Alignments Computing an optimal global alignment between two sequences. File "alignment.cpp" A tutorial about global alignments.
1 | #include <iostream>
2 | #include <seqan/align.h>
3 | #include <seqan/graph_align.h>
4 |
5 | using namespace seqan;
6 |
7 | int main()
8 | {
Two DNA sequences that shall be aligned.
9 | typedef String<Dna> TSequence;
10 | TSequence seq1 = "atcgaatgcgga";
11 | TSequence seq2 = "actcgttgca";
Scoring objects are used to define a scoring scheme. In this case, affine gap costs with match = 0, mismatch = -1, gapextend = -1 and gapopen = -2.
12 | Score<int> score(0, -1, -1, -2);
Example 1: We use Align to align the two sequences. Since we do not specify an algorithm tag when we call globalAlignment, a suitable algorithm (Gotoh) is automatically choosen.
13 | Align<TSequence, ArrayGaps> align;
14 | resize(rows(align), 2);
15 | assignSource(row(align, 0), seq1);
16 | assignSource(row(align, 1), seq2);
17 |
18 | ::std::cout << "Score = " << globalAlignment(align, score) << ::std::endl;
19 | ::std::cout << align << ::std::endl;
Example 2: We now choose explicitely the algorithm MyersHirschberg. Since this algorithm always works on Levenshtein distance, score is ignored here. Therefore, this algorithm computes a different alignment and returns a different score.
20 | ::std::cout << "Score = " << globalAlignment(align, score, MyersHirschberg()) << ::std::endl;
21 | ::std::cout << align << ::std::endl;
Example 3: We now do the same as in case 1, but now we use an Alignment Graph for storing the alignment. Here we use Gotoh's algorithm.
22 | typedef StringSet<TSequence, Dependent<> > TStringSet;
23 | typedef Graph<Alignment<TStringSet, void> > TAlignmentGraph;
24 |
25 | TStringSet string_set;
26 | appendValue(string_set, seq1);
27 | appendValue(string_set, seq2);
28 | TAlignmentGraph alignment_graph(string_set);
29 |
30 | ::std::cout << "Score = " << globalAlignment(alignment_graph, score, Gotoh()) << ::std::endl;
31 | ::std::cout << alignment_graph << ::std::endl;
32 | return 0;
33 | }
See Alignment Graph, Align, Score, globalAlignment SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2012/03/14 16:34:45