Exemple #1
0
void BedMap::Map() {

    // create new BED file objects for A and B
    _bedA = new BedFile(_bedAFile);
    _bedB = new BedFile(_bedBFile);

    // use the chromsweep algorithm to detect overlaps on the fly.
    ChromSweep sweep = ChromSweep(_bedA, _bedB, 
                                  _sameStrand, _diffStrand, 
                                  _overlapFraction, _reciprocal,
                                  _printHeader);

    pair<BED, vector<BED> > hit_set;
    hit_set.second.reserve(10000);
    while (sweep.Next(hit_set)) {
        string result = MapHits(hit_set.first, hit_set.second);
        _bedA->reportBedTab(hit_set.first);
        printf("%s\n", result.c_str());
    }
}
Exemple #2
0
unsigned long Jaccard::GetIntersection() {
    
    _bedA = new BedFile(_bedAFile);
    _bedB = new BedFile(_bedBFile);
    
    unsigned long I = 0;

    ChromSweep sweep = ChromSweep(_bedA, _bedB, 
                                  false, false, 
                                  _overlapFraction, _reciprocal,
                                  true, false);


    pair<BED, vector<BED> > hit_set;
    hit_set.second.reserve(10000);
    while (sweep.Next(hit_set)) {
        I += GetTotalIntersection(hit_set.first, hit_set.second);
    }
    return I;
}
void BedIntersect::IntersectBed() {

    // create new BED file objects for A and B
    _bedA = new BedFile(_bedAFile);
    _bedB = new BedFile(_bedBFile);

    if (_sortedInput == false) {
        // load the "B" file into a map in order to
        // compare each entry in A to it in search of overlaps.
        _bedB->loadBedFileIntoMap();

        vector<BED> hits;
        hits.reserve(100);
        BED a;

        // open the "A" file, process each BED entry and searh for overlaps.
        _bedA->Open();
        // report A's header first if asked.
        if (_printHeader == true) {
            _bedA->PrintHeader();
        }
        while (_bedA->GetNextBed(a)) {
            if (_bedA->_status == BED_VALID) {
                // treat the BED as a single "block"
                if (_obeySplits == false)
                    FindOverlaps(a, hits);
                // split the BED12 into blocks and look for overlaps in each discrete block
                else {
                    // find the hits that overlap with the full span of the blocked BED
                    _bedB->allHits(a.chrom, a.start, a.end, a.strand,
                                   hits, _sameStrand, _diffStrand,
                                   _overlapFraction, _reciprocal);
                    // break a into discrete blocks, as we need to 
                    // measure overlap with the individual blocks, not the full span.
                    bedVector a_blocks; 
                    GetBedBlocks(a, a_blocks);
                    // find the overlaps between the block in A and B 
                    // last parm is false as a is not a BAM entry
                    FindBlockedOverlaps(a, a_blocks, hits, false);
                }
                hits.clear();
            }
        }
        _bedA->Close();
    }
    else {
        // use the chromsweep algorithm to detect overlaps on the fly.
        ChromSweep sweep = ChromSweep(_bedA, _bedB, 
                                      _sameStrand, _diffStrand, 
                                      _overlapFraction, _reciprocal,
                                      _printHeader);

        pair<BED, vector<BED> > hit_set;
        hit_set.second.reserve(10000);
        while (sweep.Next(hit_set)) {
            if (_obeySplits == false)
                processHits(hit_set.first, hit_set.second);
            else {
                bedVector a_blocks; 
                GetBedBlocks(hit_set.first, a_blocks);
                FindBlockedOverlaps(hit_set.first, a_blocks, hit_set.second, false);
            }
        }
    }
}