-
Notifications
You must be signed in to change notification settings - Fork 5
/
FastxReader.h
64 lines (46 loc) · 1.53 KB
/
FastxReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <sstream>
enum FileFormat {
FORMAT_AUTO_DETECT,
FORMAT_FASTA,
FORMAT_FASTQ,
FORMAT_FASTA_QUAL
};
/*enum FastqVersion {
VERSION_AUTO_DETECT,
SANGER,
SOLEXA,
ILLUMINA_1_3,
ILLUMINA_1_5,
};*/
struct FastxRecord {
FileFormat format;
std::string header = ""; // header line, including @/>, but not newline
std::string id = ""; // from first char. after @/> up to first whitespace
std::string sequence = "";
std::string quality = ""; // only meaningful for FASTQ seqs
std::string &to_string();
private:
std::string str_representation;
};
class BufferedFastxReader {
private:
std::stringstream str_stream_;
std::string str_buffer_ = "";
FileFormat file_format_;
char* block_buffer_;
size_t block_buffer_size_;
bool strip_space_ = true;
public:
BufferedFastxReader();
~BufferedFastxReader();
BufferedFastxReader(const BufferedFastxReader &rhs) = delete;
BufferedFastxReader &operator=(const BufferedFastxReader &rhs) = delete;
bool LoadBatch(std::istream &ifs, size_t record_count);
bool LoadBlock(std::istream &ifs, size_t block_size);
bool NextSequence(FastxRecord &record);
static bool ReadNextSequence(std::istream &is, FastxRecord &record,
std::string &str_buffer_ptr, FileFormat format = FORMAT_AUTO_DETECT);
void auto_detect() { file_format_ = FORMAT_AUTO_DETECT; }
FileFormat file_format() { return file_format_; }
};