13 |
|
#include <sstream> |
14 |
|
#include <seqan/sequence.h> |
15 |
|
#include "common.h" |
16 |
+ |
#include <queue> |
17 |
|
|
18 |
|
using std::string; |
19 |
|
|
20 |
< |
static const int max_read_bp = 64; |
20 |
> |
static const int max_read_bp = 256; |
21 |
|
|
22 |
|
// Note: qualities are not currently used by TopHat |
23 |
|
struct Read |
69 |
|
} |
70 |
|
|
71 |
|
class ReadTable; |
72 |
< |
|
72 |
> |
/* |
73 |
|
bool get_read_from_stream(uint64_t insert_id, |
74 |
|
FILE* reads_file, |
75 |
|
ReadFormat reads_format, |
77 |
|
char read_name [], |
78 |
|
char read_seq [], |
79 |
|
char read_alt_name [], |
80 |
< |
char read_qual []); |
80 |
> |
char read_qual [], |
81 |
> |
FILE* um_out=NULL); //unmapped reads output |
82 |
> |
*/ |
83 |
> |
bool get_read_from_stream(uint64_t insert_id, |
84 |
> |
FILE* reads_file, |
85 |
> |
ReadFormat reads_format, |
86 |
> |
bool strip_slash, |
87 |
> |
Read& read, |
88 |
> |
FILE* um_out=NULL, //unmapped reads output |
89 |
> |
bool um_write_found=false); |
90 |
|
|
91 |
|
class FLineReader { //simple text line reader class, buffering last line read |
92 |
|
int len; |
140 |
|
} |
141 |
|
}; |
142 |
|
|
143 |
+ |
|
144 |
|
void skip_lines(FLineReader& fr); |
145 |
|
bool next_fasta_record(FLineReader& fr, string& defline, string& seq, ReadFormat reads_format); |
146 |
|
bool next_fastq_record(FLineReader& fr, const string& seq, string& alt_name, string& qual, ReadFormat reads_format); |
147 |
< |
bool next_fastx_read(FLineReader& fr, Read& read, ReadFormat reads_format, |
147 |
> |
bool next_fastx_read(FLineReader& fr, Read& read, ReadFormat reads_format=FASTQ, |
148 |
|
FLineReader* frq=NULL); |
149 |
|
|
150 |
+ |
|
151 |
+ |
|
152 |
+ |
class ReadStream { |
153 |
+ |
protected: |
154 |
+ |
struct ReadOrdering |
155 |
+ |
{ |
156 |
+ |
bool operator()(std::pair<uint64_t, Read>& lhs, std::pair<uint64_t, Read>& rhs) |
157 |
+ |
{ |
158 |
+ |
return (lhs.first > rhs.first); |
159 |
+ |
} |
160 |
+ |
}; |
161 |
+ |
FZPipe fstream; |
162 |
+ |
std::priority_queue< std::pair<uint64_t, Read>, |
163 |
+ |
std::vector<std::pair<uint64_t, Read> >, |
164 |
+ |
ReadOrdering > read_pq; |
165 |
+ |
uint64_t last_id; //keep track of last requested ID, for consistency check |
166 |
+ |
bool r_eof; |
167 |
+ |
bool next_read(Read& read, ReadFormat read_format); //get top read from the queue |
168 |
+ |
|
169 |
+ |
public: |
170 |
+ |
ReadStream():fstream(), read_pq(), last_id(0), r_eof(false) { } |
171 |
+ |
|
172 |
+ |
ReadStream(string& fname):fstream(fname, false), |
173 |
+ |
read_pq(), last_id(0), r_eof(false) { } |
174 |
+ |
|
175 |
+ |
void init(string& fname) { |
176 |
+ |
fstream.openRead(fname, false); |
177 |
+ |
} |
178 |
+ |
const char* filename() { |
179 |
+ |
return fstream.filename.c_str(); |
180 |
+ |
} |
181 |
+ |
//read_ids must ALWAYS be requested in increasing order |
182 |
+ |
bool getRead(uint64_t read_id, Read& read, |
183 |
+ |
ReadFormat read_format=FASTQ, |
184 |
+ |
bool strip_slash=false, |
185 |
+ |
FILE* um_out=NULL, //unmapped reads output |
186 |
+ |
bool um_write_found=false); |
187 |
+ |
|
188 |
+ |
void rewind() { |
189 |
+ |
fstream.rewind(); |
190 |
+ |
clear(); |
191 |
+ |
} |
192 |
+ |
FILE* file() { |
193 |
+ |
return fstream.file; |
194 |
+ |
} |
195 |
+ |
void clear() { |
196 |
+ |
/* while (read_pq.size()) { |
197 |
+ |
const std::pair<uint64_t, Read>& t = read_pq.top(); |
198 |
+ |
//free(t.second); |
199 |
+ |
read_pq.pop(); |
200 |
+ |
} */ |
201 |
+ |
read_pq=std::priority_queue< std::pair<uint64_t, Read>, |
202 |
+ |
std::vector<std::pair<uint64_t, Read> >, |
203 |
+ |
ReadOrdering > (); |
204 |
+ |
} |
205 |
+ |
void close() { |
206 |
+ |
clear(); |
207 |
+ |
fstream.close(); |
208 |
+ |
} |
209 |
+ |
~ReadStream() { |
210 |
+ |
close(); |
211 |
+ |
} |
212 |
+ |
}; |
213 |
|
#endif |