| Example Program Needleman-Wunsch Algorithm Needleman-Wunsch alignment code example File "graph_align_nw.cpp" This code example illustrates a graph-based Needleman-Wunsch alignment
1 | #include <seqan/graph_align.h>
2 | #include <iostream>
3 |
4 | using namespace seqan;
5 |
6 | int main() {
7 | typedef String<char> TString;
8 | typedef StringSet<TString, Dependent<> > TStringSet;
9 | typedef Graph<Alignment<TStringSet, void> > TGraph;
Alignments are carried out on a StringSet that holds the sequences
10 | TStringSet str;
11 | TString str0("Myannealing");appendValue(str, str0);
12 | TString str1("annual"); appendValue(str, str1);
Configuration of alignment algorithm: Scoring (Match = 0, Mismatch = -1, Gap = -1)
13 | Score<int> score_type = Score<int>(0,-1,-1,0);
Out-parameter: An alignment graph
14 | TGraph g(str);
Global alignment with Needleman-Wunsch
15 | int score = globalAlignment(g, score_type, NeedlemanWunsch() );
Console output
16 | std::cout << "Scoring schema: Match=0, Mismatch=-1, Gap=-1" << std::endl;
17 | std::cout << g << std::endl;
18 | std::cout << "Score: " << score << std::endl;
The initialization of the matrix and the traceback start can also be controlled. Configuration: AlignConfig<TTop, TLeft, TRight, TBottom>. If TTop, TLeft, TRight, or TBottom is true the corresponding row / column is initialized with 0's or searched for the maximum, respectively.
19 | AlignConfig<true,false,false,true> ac;
Global alignment with Needleman-Wunsch and special initialization
20 | int score2 = globalAlignment(stringSet(g), score_type, ac, NeedlemanWunsch() );
Console output
21 | std::cout << "Score with ends free-space alignment: " << score2 << std::endl;
22 | return 0;
23 | }
See globalAlignment, Graph SeqAn - Sequence Analysis Library - www.seqan.de