Class
FaiIndex
Data type for storing FAI indices.
FaiIndex
Include Headers
seqan/seq_io.h
Data Members
FaiIndexThe FaiIndex class only provides the default constructor.
Functions
buildCreate FaiIndex from FASTA file.
clearReset a FaiIndex object to the state after default construction.
getIdByNameReturn id (numeric index in the file) of a sequence in a FAI file.
numSeqsReturn number of sequences known to an FaiIndex.
readRead a FAI index.
readRegionLoad the infix of a sequence from a FaiIndex.
readSequenceLoad a whole sequence from an FaiIndex.
sequenceLengthReturn length of the sequence with the given id in the FaiIndex.
sequenceNameReturn the name of the sequence with the given id in the FaiIndex.
writeWrite out an FaiIndex object.
Examples
The following example demonstrate the usage of the FAIIndex class.
1#include <seqan/basic.h>
2#include <seqan/seq_io.h>
3#include <seqan/sequence.h>
4
5using namespace seqan;
6
7int main(int argc, char ** argv)
8{
9    if (argc != 2)
10    {
11        std::cerr << "USAGE: " << argv[0] << " SEQUENCE.fasta\n";
12        return 1;
13    }
14    
15    FaiIndex faiIndex;
16
17    // Try to read the FAI index.
18    bool readSuccess = (read(faiIndex, argv[1]) == 0);
19    if (!readSuccess)
20        std::cerr << "Could not read the FAI index.  Not fatal, we can just build it.\n";
21
22    // Try to build the FAI index (in memory) if reading was unsuccessful.  If
23    // building into memory succeeded, we try to write it out.
24    if (!readSuccess)
25    {
26        if (build(faiIndex, argv[1]) != 0)
27        {
28            std::cerr << "FATAL: Could not build FAI index.\n";
29            return 1;
30        }
31
32        if (write(faiIndex) != 0)
33        {
34            std::cerr << "FATAL: Could not write out FAI index after building.\n";
35            return 1;
36        }
37    }
38
39    // Now, read the first 1000 characters of chr1.
40    unsigned idx = 0;
41    if (!getIdByName(faiIndex, "chr1", idx))
42    {
43        std::cerr << "FATAL: chr1 not found in FAI index.\n";
44        return 1;
45    }
46    CharString seq;
47    if (readRegion(seq, faiIndex, idx, 0, 1000) != 0)
48    {
49        std::cerr << "FATAL: Problem reading FASTA file through FAI index.\n";
50        return 1;
51    }
52
53    // Now print the first 1000 characters we just read.
54    std::cerr << "chr1:1-1000 = " << seq << "\n";
55    
56    return 0;
57}
SeqAn - Sequence Analysis Library - www.seqan.de
 

Page built @2013/07/11 09:12:34