| Example Program MSA with Neighbor-Joining Progressive multiple sequence alignment using neighbor joining for building the guide tree. File "graph_align_guide_nj.cpp" This code example illustrates a guide tree creation using neighbor-joing
1 | #include <seqan/graph.h>
2 | #include <iostream>
3 |
4 | using namespace seqan;
5 |
6 | int main() {
Create an artificial distance matrix
7 | String<double> mat;
8 | fill(mat, 8*8, 0);
9 | assignValue(mat, 0*8+0, 0);assignValue(mat, 0*8+1, 7);assignValue(mat, 0*8+2, 8);assignValue(mat, 0*8+3, 11);
10 | assignValue(mat, 0*8+4, 13);assignValue(mat, 0*8+5, 16);assignValue(mat, 0*8+6, 13);assignValue(mat, 0*8+7, 17);
11 | assignValue(mat, 1*8+0, 7);assignValue(mat, 1*8+1, 0);assignValue(mat, 1*8+2, 5);assignValue(mat, 1*8+3, 8);
12 | assignValue(mat, 1*8+4, 10);assignValue(mat, 1*8+5, 13);assignValue(mat, 1*8+6, 10);assignValue(mat, 1*8+7, 14);
13 | assignValue(mat, 2*8+0, 8);assignValue(mat, 2*8+1, 5);assignValue(mat, 2*8+2, 0);assignValue(mat, 2*8+3, 5);
14 | assignValue(mat, 2*8+4, 7);assignValue(mat, 2*8+5, 10);assignValue(mat, 2*8+6, 7);assignValue(mat, 2*8+7, 11);
15 | assignValue(mat, 3*8+0, 11);assignValue(mat, 3*8+1, 8);assignValue(mat, 3*8+2, 5);assignValue(mat, 3*8+3, 0);
16 | assignValue(mat, 3*8+4, 8);assignValue(mat, 3*8+5, 11);assignValue(mat, 3*8+6, 8);assignValue(mat, 3*8+7, 12);
17 | assignValue(mat, 4*8+0, 13);assignValue(mat, 4*8+1, 10);assignValue(mat, 4*8+2, 7);assignValue(mat, 4*8+3, 8);
18 | assignValue(mat, 4*8+4, 0);assignValue(mat, 4*8+5, 5);assignValue(mat, 4*8+6, 6);assignValue(mat, 4*8+7, 10);
19 | assignValue(mat, 5*8+0, 16);assignValue(mat, 5*8+1, 13);assignValue(mat, 5*8+2, 10);assignValue(mat, 5*8+3, 11);
20 | assignValue(mat, 5*8+4, 5);assignValue(mat, 5*8+5, 0);assignValue(mat, 5*8+6, 9);assignValue(mat, 5*8+7, 13);
21 | assignValue(mat, 6*8+0, 13);assignValue(mat, 6*8+1, 10);assignValue(mat, 6*8+2, 7);assignValue(mat, 6*8+3, 8);
22 | assignValue(mat, 6*8+4, 6);assignValue(mat, 6*8+5, 9);assignValue(mat, 6*8+6, 0);assignValue(mat, 6*8+7, 8);
23 | assignValue(mat, 7*8+0, 17);assignValue(mat, 7*8+1, 14);assignValue(mat, 7*8+2, 11);assignValue(mat, 7*8+3, 12);
24 | assignValue(mat, 7*8+4, 10);assignValue(mat, 7*8+5, 13);assignValue(mat, 7*8+6, 8);assignValue(mat, 7*8+7, 0);
Out-parameter: A guide tree based upon a distance matrix
25 | typedef Graph<Tree<double> > TGraph;
26 | TGraph njTreeOut;
Neighbor-joining
27 | slowNjTree(mat, njTreeOut);
Console output
28 | std::cout << njTreeOut << std::endl;
29 | typedef Iterator<TGraph, DfsPreorder>::Type TDfsPreorder;
30 | TDfsPreorder dfsIt(njTreeOut,getRoot(njTreeOut));
31 | std::cout << "Dfs: ";
32 | for(;!atEnd(dfsIt);goNext(dfsIt)) {
33 | std::cout << *dfsIt << ", ";
34 | }
35 | std::cout << std::endl;
36 | typedef Iterator<TGraph, EdgeIterator>::Type TEdgeIter;
37 | TEdgeIter edIt(njTreeOut);
38 | std::cout << "Edges: " << std::endl;
39 | for(;!atEnd(edIt);goNext(edIt)) {
40 | std::cout << sourceVertex(edIt) << " -- " << targetVertex(edIt) << ": Weight = " << getCargo(*edIt) << std::endl;
41 | }
42 | return 0;
43 | }
See Graph SeqAn - Sequence Analysis Library - www.seqan.de