]> git.donarmstrong.com Git - mothur.git/blob - sfasta.h
79ab9617527efa014fad336156d8dd7064865748
[mothur.git] / sfasta.h
1 //uchime by Robert C. Edgar http://drive5.com/uchime This code is donated to the public domain.\r
2 \r
3 #ifndef sfasta_h\r
4 #define sfasta_h\r
5 \r
6 #include "myutils.h"\r
7 #include "seq.h"\r
8 \r
9 typedef void (*ON_START_XSEQ)(const SeqData &SD);\r
10 typedef void (*ON_END_XSEQ)(const SeqData &SD);\r
11 \r
12 // Sequential reader for FASTA file format.\r
13 // Serves sequences in file order to save memory.\r
14 // Caches biggish chunks to compromise memory vs. speed.\r
15 class SFasta\r
16         {\r
17 public:\r
18         string m_FileName;\r
19         FILE *m_File;\r
20         bool m_AllowGaps;\r
21 \r
22         off_t m_FileSize;\r
23 \r
24 // Position to start next read\r
25         off_t m_FilePos;\r
26 \r
27 // Cached data.\r
28         byte *m_Buffer;\r
29 \r
30 // Bytes allocated to m_Buffer\r
31         unsigned m_BufferSize;\r
32 \r
33 // Current position in buffer, normally points to '>'\r
34         unsigned m_BufferOffset;\r
35 \r
36 // File data in buffer <= m_BufferSize\r
37         unsigned m_BufferBytes;\r
38 \r
39 // Current label\r
40 // Points into m_Buffer, not a separate buffer.\r
41         char *m_Label;\r
42 \r
43 // Current sequence length\r
44         unsigned m_SeqLength;\r
45 \r
46 // Current seq index\r
47         unsigned m_SeqIndex;\r
48 \r
49         unsigned m_ShortestLength;\r
50         unsigned m_LongestLength;\r
51         unsigned m_TooShortCount;\r
52         unsigned m_TooLongCount;\r
53         unsigned m_TooPolyCount;\r
54 \r
55 private:\r
56         bool m_IsNucleoSet;\r
57         bool m_IsNucleo;\r
58 \r
59 public:\r
60         SFasta();\r
61         ~SFasta();\r
62 \r
63         void Clear();\r
64         void Open(const string &FileName);\r
65         void Rewind();\r
66         bool SetIsNucleo();\r
67         bool GetIsNucleo() const { asserta(m_IsNucleoSet); return m_IsNucleo; };\r
68 \r
69 // Get next sequence.\r
70 // Returns zero on end-of-file\r
71         const byte *GetNextSeq();\r
72 \r
73 // Get next sequence as SeqData object, return false on end-of-file.\r
74         bool GetNextSD(SeqData &SD);\r
75 \r
76 // Length of most recent sequence returned by GetNextSeq().\r
77         unsigned GetSeqLength() const { return m_SeqLength; }\r
78 \r
79 // Label of most recent sequence returned by GetNextSeq().\r
80         const char *GetLabel() const { return m_Label; }\r
81 \r
82 // Index of most recent sequence returned by GetNextSeq().\r
83         unsigned GetSeqIndex() const { return m_SeqIndex; }\r
84 \r
85         unsigned GetPctDoneX10() const;\r
86         double GetPctDone() const;\r
87 \r
88         void LogMe() const;\r
89 \r
90 private:\r
91         void FillCache();\r
92         const byte *GetNextSeqLo();\r
93         };\r
94 \r
95 #endif // sfasta_h\r