struct bed *findMostOverlapping(struct bed *bed, struct hash *keeperHash) /* Try find most overlapping thing to bed in keeper hash. */ { struct bed *bestBed = NULL; int bestOverlap = 0; struct binKeeper *bk = hashFindVal(keeperHash, bed->chrom); if (bk == NULL) return NULL; struct binElement *bin, *binList = binKeeperFind(bk, bed->chromStart, bed->chromEnd); for (bin = binList; bin != NULL; bin = bin->next) { struct bed *bed2 = bin->val; if (bed2->strand[0] == bed->strand[0]) { int overlap = bedSameStrandOverlap(bed2, bed); if (overlap > bestOverlap) { bestOverlap = overlap; bestBed = bed2; } } } slFreeList(&binList); return bestBed; }
double bedOverlapRatio(struct bed *a, struct bed *b) /* Return TRUE if a overlaps b by at least given ratio. */ { int aSize = bedTotalBlockSize(a); int bSize = bedTotalBlockSize(b); int overlapSize = bedSameStrandOverlap(a,b); if (aSize == bSize && aSize == overlapSize) return 1.0; /* Avoid rounding here. */ double x = overlapSize; double aCov = x / aSize; double bCov = x / bSize; return min(aCov, bCov); }