Пример #1
0
//this function is called from within the bamreader
void callBack_bambi(fcb *fff){

  if(fff==NULL){
    //    fprintf(stderr,"SEnding NULL this is a killswitch");
    selector(NULL);//<-send NULL which acts as a killswitch
  }else{
    funkyPars *fp = allocFunkyPars();
    fp->for_callback=fff;
    fp->refId = fp->for_callback->refId;
    selector(fp);
  }
}
Пример #2
0
funkyPars *vcfReader::fetch(int chunkSize){
  //  fprintf(stderr,"fetch:%d curChr:%d\n\n",chunkSize,curChr);
  static int eof=0;
  if(eof)
    return NULL;
  funkyPars *r = allocFunkyPars();  
  //  r->likes=r->post=NULL;
  r->likes=new double*[chunkSize];
  r->post=new double*[chunkSize];
  for(int i=0;i<chunkSize;i++){
    memset(r->likes,0,chunkSize*sizeof(double*));
    memset(r->post,0,chunkSize*sizeof(double*));
  }
  r->posi=new int[chunkSize];
  r->major = new char[chunkSize];
  r->minor = new char[chunkSize];
  
  memset(r->major,0,chunkSize);
  memset(r->minor,0,chunkSize);
  //  fprintf(stderr,"curChr:%d\n",curChr);
  r->refId = curChr;
  
  static int changed =0;
 reread:
  int i=0;
  if(changed){
    //    fprintf(stderr,"inchange\n");
    int p = parseline(r->likes,r->post,r->major[0],r->minor[0]);
    if(p>0)
      r->posi[i++]=p-1;
  }

  changed=0;
  int cnt=i;//counter for the in-array position.
  buf=original;
  for(;i<chunkSize;i++){
    if(0==aio::tgets(gz,&buf,&len)){
      fprintf(stderr,"\t-> Done reading vcffile\n");fflush(stderr);
      eof=1;
      break;
    }
    if(buf!=original)
      original=buf;
    //    fprintf(stderr,"in for loop2\n");
    buf[strlen(buf)-1] = '\0';
    saveptr=buf;
  
    char *tmp = strchr(saveptr,'\t');
    tmp[0]='\0';
    char *chr = saveptr;
    saveptr=tmp+1;

    aMap::const_iterator it=revMap->find(chr);
    if(it==revMap->end()){
      fprintf(stderr,"Problem finding chromosome: %s in fai file\n",chr);
      exit(0);
    }

    if(curChr==-1){
      //init chr
      r->refId=curChr=it->second;
    }
    if(curChr!=it->second){
      changed =1;
      curChr=it->second;
      //      fprintf(stderr,"breaking for change of chr\n");
      break;
    }
    //  fprintf(stderr,"in for loop3\n");
    int p = parseline(r->likes+cnt,r->post+cnt,r->major[cnt],r->minor[cnt]);
    //  fprintf(stderr,"in for loop4\n");
    buf=original;
    if(p==0)
      continue;
    else{
      r->posi[cnt]=p-1;
      cnt++;//only update cnt
    }
  }
  r->nInd=nInd;
  r->numSites=cnt;
  //  fprintf(stderr,"\t-> r->nind:%d r->numSites:%d r->refId:%d\n",r->nInd,r->numSites,r->refId);
  if(r->numSites==0&&eof!=1)
    goto reread;
  //  fprintf(stderr,"\t-> r->nind:%d r->numSites:%d r->refId:%d\n",r->nInd,r->numSites,r->refId);
  return r;
}
Пример #3
0
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);
}
Пример #4
0
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);

}