diff --git a/fastqlib.cpp b/fastqlib.cpp index 47fdae6..eff47d7 100755 --- a/fastqlib.cpp +++ b/fastqlib.cpp @@ -167,25 +167,36 @@ fastqWriter::fastqWriter(string fname){ } int fastqWriter::open(string fname){ - fp = gzopen(fname.c_str(), "wb"); - if(!fp ) { - cerr << "Problem reading "<0) { - if(gzwrite(fp,"@",1)==0) die("problem writing output"); - if(gzwrite(fp,(char *)read.h.c_str(),read.h.size())==0) die("problem writing output"); - if( gzwrite(fp,"\n",1)==0) die("problem writing output"); - if( gzwrite(fp,(char *)read.s.c_str(),read.s.size())==0) die("problem writing output"); - if( gzwrite(fp,"\n",1)==0) die("problem writing output"); - if( gzwrite(fp,(char *)read.l3.c_str(),read.l3.size())==0) die("problem writing output"); - if( gzwrite(fp,"\n",1)==0) die("problem writing output"); - if( gzwrite(fp,(char *)read.q.c_str(),read.q.size())==0) die("problem writing output"); - if( gzwrite(fp,"\n",1)==0) die("problem writing output"); + if(_stdout) { + read.print(); + } + else{ + if(gzwrite(fp,"@",1)==0) die("problem writing output"); + if(gzwrite(fp,(char *)read.h.c_str(),read.h.size())==0) die("problem writing output"); + if( gzwrite(fp,"\n",1)==0) die("problem writing output"); + if( gzwrite(fp,(char *)read.s.c_str(),read.s.size())==0) die("problem writing output"); + if( gzwrite(fp,"\n",1)==0) die("problem writing output"); + if( gzwrite(fp,(char *)read.l3.c_str(),read.l3.size())==0) die("problem writing output"); + if( gzwrite(fp,"\n",1)==0) die("problem writing output"); + if( gzwrite(fp,(char *)read.q.c_str(),read.q.size())==0) die("problem writing output"); + if( gzwrite(fp,"\n",1)==0) die("problem writing output"); + } return(1); } else return(0); diff --git a/fastqlib.h b/fastqlib.h index 36d0cd4..a5ce18a 100755 --- a/fastqlib.h +++ b/fastqlib.h @@ -59,6 +59,7 @@ class fastqWriter { int write(readPair & read); private: gzFile fp; + bool _stdout;//true if writing to stdout }; class pairReader { @@ -78,7 +79,7 @@ class pairWriter { //interleaved pairWriter(string fname); - int open(string fname); + int open(string fname); //separate files pairWriter(string fname1,string fname2); int open(string fname1,string fname2); diff --git a/matepair.cpp b/matepair.cpp index 9e664a0..3c7a3c0 100755 --- a/matepair.cpp +++ b/matepair.cpp @@ -516,24 +516,29 @@ nxtrimWriter::nxtrimWriter(string prefix,bool jmp,bool separate) { } int nxtrimWriter::open(string prefix,bool jmp,bool separate) { + if(prefix=="-") + return(open(jmp,separate)); n_mp=0; n_pe=0; n_se=0; n_unk=0; justmp = jmp; - if(separate) mp_out.open(prefix+"_R1.mp.fastq.gz", prefix+"_R2.mp.fastq.gz"); - else mp_out.open(prefix+".mp.fastq.gz"); + if(separate) + mp_out.open(prefix+"_R1.mp.fastq.gz", prefix+"_R2.mp.fastq.gz"); + else + mp_out.open(prefix+".mp.fastq.gz"); - if(separate) unknown_out.open(prefix+"_R1.unknown.fastq.gz",prefix+"_R2.unknown.fastq.gz"); - else unknown_out.open(prefix+".unknown.fastq.gz"); + if(separate) + unknown_out.open(prefix+"_R1.unknown.fastq.gz",prefix+"_R2.unknown.fastq.gz"); + else + unknown_out.open(prefix+".unknown.fastq.gz"); if(!justmp) { if(separate) pe_out.open(prefix+"_R1.pe.fastq.gz",prefix+"_R2.pe.fastq.gz"); else pe_out.open(prefix+".pe.fastq.gz"); se_out.open(prefix+".se.fastq.gz"); } - print_to_stdout=false; return(0); } @@ -549,29 +554,21 @@ int nxtrimWriter::open(bool jmp,bool separate) { n_se=0; n_unk=0; justmp = jmp; - - print_to_stdout=true; + mp_out.open("-"); + pe_out.open("-"); + unknown_out.open("-"); + se_out.open("-"); return(0); } int nxtrimWriter::write(matePair m) { - if(!print_to_stdout) { - n_mp+=mp_out.write(m.mp); - n_unk+=unknown_out.write(m.unknown); - if(!justmp) { - n_pe+=pe_out.write(m.pe); - n_se+=se_out.write(m.se); - } - if(DEBUG>0) - cerr << "Wrote: n_mp="<