--- /dev/null
+#ifndef sfasta_h\r
+#define sfasta_h\r
+\r
+#include "myutils.h"\r
+#include "seq.h"\r
+\r
+typedef void (*ON_START_XSEQ)(const SeqData &SD);\r
+typedef void (*ON_END_XSEQ)(const SeqData &SD);\r
+\r
+// Sequential reader for FASTA file format.\r
+// Serves sequences in file order to save memory.\r
+// Caches biggish chunks to compromise memory vs. speed.\r
+class SFasta\r
+ {\r
+public:\r
+ string m_FileName;\r
+ FILE *m_File;\r
+ bool m_AllowGaps;\r
+\r
+ off_t m_FileSize;\r
+\r
+// Position to start next read\r
+ off_t m_FilePos;\r
+\r
+// Cached data.\r
+ byte *m_Buffer;\r
+\r
+// Bytes allocated to m_Buffer\r
+ unsigned m_BufferSize;\r
+\r
+// Current position in buffer, normally points to '>'\r
+ unsigned m_BufferOffset;\r
+\r
+// File data in buffer <= m_BufferSize\r
+ unsigned m_BufferBytes;\r
+\r
+// Current label\r
+// Points into m_Buffer, not a separate buffer.\r
+ char *m_Label;\r
+\r
+// Current sequence length\r
+ unsigned m_SeqLength;\r
+\r
+// Current seq index\r
+ unsigned m_SeqIndex;\r
+\r
+ unsigned m_ShortestLength;\r
+ unsigned m_LongestLength;\r
+ unsigned m_TooShortCount;\r
+ unsigned m_TooLongCount;\r
+ unsigned m_TooPolyCount;\r
+\r
+private:\r
+ bool m_IsNucleoSet;\r
+ bool m_IsNucleo;\r
+\r
+public:\r
+ SFasta();\r
+ ~SFasta();\r
+\r
+ void Clear();\r
+ void Open(const string &FileName);\r
+ void Rewind();\r
+ bool SetIsNucleo();\r
+ bool GetIsNucleo() const { asserta(m_IsNucleoSet); return m_IsNucleo; };\r
+\r
+// Get next sequence.\r
+// Returns zero on end-of-file\r
+ const byte *GetNextSeq();\r
+\r
+// Get next sequence as SeqData object, return false on end-of-file.\r
+ bool GetNextSD(SeqData &SD);\r
+\r
+// Length of most recent sequence returned by GetNextSeq().\r
+ unsigned GetSeqLength() const { return m_SeqLength; }\r
+\r
+// Label of most recent sequence returned by GetNextSeq().\r
+ const char *GetLabel() const { return m_Label; }\r
+\r
+// Index of most recent sequence returned by GetNextSeq().\r
+ unsigned GetSeqIndex() const { return m_SeqIndex; }\r
+\r
+ unsigned GetPctDoneX10() const;\r
+ double GetPctDone() const;\r
+\r
+ void LogMe() const;\r
+\r
+private:\r
+ void FillCache();\r
+ const byte *GetNextSeqLo();\r
+ };\r
+\r
+#endif // sfasta_h\r