Example Program
Global Alignments
Computing an optimal global alignment between two sequences.
A tutorial about global alignments.
1//#include <iostream>
2
3#include <seqan/basic.h>
4#include <seqan/file.h>
5#include <seqan/align.h>
6
7int main()
8{
9    using namespace seqan;
10    typedef Value<Gaps<Dna5String, ArrayGaps> >::Type TValue;
11    /*
12    using namespace seqan;
13
Two DNA sequences that shall be aligned.
14    typedef String<Dna> TSequence;
15    TSequence seq1 = "atcgaatgcgga";
16    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.
17    Score<int> scoringScheme(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.
18    Align<TSequence, ArrayGaps> align;
19    resize(rows(align), 2);
20    assignSource(row(align, 0), seq1);
21    assignSource(row(align, 1), seq2);
22
23    int score = globalAlignment(align, scoringScheme);
24    std::cout << "Score = " << score << std::endl;
25    std::cout << align << std::endl;
Example 2: We now choose explicitely the algorithm MyersHirschberg. Since this algorithm always works on Levenshtein distance, we do not need score.
26    score = globalAlignment(align, MyersHirschberg());
27    std::cout << "Score = " << score << std::endl;
28    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.
29    typedef StringSet<TSequence, Dependent<> > TStringSet;
30    typedef Graph<Alignment<TStringSet, void> > TAlignmentGraph;
31
32    TStringSet string_set;
33    appendValue(string_set, seq1);
34    appendValue(string_set, seq2);
35    TAlignmentGraph alignment_graph(string_set);
36
37    score = globalAlignment(alignment_graph, scoringScheme, Gotoh());
38    std::cout << "Score = " << score << std::endl;
39    std::cout << alignment_graph << std::endl;
40    */
41    return 0;
42}
SeqAn - Sequence Analysis Library - www.seqan.de
 

Page built @2012/10/02 11:10:29