| Class FaiIndex Data type for storing FAI indices. FaiIndex Include Headers seqan/seq_io.h Data Members
FaiIndex | The FaiIndex class only provides the default constructor.
Functions
build | Create FaiIndex from FASTA file.
clear | Reset a FaiIndex object to the state after default construction.
getIdByName | Return id (numeric index in the file) of a sequence in a FAI file.
numSeqs | Return number of sequences known to an FaiIndex.
read | Read a FAI index.
readRegion | Load the infix of a sequence from a FaiIndex.
readSequence | Load a whole sequence from an FaiIndex.
sequenceLength | Return length of the sequence with the given id in the FaiIndex.
sequenceName | Return the name of the sequence with the given id in the FaiIndex.
write | Write out an FaiIndex object.
Examples The following example demonstrate the usage of the FAIIndex class. File "fai_index_example.cpp"
1 | #include <seqan/basic.h>
2 | #include <seqan/seq_io.h>
3 | #include <seqan/sequence.h>
4 |
5 | using namespace seqan;
6 |
7 | int main()
8 | {
9 | CharString path = SEQAN_PATH_TO_ROOT();
10 | append(path, "/core/demos/seq_io/example.fa");
11 |
12 | FaiIndex faiIndex;
13 |
14 | // Try to read the FAI index.
15 | bool readSuccess = (read(faiIndex, toCString(path)) == 0);
16 | if (!readSuccess)
17 | std::cerr << "Could not read the FAI index. Not fatal, we can just build it.\n";
18 |
19 | // Try to build the FAI index (in memory) if reading was unsuccessful. If
20 | // building into memory succeeded, we try to write it out.
21 | if (!readSuccess)
22 | {
23 | if (build(faiIndex, toCString(path)) != 0)
24 | {
25 | std::cerr << "FATAL: Could not build FAI index.\n";
26 | return 1;
27 | }
28 |
29 | if (write(faiIndex) != 0)
30 | {
31 | std::cerr << "FATAL: Could not write out FAI index after building.\n";
32 | return 1;
33 | }
34 | }
35 |
36 | // Now, read the first 1000 characters of chr1.
37 | unsigned idx = 0;
38 | if (!getIdByName(faiIndex, "chr", idx))
39 | {
40 | std::cerr << "FATAL: chr1 not found in FAI index.\n";
41 | return 1;
42 | }
43 | CharString seq;
44 | if (readRegion(seq, faiIndex, idx, 0, 100) != 0)
45 | {
46 | std::cerr << "FATAL: Problem reading FASTA file through FAI index.\n";
47 | return 1;
48 | }
49 |
50 | // Now print the first 100 characters we just read.
51 | std::cout << "chr:1-100 = " << seq << "\n";
52 |
53 | return 0;
54 | }
SeqAn - Sequence Analysis Library - www.seqan.de

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