ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/tophat_cpp/reads.cpp
(Generate patch)
# Line 173 | Line 173
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) {
# Line 262 | Line 263
263             }
264      }
265  
266 <  fr.last_read = read;  
266 >  //fr.last_read = read;
267    return !(read.seq.empty());
268   }
269  
# Line 594 | Line 595
595   }
596  
597  
598 + void bam2Read(bam1_t *b, Read& rd, bool alt_name=false) {
599 +  GBamRecord bamrec(b);
600 +  rd.clear();
601 +  rd.seq=bamrec.seqData(&rd.qual);
602 +  rd.name=bam1_qname(b);
603 +  if (alt_name)
604 +    rd.alt_name=bamrec.tag_str("XA");
605 + }
606 +
607 +
608   bool ReadStream::next_read(Read& r, ReadFormat read_format) {
609 <  FLineReader fr(fstream.file);
599 <  while (read_pq.size()<500000 && !r_eof) {
609 >  while (read_pq.size()<ReadBufSize && !r_eof) {
610      //keep the queue topped off
611      Read rf;
612 <    if (!next_fastx_read(fr, rf, read_format)) {
612 >    if (fstream.is_bam) {
613 >      if (samread(fstream.bam_file, b) < 0) {
614          r_eof=true;
615          break;
616          }
617 <    //Read read=Read(rf);
617 >      bam2Read(b, rf, bam_alt_name);
618 >      }
619 >    else {
620 >      if (!next_fastx_read(*flseqs, rf, read_format, flquals)) {
621 >        r_eof=true;
622 >        break;
623 >        }
624 >    }
625      uint64_t id = (uint64_t)atol(rf.name.c_str());
626      read_pq.push(make_pair(id, rf));
627      }
# Line 616 | Line 634
634    return true;
635   }
636  
637 + bool ReadStream::get_direct(Read& r, ReadFormat read_format) {
638 +  if (fstream.file==NULL) return false;
639 +   if (fstream.is_bam) {
640 +     if (samread(fstream.bam_file, b) < 0) {
641 +       r_eof=true;
642 +       return false;
643 +       }
644 +     bam2Read(b, r, bam_alt_name);
645 +     return true;
646 +     }
647 +   if (!next_fastx_read(*flseqs, r, read_format, flquals)) {
648 +        r_eof=true;
649 +        return false;
650 +        }
651 +  return true;
652 + }
653 +
654   // reads must ALWAYS requested in increasing order of their ID
655   bool ReadStream::getRead(uint64_t r_id,
656                           Read& read,
# Line 669 | Line 704
704      } //while reads
705    return found;
706   }
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 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines