| Example Program Longest Common Subsequence Longest common subsequence code example File "graph_algo_lcs.cpp" This code example illustrates the longest common subsequence algorithm
1 | #include <seqan/graph.h>
2 | #include <iostream>
3 |
4 | using namespace seqan;
5 |
6 | int main() {
Creation two sequences
7 | String<char> seq1("abacx");
8 | String<char> seq2("baabca");
Out-parameter: A string of positions belonging to the longest common subsequence
9 | String<std::pair<unsigned int, unsigned int>, Block<> > pos;
Longest common subsequence
10 | longestCommonSubsequence(seq1, seq2, pos);
Console ouptut
11 | std::cout << seq1 << std::endl;
12 | std::cout << seq2 << std::endl;
13 | std::cout << "Lcs:" << std::endl;
14 | for(int i = length(pos)-1; i>=0; --i) {
15 | std::cout << seq1[pos[i].first] << ',';
16 | }
17 | std::cout << std::endl;
18 | for(int i = length(pos)-1; i>=0; --i) {
19 | std::cout << seq2[pos[i].second] << ',';
20 | }
21 | std::cout << std::endl;
22 | return 0;
23 | }
See Graph, longestCommonSubsequence SeqAn - Sequence Analysis Library - www.seqan.de