-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastqReader.cpp
More file actions
102 lines (73 loc) · 2.23 KB
/
FastqReader.cpp
File metadata and controls
102 lines (73 loc) · 2.23 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Created by Walfred (Wangfei) MA at the University of Southern California,
// Mark Chaisson Lab on 2/13/23.
//
// Licensed under the MIT License.
// If you use this code, please cite our work.
//
#include "FastqReader.hpp"
void FastqReader::Load()
{
buffer.resize(MAX_LINE);
if (strlen(filepath)<2) return;
fafile = gzopen(filepath, "rb");
if (fafile == NULL)
{
std::cerr << "ERROR: Could not open " << filepath << " for reading.\n" << std::endl;
std::_Exit(EXIT_FAILURE);
}
}
bool FastqReader:: nextLine_prt(const char* &StrLine, size_t &rlen)
{
lock_guard<mutex> IO(IO_lock);
//if (buffer.size() < 501) {buffer.resize(501);}
if (buffer.size() - bytes_read < 2000000)
{
gzseek(fafile, - bytes_read + pos_read, SEEK_CUR);
bytes_read = gzread(fafile, &buffer[0], 1000000);
if (bytes_read <= 0) return 0;
pos_read = 0;
}
while (1)
{
if (pos_read == bytes_read)
{
int new_bytes_read = gzread(fafile, &buffer[bytes_read], 1000000);
if (new_bytes_read <= 0 ) return 0;
bytes_read += new_bytes_read;
}
++pos_read;
if (buffer[pos_read-1] == '\n') break;
}
size_t start = pos_read;
while (1)
{
if (pos_read == bytes_read)
{
int new_bytes_read = gzread(fafile, &buffer[bytes_read], 1000000);
if (new_bytes_read <= 0 ) return 0;
bytes_read += new_bytes_read;
}
++pos_read;
if (buffer[pos_read-1] == '\n') break;
}
rlen = pos_read - start;
while (1)
{
if (pos_read == bytes_read)
{
int new_bytes_read = gzread(fafile, &buffer[bytes_read], 1000000);
if (new_bytes_read <= 0 ) return 1;
bytes_read += new_bytes_read;
}
++pos_read;
if (buffer[pos_read-1] == '\n') break;
}
StrLine = &buffer[start];
//gzseek(fafile, - bytes_read + pos_read, SEEK_CUR);
return 1;
}
void FastqReader::Close()
{
gzclose(fafile);
}