| Example Program Local Alignments Computing local alignments between two sequences. File "alignment_local.cpp" A tutorial about local alignments.
1 | #include <iostream>
2 | #include <seqan/score.h>
3 | #include <seqan/align.h>
4 |
5 | using namespace seqan;
6 |
7 | int main()
8 | {
Example 1: This program applies the Smith-Waterman algorithm to compute the best local alignment between two given sequences.
9 | StringSet<CharString> strings;
10 | Align<String<char> > ali;
11 | resize(rows(ali), 2);
12 | assignSource(row(ali, 0), "aphilologicaltheorem");
13 | assignSource(row(ali, 1), "bizarreamphibology");
14 | int score = localAlignment(ali, Score<int>(3,-3,-2, -2));
15 | std::cout << "Score = " << score << std::endl;
16 | std::cout << ali;
17 | unsigned cBeginPos = clippedBeginPosition(row(ali, 0));
18 | unsigned cEndPos = clippedEndPosition(row(ali, 0)) - 1;
19 | std::cout << "Aligns Seq1[" << cBeginPos << ":" << cEndPos << "]";
20 | std::cout << " and Seq2[" << cBeginPos << ":" << cEndPos << "]" << std::endl << std::endl;
21 |
22 |
Example 2: This program applies the Waterman-Eggert algorithm to compute all non-overlapping local alignments with score better or equal 2.
23 | Align<String<Dna> > ali2;
24 | resize(rows(ali2), 2);
25 | assignSource(row(ali2, 0), "ataagcgtctcg");
26 | assignSource(row(ali2, 1), "tcatagagttgc");
27 |
28 | Score<int> scoring(2, -1, -2, 0);
29 | LocalAlignmentEnumerator<Score<int>, Unbanded> enumerator(scoring, 2);
30 | while (nextLocalAlignment(ali2, enumerator))
31 | {
32 | std::cout << "Score = " << getScore(enumerator) << std::endl;
33 | std::cout << ali2;
34 | unsigned cBeginPos0 = clippedBeginPosition(row(ali2, 0));
35 | unsigned cEndPos0 = clippedEndPosition(row(ali2, 0)) - 1;
36 | unsigned cBeginPos1 = clippedBeginPosition(row(ali2, 1));
37 | unsigned cEndPos1 = clippedBeginPosition(row(ali2, 1)) - 1;
38 | std::cout << "Aligns Seq1[" << cBeginPos0 << ":" << cEndPos0 << "]";
39 | std::cout << " and Seq2[" << cBeginPos1 << ":" << cEndPos1 << "]";
40 | std::cout << std::endl << std::endl;
41 | }
42 |
Example 3
43 | Align<String<Dna> > ali3;
44 | resize(rows(ali3), 2);
45 | assignSource(row(ali3, 0), "cccccc");
46 | assignSource(row(ali3, 1), "tttttggccccccgg");
47 |
48 | Score<int> scoring3(1, -1, -1, -1);
49 | LocalAlignmentEnumerator<Score<int>, Unbanded> enumerator3(scoring3, 5);
50 | while (nextLocalAlignment(ali3, enumerator3))
51 | {
52 | std::cout << "Score = " << getScore(enumerator3) << std::endl;
53 | std::cout << ali3;
54 | unsigned cBeginPos0 = clippedBeginPosition(row(ali3, 0));
55 | unsigned cEndPos0 = clippedEndPosition(row(ali3, 0)) - 1;
56 | unsigned cBeginPos1 = clippedBeginPosition(row(ali3, 1));
57 | unsigned cEndPos1 = clippedEndPosition(row(ali3, 1)) - 1;
58 | std::cout << "Aligns Seq1[" << cBeginPos0 << ":" << cEndPos0 << "]";
59 | std::cout << " and Seq2[" << cBeginPos1 << ":" << cEndPos1 << "]";
60 | std::cout << std::endl << std::endl;
61 | }
62 |
Example 4: This program applies the banded Waterman-Eggert algorithm to compute all non-overlapping local alignments with score or equal 5 in the band from diagonal -1 to diagonal 8.
63 | Align<String<Dna5> > ali4;
64 | resize(rows(ali4), 2);
65 | assignSource(row(ali4, 0), "AAAAAAANAAAGGGNGGGGGGGGNGGGGGANAA");
66 | assignSource(row(ali4, 1), "GGGGGGCGGGGGGGA");
67 |
68 | LocalAlignmentFinder<> finder4(ali4);
69 | Score<int> scoring4(1, -1, -1, -1);
70 | LocalAlignmentEnumerator<Score<int>, Banded> enumerator4(scoring3, -1, 8, 5);
71 | while (nextLocalAlignment(ali4, enumerator4))
72 | {
73 | std::cout << "Score = " << getScore(enumerator4) << std::endl;
74 | std::cout << ali4;
75 | unsigned cBeginPos0 = clippedBeginPosition(row(ali4, 0));
76 | unsigned cEndPos0 = clippedEndPosition(row(ali4, 0)) - 1;
77 | unsigned cBeginPos1 = clippedBeginPosition(row(ali4, 1));
78 | unsigned cEndPos1 = clippedEndPosition(row(ali4, 1)) - 1;
79 | std::cout << "Aligns Seq1[" << cBeginPos0 << ":" << cEndPos0 << "]";
80 | std::cout << " and Seq2[" << cBeginPos1 << ":" << cEndPos1 << "]";
81 | std::cout << std::endl << std::endl;
82 | }
83 |
84 | return 0;
85 | }
See localAlignment, Score, Align SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2014/10/13 16:12:57