Пример #1
0
void PairToPair::FindOverlaps(const BEDPE &a) {
    //
    vector<MATE> hitsA1B1, hitsA1B2, hitsA2B1, hitsA2B2;

    // add the appropriate slop to the starts and ends
    int start1 = a.start1;
    int end1   = a.end1;
    int start2 = a.start2;
    int end2   = a.end2;

    if (_strandedSlop == true) {
        if (a.strand1 == "+")
            end1   += _slop;
        else
            start1 -= _slop;
        if (a.strand2 == "+")
            end2   += _slop;
        else
            start2 -= _slop;
    }
    else {
        (start1 - _slop) >= 0 ? start1 -= _slop : start1 = 0;
        (start2 - _slop) >= 0 ? start2 -= _slop : start2 = 0;
        end1   += _slop;
        end2   += _slop;
    }

    // Find the _potential_ hits between each end of A and B
    _bedB->FindOverlapsPerBin(1, a.chrom1, start1, end1, a.name, a.strand1, hitsA1B1, _overlapFraction, !(_ignoreStrand), _reqDiffNames);   // hits b/w A1 & B1
    _bedB->FindOverlapsPerBin(1, a.chrom2, start2, end2, a.name, a.strand2, hitsA2B1, _overlapFraction, !(_ignoreStrand), _reqDiffNames);   // hits b/w A2 & B1
    _bedB->FindOverlapsPerBin(2, a.chrom1, start1, end1, a.name, a.strand1, hitsA1B2, _overlapFraction, !(_ignoreStrand), _reqDiffNames);   // hits b/w A1 & B2
    _bedB->FindOverlapsPerBin(2, a.chrom2, start2, end2, a.name, a.strand2, hitsA2B2, _overlapFraction, !(_ignoreStrand), _reqDiffNames);   // hits b/w A2 & B2

    unsigned int matchCount1 = (hitsA1B1.size() + hitsA2B2.size());
    unsigned int matchCount2 = (hitsA2B1.size() + hitsA1B2.size());

    
    // report the fact that no hits were found iff _searchType is neither.
    if ((matchCount1 == 0) && (matchCount2 == 0) && (_searchType == "neither")) {
        _bedA->reportBedPENewLine(a);
    }
    else if (_searchType == "both")  {
        bool found1 = false;
        bool found2 = false;
        if ((hitsA1B1.size() > 0) || (hitsA2B2.size() > 0))
            found1 = FindHitsOnBothEnds(a, hitsA1B1, hitsA2B2);
        if ((hitsA2B1.size() > 0) || (hitsA1B2.size() > 0))
            found2 = FindHitsOnBothEnds(a, hitsA2B1, hitsA1B2);
    }
    else if (_searchType == "notboth")  {
        bool found1 = false;
        bool found2 = false;
        if ((hitsA1B1.size() > 0) || (hitsA2B2.size() > 0))
            found1 = FindHitsOnBothEnds(a, hitsA1B1, hitsA2B2);
        if ((hitsA2B1.size() > 0) || (hitsA1B2.size() > 0))
            found2 = FindHitsOnBothEnds(a, hitsA2B1, hitsA1B2);
        if (found1 == false && found2 == false)
            _bedA->reportBedPENewLine(a);
    }
    else if (_searchType == "either") {
        FindHitsOnEitherEnd(a, hitsA1B1, hitsA2B2);
        FindHitsOnEitherEnd(a, hitsA2B1, hitsA1B2);
    }
}
Пример #2
0
void PairToPair::FindOverlaps(const BEDPE &a, vector<BEDCOV> &hitsA1B1, vector<BEDCOV> &hitsA1B2, 
							  vector<BEDCOV> &hitsA2B1, vector<BEDCOV> &hitsA2B2) {

	// list of hits on each end of BEDPE
	// that exceed the requested overlap fraction
	vector<BEDCOV> qualityHitsA1B1;
	vector<BEDCOV> qualityHitsA1B2;
	vector<BEDCOV> qualityHitsA2B1;
	vector<BEDCOV> qualityHitsA2B2;

	// count of hits on each end of BEDPE
	// that exceed the requested overlap fraction
	int numOverlapsA1B1 = 0;
	int numOverlapsA1B2 = 0;
	int numOverlapsA2B1 = 0;
	int numOverlapsA2B2 = 0;
	
	// add the appropriate slop to the starts and ends 
    CHRPOS start1 = a.start1;
    CHRPOS end1   = a.end1;
    CHRPOS start2 = a.start2;
    CHRPOS end2   = a.end2;
    
    if (_strandedSlop == true) {
        if (a.strand1 == "+") 
            end1   += _slop;
        else
            start1 -= _slop;
        if (a.strand2 == "+") 
            end2   += _slop;
        else
            start2 -= _slop;
    }
    else {
        start1 -= _slop;
        start2 -= _slop;
        end1   += _slop;
        end2   += _slop;        
    }

	// Find the _potential_ hits between each end of A and B
	_bedB->FindOverlapsPerBin(1, a.chrom1, start1, end1, a.strand1, hitsA1B1, !(_ignoreStrand));	// hits b/w A1 & B1
	_bedB->FindOverlapsPerBin(1, a.chrom2, start2, end2, a.strand2, hitsA2B1, !(_ignoreStrand));	// hits b/w A2 & B1
	_bedB->FindOverlapsPerBin(2, a.chrom1, start1, end1, a.strand1, hitsA1B2, !(_ignoreStrand));	// hits b/w A1 & B2
	_bedB->FindOverlapsPerBin(2, a.chrom2, start2, end2, a.strand2, hitsA2B2, !(_ignoreStrand));	// hits b/w A2 & B2	

	// Now, reduce to the set of hits on each end of A and B 
	// that meet the required overlap fraction and orientation.
    // FindQualityHitsBetweenEnds(start1, end1, start2, end2, hitsA1B1, qualityHitsA1B1, numOverlapsA1B1);     // quality hits b/w A1 & B1
    // FindQualityHitsBetweenEnds(start1, end1, start2, end2, hitsA1B2, qualityHitsA1B2, numOverlapsA1B2);     // quality hits b/w A1 & B2
    // FindQualityHitsBetweenEnds(start1, end1, start2, end2, hitsA2B1, qualityHitsA2B1, numOverlapsA2B1);     // quality hits b/w A2 & B1
    // FindQualityHitsBetweenEnds(start1, end1, start2, end2, hitsA2B2, qualityHitsA2B2, numOverlapsA2B2);     // quality hits b/w A2 & B2
	FindQualityHitsBetweenEnds(start1, end1, hitsA1B1, qualityHitsA1B1, numOverlapsA1B1);	   // quality hits b/w A1 & B1
	FindQualityHitsBetweenEnds(start1, end1, hitsA1B2, qualityHitsA1B2, numOverlapsA1B2);	   // quality hits b/w A1 & B2
	FindQualityHitsBetweenEnds(start2, end2, hitsA2B1, qualityHitsA2B1, numOverlapsA2B1);	   // quality hits b/w A2 & B1
	FindQualityHitsBetweenEnds(start2, end2, hitsA2B2, qualityHitsA2B2, numOverlapsA2B2);	   // quality hits b/w A2 & B2


	int matchCount1 = 0;	
	int matchCount2 = 0;
	if (_searchType == "neither" || _searchType == "both") {
    	if ((numOverlapsA1B1 > 0) || (numOverlapsA2B2 > 0))
    		FindHitsOnBothEnds(a, qualityHitsA1B1, qualityHitsA2B2, matchCount1);
    	if ((numOverlapsA1B2 > 0) || (numOverlapsA2B1 > 0)) 
    		FindHitsOnBothEnds(a, qualityHitsA2B1, qualityHitsA1B2, matchCount2);
        
        // report the fact that no hits were found iff _searchType is neither.
        if ((matchCount1 == 0) && (matchCount2 == 0) && (_searchType == "neither")) {
    		_bedA->reportBedPENewLine(a);		
    	}
	}
	else if (_searchType == "either") {
	    FindHitsOnEitherEnd(a, qualityHitsA1B1, qualityHitsA2B2, matchCount1);
	    FindHitsOnEitherEnd(a, qualityHitsA2B1, qualityHitsA1B2, matchCount2);
	}
}