/************************************ Helper functions ************************************/ bool BedIntersect::processHits(const BED &a, const vector<BED> &hits) { bool hitsFound = false; if (_printable == true) { // -wao the user wants to force the reporting of 0 overlap if (hits.size() == 0) { if (_writeAllOverlap) { _bedA->reportBedTab(a); _bedB->reportNullBedTab(); printf("0\n"); } else if (_leftJoin) { _bedA->reportBedTab(a); _bedB->reportNullBedNewLine(); } } else { vector<BED>::const_iterator h = hits.begin(); vector<BED>::const_iterator hitsEnd = hits.end(); for (; h != hitsEnd; ++h) { CHRPOS s = max(a.start, h->start); CHRPOS e = min(a.end, h->end); int overlapBases = (e - s); ReportOverlapDetail(overlapBases, a, *h, s, e); hitsFound = true; } } } else { ReportOverlapSummary(a, hits.size()); } return hitsFound; }
/************************************ Helper functions ************************************/ bool BedIntersect::processHits(const BED &a, const vector<BED> &hits, bool printable) { // how many overlaps are there b/w the bed and the set of hits? int s, e, overlapBases; int numOverlaps = 0; bool hitsFound = false; int aLength = (a.end - a.start); // the length of a in b.p. // loop through the hits and report those that meet the user's criteria vector<BED>::const_iterator h = hits.begin(); vector<BED>::const_iterator hitsEnd = hits.end(); for (; h != hitsEnd; ++h) { s = max(a.start, h->start); e = min(a.end, h->end); overlapBases = (e - s); // the number of overlapping bases b/w a and b // is there enough overlap relative to the user's request? (default ~ 1bp) if ( ( (float) overlapBases / (float) aLength ) >= _overlapFraction ) { // Report the hit if the user doesn't care about reciprocal overlap between A and B. if (_reciprocal == false) { hitsFound = true; numOverlaps++; if (printable == true) ReportOverlapDetail(overlapBases, a, *h, s, e); } // we require there to be sufficient __reciprocal__ overlap else { int bLength = (h->end - h->start); float bOverlap = ( (float) overlapBases / (float) bLength ); if (bOverlap >= _overlapFraction) { hitsFound = true; numOverlaps++; if (printable == true) ReportOverlapDetail(overlapBases, a, *h, s, e); } } } } // report the summary of the overlaps if requested. ReportOverlapSummary(a, numOverlaps); // were hits found for this BED feature? return hitsFound; }