| Example Program Smith-Waterman Algorithm Smith-Waterman local alignment code example. File "graph_align_sw.cpp" This code example illustrates a graph-based Smith-Waterman alignment
1 | #include <seqan/graph.h>
2 | #include <iostream>
3 |
4 | using namespace seqan;
5 |
6 | int main() {
7 | typedef String<Dna> TString;
8 | typedef StringSet<TString, Dependent<> > TStringSet;
9 | typedef Graph<Alignment<TStringSet, Dna> > TGraph;
Alignments are carried out on a StringSet that holds the sequences
10 | TStringSet str;
11 | TString str0("TTGACACCCTCCCAATTGTA"); appendValue(str, str0);
12 | TString str1("ACCCCAGGCTTTACACAT"); appendValue(str, str1);
Configuration of alignment algorithm: Scoring (Match = 2, Mismatch = -1, Gap-extension = -1, Gap-opening = -2)
13 | Score<int> score_type = Score<int>(2,-1,-1,-2);
We could again use a graph to retrieve the local alignment, but as with all other alignment algorithms we can also use a string of fragments or simply std::cout.
14 | typedef Fragment<> TFragment;
15 | typedef String<TFragment, Block<> > TFragmentString;
16 | TFragmentString matches;
Local alignment with Smith-Waterman
17 | int score = localAlignment(matches, str, score_type, SmithWaterman() );
Console output
18 | std::cout << "Scoring schema: Match=2, Mismatch=-1, Gap-extension=-1, Gap-opening=-2" << std::endl;
19 | std::cout << str0 << std::endl;
20 | std::cout << str1 << std::endl;
21 | std::cout << "Local match: " << std::endl;
22 | std::cout << label(matches[0], str, 0) << std::endl;
23 | std::cout << label(matches[0], str, 1) << std::endl;
24 | std::cout << "Score: " << score << std::endl;
25 | return 0;
26 | }
27 |
See Graph, localAlignment SeqAn - Sequence Analysis Library - www.seqan.de