funkyPars *beagle_reader::fetch(int chunksize){ char refToChar[256] = { 0,1,2,3,4,4,4,4,4,4,4,4,4,4,4,4,//15 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//31 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//47 0,1,2,3,4,4,4,4,4,4,4,4,4,4,4,4,//63 4,0,4,1,4,4,4,2,4,4,4,4,4,4,4,4,//79 4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,//95 4,0,4,1,4,4,4,2,4,4,4,4,4,4,4,4,//111 4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,//127 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//143 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//159 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//175 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//191 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//207 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//223 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,//239 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4//255 }; static const char *delims = "\t \n"; static const char *delims2 = "_\t \n"; double **post = new double*[chunksize]; funkyPars * myfunky =allocFunkyPars(); myfunky->posi = new int[chunksize]; myfunky->major = new char[chunksize]; myfunky->minor = new char[chunksize]; for(int s=0;s<chunksize;s++) post[s] = new double[nInd*3]; int nSites=0; static int positions =0;//every site is a new position across different chunks static int lastRefId =-1; static int changed =0; if(changed){ //parse an entire site: myfunky->refId = lastRefId; myfunky->posi[nSites] = atoi(strtok_r(NULL,delims2,&buffer))-1; myfunky->major[nSites] = refToChar[strtok_r(NULL,delims,&buffer)[0]]; myfunky->minor[nSites] = refToChar[strtok_r(NULL,delims,&buffer)[0]]; parsepost(buffer,post[nSites],nInd,delims); nSites++; changed =0; } buffer=original; while(gzgets(gz,buffer,bytesPerLine)) { if(strlen(buffer)==bytesPerLine-1){ fprintf(stderr,"\t-> Increase -bytesPerLine value\n"); exit(0); } if(intName){ char *tok = strtok_r(buffer,delims2,&buffer); aMap ::const_iterator it = revMap->find(tok); if(it==revMap->end()){ fprintf(stderr,"\t-> Problem finding chr:%s from faifile\n",tok); exit(0); } if(lastRefId==-1) lastRefId = it->second; if(lastRefId!=it->second){ changed =1; lastRefId = it->second; break; } lastRefId = it->second; myfunky->refId = lastRefId; myfunky->posi[nSites] = atoi(strtok_r(NULL,delims2,&buffer))-1; } else{ char *tok = strtok_r(buffer,delims,&buffer); myfunky->refId = 0; myfunky->posi[nSites] = positions++; } myfunky->major[nSites] = refToChar[strtok_r(NULL,delims,&buffer)[0]]; myfunky->minor[nSites] = refToChar[strtok_r(NULL,delims,&buffer)[0]]; parsepost(buffer,post[nSites],nInd,delims); buffer=original; nSites++; if(nSites>=chunksize) break; } if(nSites<chunksize){ for(int s=nSites;s<chunksize;s++) delete[] post[s]; } myfunky->nInd=nInd; myfunky->post=post; myfunky->numSites = nSites; if(nSites==0){ delete [] post; deallocFunkyPars(myfunky); return(NULL); } return(myfunky); }
funkyPars *mpileup::fetch(int chunksize){ static const char *delims = "\t \n"; funkyPars * myfunky =allocFunkyPars(); myfunky->posi = new int[chunksize]; myfunky->ref = new char[chunksize]; myfunky->chk = new chunkyT; myfunky->chk->nd = new tNode **[chunksize]; myfunky->chk->refPos = NULL; int nSites=0; static int lastRefId =-1; static int changed =0; aMap ::const_iterator it; if(changed){ //parse an entire site: myfunky->refId = lastRefId; myfunky->posi[nSites] = atoi(strtok_r(NULL,delims,&buffer))-1; myfunky->ref[nSites] = refToInt[strtok_r(NULL,delims,&buffer)[0]]; myfunky->chk->nd[nSites++] = parseNd(buffer,nInd,delims,minQ); changed =0; } buffer=original; while(aio::tgets(gz,&buffer,&l)) { if(buffer!=original) original=buffer; char *tok = strtok_r(buffer,delims,&buffer); it=revMap->find(tok); if(it==revMap->end()){ fprintf(stderr,"\t-> Problems finding reference \'%s\' in fai file\n",tok); exit(0); } if(lastRefId==-1) lastRefId = it->second; if(lastRefId!=it->second){ changed =1; lastRefId = it->second; myfunky->refId = lastRefId; break; } lastRefId = it->second; myfunky->refId = lastRefId; myfunky->posi[nSites] = atoi(strtok_r(NULL,delims,&buffer))-1; myfunky->ref[nSites] = refToInt[strtok_r(NULL,delims,&buffer)[0]]; myfunky->chk->nd[nSites++] = parseNd(buffer,nInd,delims,minQ); buffer=original; if(nSites>=chunksize) break; } // fprintf(stderr,"afterloop\n"); myfunky->nInd=myfunky->chk->nSamples= nInd; myfunky->numSites = myfunky->chk->nSites=nSites; //fprintf(stderr,"\nchange2 %d\tnSites %d\tlastRefId\t%d %d %d\n",lastRefId,nSites,lastRefId,myfunky->refId,it->second); // fflush(stderr); if(nSites==0 && changed == 0){ deallocFunkyPars(myfunky); return(NULL); } return(myfunky); }