File: base.cpp

package info (click to toggle)
seqan2 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228,748 kB
  • sloc: cpp: 257,602; ansic: 91,967; python: 8,326; sh: 1,056; xml: 570; makefile: 229; awk: 51; javascript: 21
file content (69 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//![INCLUDE]
#include <seqan/store.h>
//![INCLUDE]
//![MAIN]
#include <iostream>
#include <seqan/sequence.h>
#include <seqan/stream.h>

using namespace seqan2;

int main()
{
//![MAIN]
//![SIGNATURE]
    FragmentStore<> store;
//![SIGNATURE]
//![LOAD]
    CharString fileName = getAbsolutePath("demos/tutorial/genome_annotations/example.gtf");
    GffFileIn file(toCString(fileName));

    readRecords(store, file);
//![LOAD]
//![ITERATOR]
    Iterator<FragmentStore<>, AnnotationTree<> >::Type it;
    it = begin(store, AnnotationTree<>());
//![ITERATOR]
//![MOVE]
    // Move the iterator down to a leaf
    while (goDown(it))
    {}
    // Create a new iterator and if possible move it to the right sibling of the first iterator
    Iterator<FragmentStore<>, AnnotationTree<> >::Type it2;
    if (isLastChild(it))
        it2 = nodeRight(it);
//![MOVE]
//![DFS]
    // Move the iterator back to the beginning
    goBegin(it);
    // Iterate over the nodes in preorder DFS while the end is not reached and
    // output if the current node is a leaf
    while (!atEnd(it))
    {
        if (isLeaf(it))
            std::cout << " current node is leaf" << std::endl;
        goNext(it);
    }
//![DFS]
//![ACCESS]
    // Move the iterator to the begin of the annotation tree
    it = begin(store, AnnotationTree<>());
    // Go down to exon level
    while (goDown(it)) ;
    std::cout << "type: " <<  getType(it) << std::endl;
    std::cout << "id: " << value(it) << std::endl;
    std::cout << "begin position: " <<  getAnnotation(it).beginPos << std::endl;
//![ACCESS]
//![CREATE]
    Iterator<FragmentStore<>, AnnotationTree<> >::Type it3;
    // Create a right sibling of the current node and return an iterator to this new node
    it3 = createSibling(it);
//![CREATE]
//![OUT]
    // Open output stream
    GffFileOut fileOut("example_out.gtf");
    // Write annotations to GTF file
    writeRecords(fileOut, store);
//![OUT]
    return 0;
}