1 //![solution]
2 #include <iostream>
3 #include <seqan/align.h>
4
5 using namespace seqan;
6
main()7 int main()
8 {
9 // Defining all types that are needed.
10 typedef String<char> TSequence;
11 typedef Align<TSequence, ArrayGaps> TAlign;
12 typedef Row<TAlign>::Type TRow;
13 typedef Iterator<TRow>::Type TRowIterator;
14
15 TSequence seq1 = "ACGTCACCTC";
16 TSequence seq2 = "ACGGGCCTATC";
17
18 // Initializing the align object.
19 TAlign align;
20 resize(rows(align), 2);
21 assignSource(row(align, 0), seq1);
22 assignSource(row(align, 1), seq2);
23
24 // Use references to the rows of align.
25 TRow & row1 = row(align, 0);
26 TRow & row2 = row(align, 1);
27
28 // Insert gaps.
29 insertGaps(row1, 2, 2);
30 insertGap(row1, 7); // We need to pass the view position which is changed due to the previous insertion.
31 insertGaps(row2, 9, 2);
32
33 // Initialize the row iterators.
34 TRowIterator itRow1 = begin(row1);
35 TRowIterator itEndRow1 = end(row1);
36 TRowIterator itRow2 = begin(row2);
37
38 // Iterate over both rows simultaneously.
39 int gapCount = 0;
40 for (; itRow1 != itEndRow1; ++itRow1, ++itRow2)
41 {
42 if (isGap(itRow1))
43 {
44 gapCount += countGaps(itRow1); // Count the number of consecutive gaps from the current position in row1.
45 itRow1 += countGaps(itRow1); // Jump to next position to check for gaps.
46 itRow2 += countGaps(itRow1); // Jump to next position to check for gaps.
47 }
48 if (isGap(itRow2))
49 {
50 gapCount += countGaps(itRow2); // Count the number of consecutive gaps from the current position in row2.
51 itRow1 += countGaps(itRow2); // Jump to next position to check for gaps.
52 itRow2 += countGaps(itRow2); // Jump to next position to check for gaps.
53 }
54 }
55 // Print the result.
56 std::cout << "Number of gaps: " << gapCount << std::endl;
57 }
58 //![solution]
59