173 |
|
|
174 |
|
bool next_fastx_read(FLineReader& fr, Read& read, ReadFormat reads_format, |
175 |
|
FLineReader* frq) { |
176 |
+ |
/* |
177 |
|
if (fr.pushed_read) |
178 |
|
{ |
179 |
|
read = fr.last_read; |
180 |
|
fr.pushed_read = false; |
181 |
|
return true; |
182 |
|
} |
183 |
< |
|
183 |
> |
*/ |
184 |
|
read.clear(); |
185 |
|
char* buf=NULL; |
186 |
|
while ((buf=fr.nextLine())!=NULL) { |
263 |
|
} |
264 |
|
} |
265 |
|
|
266 |
< |
fr.last_read = read; |
266 |
> |
//fr.last_read = read; |
267 |
|
return !(read.seq.empty()); |
268 |
|
} |
269 |
|
|
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
+ |
void bam2Read(bam1_t *b, Read& rd) { |
599 |
+ |
GBamRecord bamrec(b); |
600 |
+ |
rd.clear(); |
601 |
+ |
rd.seq=bamrec.seqData(&rd.qual); |
602 |
+ |
rd.name=bam1_qname(b); |
603 |
+ |
rd.alt_name=bamrec.tag_str("XA"); |
604 |
+ |
} |
605 |
+ |
|
606 |
+ |
|
607 |
|
bool ReadStream::next_read(Read& r, ReadFormat read_format) { |
608 |
< |
FLineReader fr(fstream.file); |
599 |
< |
while (read_pq.size()<500000 && !r_eof) { |
608 |
> |
while (read_pq.size()<ReadBufSize && !r_eof) { |
609 |
|
//keep the queue topped off |
610 |
|
Read rf; |
611 |
< |
if (!next_fastx_read(fr, rf, read_format)) { |
611 |
> |
if (fstream.is_bam) { |
612 |
> |
if (samread(fstream.bam_file, b) >= 0) { |
613 |
> |
bam2Read(b,rf); |
614 |
> |
} |
615 |
> |
r_eof=true; |
616 |
> |
break; |
617 |
> |
} |
618 |
> |
else { |
619 |
> |
if (!next_fastx_read(*flseqs, rf, read_format, flquals)) { |
620 |
|
r_eof=true; |
621 |
|
break; |
622 |
|
} |
623 |
< |
//Read read=Read(rf); |
623 |
> |
} |
624 |
|
uint64_t id = (uint64_t)atol(rf.name.c_str()); |
625 |
|
read_pq.push(make_pair(id, rf)); |
626 |
|
} |
633 |
|
return true; |
634 |
|
} |
635 |
|
|
636 |
+ |
bool ReadStream::get_direct(Read& r, ReadFormat read_format) { |
637 |
+ |
if (fstream.file==NULL) return false; |
638 |
+ |
if (fstream.is_bam) { |
639 |
+ |
if (samread(fstream.bam_file, b) >= 0) { |
640 |
+ |
bam2Read(b,r); |
641 |
+ |
return true; |
642 |
+ |
} |
643 |
+ |
r_eof=true; |
644 |
+ |
return false; |
645 |
+ |
} |
646 |
+ |
if (!next_fastx_read(*flseqs, r, read_format, flquals)) { |
647 |
+ |
r_eof=true; |
648 |
+ |
return false; |
649 |
+ |
} |
650 |
+ |
return true; |
651 |
+ |
} |
652 |
+ |
|
653 |
|
// reads must ALWAYS requested in increasing order of their ID |
654 |
|
bool ReadStream::getRead(uint64_t r_id, |
655 |
|
Read& read, |
703 |
|
} //while reads |
704 |
|
return found; |
705 |
|
} |
672 |
– |
|
673 |
– |
|
674 |
– |
bool get_read_from_stream(uint64_t insert_id, |
675 |
– |
FLineReader& fr, |
676 |
– |
ReadFormat reads_format, |
677 |
– |
bool strip_slash, |
678 |
– |
Read& read, |
679 |
– |
FILE* um_out, |
680 |
– |
bool um_write_found) |
681 |
– |
{ |
682 |
– |
bool found=false; |
683 |
– |
while(!found && !fr.isEof()) |
684 |
– |
{ |
685 |
– |
read.clear(); |
686 |
– |
|
687 |
– |
// Get the next read from the file |
688 |
– |
if (!next_fastx_read(fr, read, reads_format)) |
689 |
– |
break; |
690 |
– |
if (strip_slash) |
691 |
– |
{ |
692 |
– |
string::size_type slash = read.name.rfind("/"); |
693 |
– |
if (slash != string::npos) |
694 |
– |
read.name.resize(slash); |
695 |
– |
} |
696 |
– |
uint64_t id = (uint64_t)atoi(read.name.c_str()); |
697 |
– |
if (id == insert_id) |
698 |
– |
{ |
699 |
– |
found=true; |
700 |
– |
} |
701 |
– |
else if (id > insert_id) |
702 |
– |
{ |
703 |
– |
fr.pushBack_read(); |
704 |
– |
break; |
705 |
– |
} |
706 |
– |
|
707 |
– |
if (um_out && ((um_write_found && found) || |
708 |
– |
(!um_write_found && !found))) { |
709 |
– |
//write unmapped reads |
710 |
– |
fprintf(um_out, "@%s\n%s\n+\n%s\n", read.alt_name.c_str(), |
711 |
– |
read.seq.c_str(), read.qual.c_str()); |
712 |
– |
} |
713 |
– |
//rt.get_id(read.name, ref_str); |
714 |
– |
} //while reads |
715 |
– |
return found; |
716 |
– |
} |