Beispiel #1
0
void IntervalTree::GetUnion(IntervalTreeNode *x, int **start, int **stop, int *nInterval, int *nAlloc, double nAllocExpansion) {
  if (x != nil) {
    GetUnion(x->left,start,stop,nInterval,nAlloc,nAllocExpansion);
    if(*nInterval>0 && (*stop)[(*nInterval) - 1] >= x->key) {
      // extend an existing interval
      if(x->high > (*stop)[(*nInterval)-1])
        (*stop)[(*nInterval)-1] = x->high;
    } else {
      // add a new interval
      if(*nInterval == *nAlloc) {
        // need to allocate more memory
        *nAlloc = ceil(*nAlloc * nAllocExpansion);
	*start = (int *)realloc(*start, *nAlloc * sizeof(int));
        if(*start == NULL) {
          fprintf(stderr,"problem reallocating memory for %d ints for region starts, unable to compute the requested union\n",*nAlloc);
          return;
        }
	*stop =  (int *)realloc(*stop,  *nAlloc * sizeof(int));
        if(*stop == NULL) {
          fprintf(stderr,"problem reallocating memory for %d ints for region stops, unable to compute the requested union\n",*nAlloc);
          return;
        }
      }
      (*start)[*nInterval] = x->key;
      (*stop)[*nInterval]  = x->high;
      *nInterval += 1;
    }
    GetUnion(x->right,start,stop,nInterval,nAlloc,nAllocExpansion);
  }
}
Beispiel #2
0
void IntervalTree::GetUnion(int **start, int **stop, int *nInterval, int nAlloc, double nAllocExpansion) {
  *nInterval = 0;

  if(nAllocExpansion <= 1) {
    fprintf(stderr,"nAllocExpansion must be greater than 1, unable to compute union\n");
    return;
  }
  *start = (int *)malloc(nAlloc*sizeof(int));
  if(start == NULL) {
    fprintf(stderr,"problem allocating memory for %d ints for region starts, unable to compute the requested union\n",nAlloc);
    return;
  }
  *stop  = (int *)malloc(nAlloc*sizeof(int));
  if(stop == NULL) {
    fprintf(stderr,"problem allocating memory for %d ints for region stops, unable to compute the requested union\n",nAlloc);
    return;
  }
  GetUnion(root->left,start,stop,nInterval,&nAlloc,nAllocExpansion);
}
Beispiel #3
0
void Jaccard::CalculateJaccard() {

    unsigned long U = GetUnion();
    delete _bedA;
    delete _bedB;
    unsigned long I = GetIntersection();
    
    // header
    cout << "intersection\t"
         << "union\t"
         << "jaccard"
         << endl;
    
    // result
    cout << I << "\t" 
         << U - I << "\t"
         << (float) I / ((float) U - (float) I)
         << endl;
}