diff --git a/data/test_PE1.fq b/data/test_PE1.fq new file mode 100644 index 0000000000000000000000000000000000000000..6be87976ca245fb623439e8dcd85285dd2da1561 --- /dev/null +++ b/data/test_PE1.fq @@ -0,0 +1,12 @@ +@NS500443:42:H3MH2AFXX:1:11101:1162:1066/1 +AGATCAAACTACTTGCCTCGCTTGAAAAAAGCATCGAGATTCATAATGACGCTGGTGTTGTAACGGCAGATTTGCTGCTTGCTCGGGTTTTACGGTATGATTTTTCAAGTGATGTATTTGACGAAGAAAAGGAGTATATTTTACCAGAATT ++ +/A6AAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE/EAEEEEEEEEEEEEAEEEEEEE<EEEEEEEAE<EEEEEE +@NS500443:42:H3MH2AFXX:1:11101:7372:1069/1 +TTCCAGAAGCGGATTATTTGCAGGAACTGCGGCGGTTTTTCTATCAAGACGAACGGCAAACTTATTCGAATGAAGCTGTTGCTAACCGTTTTTATGAGCATTTTGATGTCGTCTATGAAAAACGAATAACGAAACAGAAAACGTTACAAAA ++ +AAAAAEEEEEEEAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEEEEEEAEEEEEEEEEEEEEEEEEEEEEEE<EE<EEEEEEEEEEEE/EEEE<EEEEEEEEEEEEEEEEEEE/AEEAAAEEEEEEEE/EEEEEEEE +@NS500443:42:H3MH2AFXX:1:11101:17849:1071/1 +ACAGTAACGCGCGCATGGTAATCCCCGTATTGTGCAAGACGTTCAGCAAACTCATTTCCAGACATAACACCTTCAGCAACAACAATGATGCTGTGCTTTTTACCACGTTCACGTCCCTTATTAAGACGCCCTACAATATCATCCATGTTAA ++ +AAAAAE6EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE/EEEEEAEEEEEEEEEE/EEAEE/EEAEAEAEEEEE</E//EE/EEEEEEEEEA<EEAAAEEEEEAEEEEAA<AE/EA<AEEEAEEE/EAEAEEEEEEEEEAEEEEEEEEEA/ diff --git a/data/test_PE2.fq b/data/test_PE2.fq new file mode 100644 index 0000000000000000000000000000000000000000..c5b32694dcbf3f985ff71bc819ebe551b9bfed35 --- /dev/null +++ b/data/test_PE2.fq @@ -0,0 +1,12 @@ +@NS500443:42:H3MH2AFXX:1:11101:1162:1066/2 +CCCTAGAATTATAGTTCAGTTTAGTTCCAAATAGGGTCACAAAATGTGATAGACAGGTCCCGTTCCATACCAAAAAAACTTGGTACTCCGCACTATTCAATTAGCGGTTAACATTCACTTTGGAACGAAGTCTATACAGCCACATAATTTG ++ +AAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEEEEEEEEEEAEEEEEEEEEEEEEEEEAEEEAEEEEE<EEEEEAEEEEEA/EEEAAEE<EAAEEAEEEE<EEEEEEEEE/EAE<EAEEEEEEE +@NS500443:42:H3MH2AFXX:1:11101:7372:1069/2 +GGTGTTGTTGCAAGTTCCGCATCTAAAATGTCGACGCCACCTGCTTTTAAAACCGACACCAGTTTAGCCTTGATCCGCTCAGCAGAAAGCCTACTATCATGTCCGATAGCGACCACTATTTTTTCTTTTGGAGTTTTTTTCTTTTGCAAGA ++ +AAAAAEEEEEEEEEEEEEEEEEEEEAEEEEEEAEEEEE/EAEEAEEEEEEEEEEE/EAEEEEEEEEEEE<EE<EEEAEEE/EEEEEEEEEEEAEEEEEEEAEEEE/EEEEE/EEEEEEEEEAEEE</E<EEE/EAEEEE<<A/EEAE<EEA +@NS500443:42:H3MH2AFXX:1:11101:17849:1071/2 +GTGGAGACGGTTCTTATCACGGTGCTGAGGCTCTTACTAAACGTGGTTTCCCAACAATTGGAATTCCGGGAACAATCGATAATGATATTTCAGGAACAGACTTCACAATAGGTTTCGATACAGCGCTAAATACAGTTTTAGACGCACTTGA ++ +AAAAAE6EE6EEEEEEEE/EEEEAE6EEAEEEEEEAEEEAEAEAEEEEEEAEAE6EEEEEEEEEEEAEEEAEEEEEEEEEEEEA6EAEAEA/AEAEE6EA6EEE<A/EE/EEEE//E/<AE/6AEAE//EEEAAEE/AA6E<AAEA6EAEA diff --git a/src/FqAuxBackend.cpp b/src/FqAuxBackend.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f97f7857e0c1c248a93ca501f47d5a36bad4c942 --- /dev/null +++ b/src/FqAuxBackend.cpp @@ -0,0 +1,115 @@ +/* + * FqAuxProcessor.cpp + * + * Created on: Jan 7, 2016 + * Author: vlegrand + */ + +#include "FqConstants.h" +#include <stdio.h> +//#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <err.h> +#include "FqAuxBackend.h" + + + +int FqAuxBackend::getNextRead(rinfo * p_nr) { + rinfo nr; + int rfound=0; + int eof=0; + + while (!rfound) { + if (pos_in_buf>=nread-1) readBuffer(); + if (nread==0) { eof=1; break;} + rfound=processBuffer(p_nr); + } + return eof; +} + +int FqAuxBackend::processBuffer(rinfo * p_nr) { + unsigned int s; + static unsigned int st; + static int num_l_in_rec; /* counter to know on which line inside the fastq record we are */ + static int qual_score=0; + static unsigned long rstart_offset; + char * pchar=buf+pos_in_buf; + int rfound=0; + while (pos_in_buf<=nread-1 && !rfound) { + switch (*pchar){ + case k_read_id_start: { + rstart_offset=cur_offset-nread+pos_in_buf; + num_l_in_rec=1; } + break; + case k_read_qual_start: { + qual_score=1; + st=0;} + break; + case '\n': { + num_l_in_rec+=1; + if (num_l_in_rec==5) {qual_score=0;/* end of fastq record */ + // debug stuff + /*printf("\nquality score is : %d \n",st); + printf("read start_offset is %lu \n",rstart_offset);*/ + p_nr->f_id=f_id; + p_nr->score=st; + p_nr->rstart_offset=rstart_offset; + rfound=1; + } + } + break; + default: + { if (qual_score==1) { + s=(int)*pchar; + s-=k_phred_32; + st+=s; + } + } + } + pchar++; + pos_in_buf++; + } + return rfound; +} + + +void FqAuxBackend::readBuffer() { + if ((nread=read(f_pe2,buf,bufsize))!=0) { + cur_offset=ftell(fp2); + pos_in_buf=0; + } +} +/* + * Opens file and performs the fist read operation. + */ +void FqAuxBackend::openFile(char * ficname, unsigned char id) { + int st,s; + // unsigned long cur_offset; + mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + + closeFile(); + filename=ficname; + f_id=id; + + f_pe2=open(filename,O_RDONLY,mode); + if (f_pe2==-1) { + err(errno,"cannot open file: %s.",filename); + } + + fp2=fdopen(f_pe2,"r"); + if (fp2==NULL) { + err(errno,"cannot open file: %s.",filename); + } + + } + +void FqAuxBackend::closeFile() { + if (filename!=NULL) { + close(f_pe2); + filename=NULL; + } + } + + diff --git a/src/FqAuxBackend.h b/src/FqAuxBackend.h new file mode 100644 index 0000000000000000000000000000000000000000..bc767e6c1c98960879a264c8f1c325feea2d9909 --- /dev/null +++ b/src/FqAuxBackend.h @@ -0,0 +1,46 @@ +/* + * FqAuxProcessor.h + * + * Created on: Jan 7, 2016 + * Author: vlegrand + */ + +#ifndef FQAUXBACKEND_H_ +#define FQAUXBACKEND_H_ + +#include "srp.h" +const size_t bufsize=10240; + +class FqAuxBackend { + char * filename; + unsigned char f_id; + char buf[bufsize]; + int nread; + int f_pe2; // for calling read + FILE * fp2; // for calling ftell + unsigned long cur_offset; + int pos_in_buf; + + void readBuffer(); + int processBuffer(rinfo * p_nr); + +public: + + FqAuxBackend() { + filename=NULL; + f_pe2=-1; + fp2=NULL; + f_id=0; + cur_offset=0; + nread=0; + pos_in_buf=bufsize; // do that to force first reading in buffer. + } + + void openFile(char * ficname, unsigned char id); + + void closeFile(); + int getNextRead(rinfo *); + +}; + +#endif /* FQAUXBACKEND_H_ */ diff --git a/src/FqConstants.h b/src/FqConstants.h new file mode 100644 index 0000000000000000000000000000000000000000..e41463a17efac020316b8347839baf4ee6f7df9f --- /dev/null +++ b/src/FqConstants.h @@ -0,0 +1,15 @@ +/* + * FqConstants.h + * + * Created on: Jan 7, 2016 + * Author: vlegrand + */ + +#ifndef FQCONSTANTS_H_ +#define FQCONSTANTS_H_ + +#define k_read_id_start '@' +#define k_read_qual_start '+' +#define k_phred_32 33 + +#endif /* FQCONSTANTS_H_ */ diff --git a/src/FqMainBackend.cpp b/src/FqMainBackend.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8d4214adf2d8d9f180d5bfcfad195b1fbd29aa3 --- /dev/null +++ b/src/FqMainBackend.cpp @@ -0,0 +1,114 @@ +/* + * FqMainProcessor.cpp + * + * Created on: Jan 7, 2016 + * Author: vlegrand + */ + +#include <stdio.h> +//#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <err.h> +#include <limits.h> +#include <assert.h> + +#include "FqMainBackend.h" +#include "srp.h" + +rpos init_rpos(unsigned char f_id, unsigned long rstart_offset) { + rpos rp; + rp.fileid=f_id <<4; + rp.read_a1=rstart_offset%INT_MAX; + return rp; +} + +/* + * Add Paired read information to already existing rpos structure. + */ +void update_rpos(unsigned char f_id,unsigned long rstart_offset,unsigned long j, rpos * rp) { + rp->fileid=rp->fileid|f_id; + rp->read_a2=rstart_offset-INT_MAX*j; +} + + +void FqMainBackend::processFile(char * filename,unsigned char f_id) { + FILE * fp; + int st,s; + int cnt,nread; + unsigned long cur_offset; + mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + char buf[bufsize]; + int f_single=open(filename,O_RDONLY,mode); + if (f_single==-1) { + err(errno,"cannot open file: %s.",filename); + } + + fp=fdopen(f_single,"r"); + if (fp==NULL) { + err(errno,"cannot open file: %s.",filename); + } + + /* for each read, we want : offset, filenb, total quality score. */ + while ((nread=read(f_single,buf,bufsize))!=0) { + // printf("%s",buf); + cur_offset=ftell(fp); + processBuf((char *)&buf,nread,f_id,cur_offset); + } + close(f_single); + +} + + +void FqMainBackend::processBuf(char * buf,int nread,unsigned char f_id,unsigned long cur_offset) { + int cnt=0; + unsigned int s; + static unsigned int st; + static int num_l_in_rec; /* counter to know on which line inside the fastq record we are */ + static int qual_score=0; + static unsigned long rstart_offset; + char * pchar=buf; + while (cnt<=nread-1) { + switch (*pchar){ + case k_read_id_start: { + rstart_offset=cur_offset-nread+cnt; + num_l_in_rec=1; } + break; + case k_read_qual_start: { + qual_score=1; + st=0;} + break; + case '\n': { + num_l_in_rec+=1; + if (num_l_in_rec==5) {qual_score=0;/* end of fastq record */ + // debug stuff + /*printf("\nquality score is : %d \n",st); + printf("read start_offset is %lu \n",rstart_offset);*/ + rpos rp=init_rpos(f_id,rstart_offset); + if (p_auxFqProcessor!=NULL) { + rinfo pe2info; + int eof=p_auxFqProcessor->getNextRead(&pe2info); + assert(!eof); // There should be the same number of reads in both PE files. + st+=pe2info.score; + unsigned long j=rstart_offset/INT_MAX; + update_rpos(pe2info.f_id,pe2info.rstart_offset,j,&rp); + } + i_dim& ref_i_dim=(*p_scoreReadStruct)[st/K_SCORE_NORM_FACTOR]; + k_dim& ref_k_dim=ref_i_dim[rstart_offset/INT_MAX]; + ref_k_dim.push_back(rp); } + } + break; + default: + { if (qual_score==1) { + s=(int)*pchar; + s-=k_phred_32; + st+=s; + } + } + } + pchar++; + cnt++; + } +} + diff --git a/src/FqMainBackend.h b/src/FqMainBackend.h new file mode 100644 index 0000000000000000000000000000000000000000..610a6a3b7be85d1de7fe1f7ff8c9a3659cb13dad --- /dev/null +++ b/src/FqMainBackend.h @@ -0,0 +1,37 @@ +/* + * FqMainProcessor.h + * + * Created on: Jan 7, 2016 + * Author: vlegrand + * + * Processes a fastq file (single or first of a pair of files that contain PE reads); Fills an srp data structure. + */ + +#ifndef FQMAINBACKEND_H_ +#define FQMAINBACKEND_H_ + +#include "FqAuxBackend.h" +#include "FqConstants.h" + +class FqMainBackend { + FqAuxBackend * p_auxFqProcessor; /* Another fastq processor component is necessary for handling the case of PE reads.*/ + srp * p_scoreReadStruct; /* Where we store information about the reads. */ + +public: + FqMainBackend(srp * io_sr) { + p_scoreReadStruct=io_sr; + p_auxFqProcessor=NULL; + } + + + + void setAuxProcessor(FqAuxBackend* fq2ndProc) { + p_auxFqProcessor=fq2ndProc; + } + + void processFile(char * filename,unsigned char f_id); + + void processBuf(char * buf,int nread,unsigned char f_id,unsigned long cur_offset); +}; + +#endif /* FQMAINBACKEND_H_ */ diff --git a/src/Makefile.am b/src/Makefile.am index ecd0fde11583d36adedcaa6189fa33086b1a10d3..6763ca1aa7b40c095d98e690d0768270db99cb38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,5 +16,5 @@ unit_test_fqreader_LDADD=librock.a librock_a_SOURCES = $(SRC) -SRC = fqreader.cpp -HDR = srp.h fqreader.h \ No newline at end of file +SRC = fqreader.cpp FqAuxBackend.cpp FqMainBackend.cpp +HDR = srp.h fqreader.h FqConstants.h FqAuxBackend.h FqMainBackend.h \ No newline at end of file diff --git a/src/fqreader.cpp b/src/fqreader.cpp index 7171d022ff9dcad39aa14dc986f0b866f824a1c4..182a1d738c43be73808bb3e43ccb6816f2162023 100644 --- a/src/fqreader.cpp +++ b/src/fqreader.cpp @@ -14,102 +14,38 @@ //#include "srp.h" #include "fqreader.h" +#include "FqMainBackend.h" + + +/* +typedef struct { + char buf[bufsize]; + unsigned char f_id; + int nread; + unsigned long cur_offset; +}fastq_buf;*/ + -const size_t bufsize=10240; -// const size_t nb_reads=6; /* for my tests for the moment */ -rpos init_rpos(unsigned char f_id, unsigned long rstart_offset) { - rpos rp; - rp.fileid=f_id <<4; - unsigned long j,k; - k=rstart_offset%INT_MAX; - j=rstart_offset/INT_MAX; - rp.read_a1=rstart_offset-INT_MAX*j; - return rp; -} -/* - * Assume qualiy is phred 32. - * Main idea : a fqreader component takes as input files containing single reads or files containing PE reads and fills a structure on which other components can work on... - */ -void processBuf(char * buf,int nread,unsigned char f_id,unsigned long cur_offset, srp * io_sr) { - int cnt=0; - unsigned int s; - static unsigned int st; - static int num_l_in_rec; /* counter to know on which line inside the fastq record we are */ - static int qual_score=0; - static unsigned long rstart_offset; - char * pchar=buf; - while (cnt<=nread-1) { - switch (*pchar){ - case k_read_id_start: { - rstart_offset=cur_offset-nread+cnt; - num_l_in_rec=1; } - break; - case k_read_qual_start: { - qual_score=1; - st=0;} - break; - case '\n': { - num_l_in_rec+=1; - if (num_l_in_rec==5) {qual_score=0;/* end of fastq record */ - // debug stuff - /*printf("\nquality score is : %d \n",st); - printf("read start_offset is %lu \n",rstart_offset);*/ - rpos rp=init_rpos(f_id,rstart_offset); - i_dim& ref_i_dim=(*io_sr)[st/K_SCORE_NORM_FACTOR]; - k_dim& ref_k_dim=ref_i_dim[rstart_offset/INT_MAX]; - ref_k_dim.push_back(rp); - } - } - break; - default: - { if (qual_score==1) { - s=(int)*pchar; - s-=k_phred_32; - st+=s; - } - } - } - pchar++; - cnt++; - } -} /* * Processes 1 file containing single reads */ void processSingleFile(char * fq_s,unsigned char f_id, srp* io_sr) { - FILE * fp; - int st,s; - int cnt,nread; - unsigned long cur_offset,rstart_offset; - mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - char buf[bufsize]; - int f_single=open(fq_s,O_RDONLY,mode); - if (f_single==-1) { - err(errno,"cannot open file: %s.",fq_s); - } - - fp=fdopen(f_single,"r"); - if (fp==NULL) { - err(errno,"cannot open file: %s.",fq_s); - } - - /* for each read, we want : offset, filenb, total quality score. */ - while ((nread=read(f_single,buf,bufsize))!=0) { - // printf("%s",buf); - cur_offset=ftell(fp); - processBuf((char *)&buf,nread,f_id,cur_offset,io_sr); - } - close(f_single); - + FqMainBackend be_fq=FqMainBackend(io_sr); + be_fq.processFile(fq_s,f_id); } /* Processes 1 pair of files containing PE reads.*/ -void processPEFiles(char * fq_1, int f_id1,char * gq_2, int f_id2,srp * io_sr ) { - +void processPEFiles(char * fq_1, unsigned char f_id1,char * fq_2, unsigned char f_id2,srp * io_sr ) { + FqMainBackend be_fq1=FqMainBackend(io_sr); + FqAuxBackend be_fq2=FqAuxBackend(); + be_fq2.openFile(fq_2,f_id2); + be_fq1.setAuxProcessor(&be_fq2); + be_fq1.processFile(fq_1,f_id1); + be_fq2.closeFile(); } diff --git a/src/fqreader.h b/src/fqreader.h index 7a319d649baec1f51d70dbedbe2a36d857d7ab3e..cc664c7274125cabe3b764fa456a17a220720ec8 100644 --- a/src/fqreader.h +++ b/src/fqreader.h @@ -8,12 +8,10 @@ #define FQREADER_H #include "srp.h" -#define k_read_id_start '@' -#define k_read_qual_start '+' -#define k_phred_32 33 + /*void processBuf(char * buf,int nread,int cur_offset);*/ void processSingleFile(char *, unsigned char, srp*); -void processPEFiles(char * fq_1, int f_id1,char * gq_2, int f_id2,srp *io_sr ); +void processPEFiles(char * fq_1, unsigned char f_id1,char * gq_2, unsigned char f_id2,srp *io_sr ); #endif diff --git a/src/srp.h b/src/srp.h index 1941b1699ecf8ac32ff498e8bec75dbcb35d8860..488cd23e05825bf54aaaa11a988b72c7825eb874 100644 --- a/src/srp.h +++ b/src/srp.h @@ -13,12 +13,22 @@ #define K_SCORE_NORM_FACTOR 1000 -typedef struct { /* Here store read offset in file whose id is fileid.*/ +typedef struct { /* Here store read offset in files whose ids are stored in the fileid field .*/ unsigned char fileid; unsigned long read_a1; unsigned long read_a2; }rpos; + + + + +typedef struct { + unsigned int score; // total quality score for read. + unsigned long rstart_offset; // read offset in file + unsigned char f_id; // identifier of the file. +}rinfo; + typedef std::vector<rpos> k_dim; typedef std::map<unsigned long,k_dim> i_dim; typedef std::map<unsigned long,i_dim> srp; diff --git a/src/unit_test_fqreader.cpp b/src/unit_test_fqreader.cpp index 43d3b3ad843a8a174c994d0e82104b3175ea6ba4..61db57c805ce0d701827f256565fede68b4287ee 100644 --- a/src/unit_test_fqreader.cpp +++ b/src/unit_test_fqreader.cpp @@ -17,7 +17,7 @@ using namespace std; void test_processSingleFile() { - printf("MAX_UINT=%u \n",UINT_MAX); + //printf("MAX_UINT=%u \n",UINT_MAX); srp sr; unsigned char f_id=1; processSingleFile((char *) "data/test_single.fq",f_id,&sr); @@ -28,7 +28,7 @@ void test_processSingleFile() { int cnt_read=0; for (rit=sr.rbegin(); rit!=sr.rend(); ++rit) { //process map in reverse order (by decreasing scores). - // cout << "score="<<rit->first<<endl; + //cout << "score="<<rit->first<<endl; unsigned long score=rit->first; assert(score==5); for (it_offs=rit->second.begin();it_offs!=rit->second.end();it_offs++) { @@ -56,10 +56,94 @@ void test_processPEFiles() { char * fq_1_test=(char *) "data/test_PE1.fq"; char * fq_2_test=(char *) "data/test_PE2.fq"; + unsigned char f_id1=1; + unsigned char f_id2=2; + + srp sr; + + processPEFiles(fq_1_test, f_id1,fq_2_test, f_id2,&sr); + srp::reverse_iterator rit; + i_dim::iterator it_offs; + k_dim::iterator it_struct; + int cnt_read=0; + + unsigned char masque=0x0F; + + for (rit=sr.rbegin(); rit!=sr.rend(); ++rit) { //process map in reverse order (by decreasing scores). + // cout << "score="<<rit->first<<endl; + unsigned long score=rit->first; + if (cnt_read==0 || cnt_read==1) assert(score==10); + if (cnt_read==2) assert(score==9); + for (it_offs=rit->second.begin();it_offs!=rit->second.end();it_offs++) { + unsigned long offset_quotient=it_offs->first; + assert(offset_quotient==0); + for (it_struct=it_offs->second.begin();it_struct!=it_offs->second.end();it_struct++) { + unsigned char fid_stored=it_struct->fileid; + assert(fid_stored >>4==f_id1); + assert((fid_stored &masque)==f_id2); + if (cnt_read==0) { + assert(it_struct->read_a1==0); + assert(it_struct->read_a1==0); + } + if (cnt_read==1) { + //std::cout<<it_struct->read_a1<<" "<<it_struct->read_a2; + assert(it_struct->read_a1==349); + assert(it_struct->read_a2==349); + } + if (cnt_read==2) { + // std::cout<<it_struct->read_a1<<" "<<it_struct->read_a2; + assert(it_struct->read_a1==698); + assert(it_struct->read_a2==698); + } + cnt_read++; + /* + int tmp1=fid_stored >>4; + int tmp2=fid_stored &masque; + cout<<" fileid1="<<tmp1<<" read_a1="<<it_struct->read_a1<<endl; + cout<<" fileid2="<<tmp2<<" read_a2="<<it_struct->read_a2<<endl; */ + } + } + } + assert(cnt_read==3); } void test_processAllFiles() { + char * fq_1_test=(char *) "data/test_PE1.fq"; + char * fq_2_test=(char *) "data/test_PE2.fq"; + char * fq_single=(char *) "data/test_single.fq"; + unsigned char f_id1=1; + unsigned char f_id2=2; + unsigned char f_single=3; + + srp sr; + + processPEFiles(fq_1_test, f_id1,fq_2_test, f_id2,&sr); + processSingleFile(fq_single,f_single,&sr); + + srp::reverse_iterator rit; + i_dim::iterator it_offs; + k_dim::iterator it_struct; + int cnt_read=0; + + for (rit=sr.rbegin(); rit!=sr.rend(); ++rit) { //process map in reverse order (by decreasing scores). + // cout << "score="<<rit->first<<endl; + unsigned long score=rit->first; + if (cnt_read==0 || cnt_read==1) assert(score==10); + else if (cnt_read==2) assert(score==9); + else { + //cout << "score="<<rit->first<<endl; + assert(score==5); + } + for (it_offs=rit->second.begin();it_offs!=rit->second.end();it_offs++) { + unsigned long offset_quotient=it_offs->first; + assert(offset_quotient==0); + for (it_struct=it_offs->second.begin();it_struct!=it_offs->second.end();it_struct++) { + cnt_read++; + } + } + } + assert(cnt_read==9); } int main(int argc, char **argv) { @@ -67,7 +151,4 @@ int main(int argc, char **argv) { test_processSingleFile(); test_processPEFiles(); test_processAllFiles(); /* mix PE together with single; nearly as in real life.*/ - - - /*void test_processPEFiles(fq_1_test,fq_2_test);*/ }