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