Beispiel #1
0
bool CloseSweep::chromChange(int dbIdx, RecordKeyVector &retList)
{
//	if (_currQueryRec->getChrName() == "chr1_gl000191_random" || (_currDbRecs[dbIdx] != NULL && _currDbRecs[dbIdx]->getChrName() == "chr1_gl000191_random")) {
//		printf("Break point here.\n");
//	}

    // the files are on the same chrom
	if (_currDbRecs[dbIdx] == NULL || _currQueryRec->sameChrom(_currDbRecs[dbIdx])) {

		//if this is the first time the query's chrom is ahead of the chrom that was in this cache,
		//then we have to clear the cache.
		if (!_caches[dbIdx].empty() && _currQueryRec->chromAfter(_caches[dbIdx].begin()->value())) {
			clearCache(dbIdx);
			_maxPrevLeftClosestEndPos[dbIdx] = 0;
		}
		return false;
	}
	if (_currDbRecs[dbIdx]->chromAfter(_currQueryRec) && (!_caches[dbIdx].empty() && (_caches[dbIdx].begin()->value()->sameChrom(_currQueryRec)))) {
		//the newest DB record's chrom is ahead of the query, but the cache still
		//has old records on that query's chrom
		scanCache(dbIdx, retList);
		finalizeSelections(dbIdx, retList);
		return true;
	}
	// the query is ahead of the database. fast-forward the database to catch-up.
	if (_currQueryRec->chromAfter(_currDbRecs[dbIdx])) {

		while (_currDbRecs[dbIdx] != NULL &&
				_currQueryRec->chromAfter(_currDbRecs[dbIdx])) {
			_dbFRMs[dbIdx]->deleteRecord(_currDbRecs[dbIdx]);
			nextRecord(false, dbIdx);
		}
		clearCache(dbIdx);
		_maxPrevLeftClosestEndPos[dbIdx] = 0;
        return false;
    }
    // the database is ahead of the query.
    else {
        // 1. scan the cache for remaining hits on the query's current chrom.
		scanCache(dbIdx, retList);

        return true;
    }

	//control can't reach here, but compiler still wants a return statement.
	return true;
}
Beispiel #2
0
void CloseSweep::masterScan(RecordKeyVector &retList) {
	//first clear out everything from the previous scan
	if (_context->reportDistance()) {
		_finalDistances.clear();
	}

	//initialize distances
	for (int i=0; i < _numDBs; i++) {
		_minUpstreamDist[i] = INT_MAX;
		_minDownstreamDist[i] = INT_MAX;
	}

	for (int i=0; i < _numDBs; i++) {

		_minUpstreamRecs[i]->clear();
		_minDownstreamRecs[i]->clear();
		_overlapRecs[i]->clear();

		if (dbFinished(i) || chromChange(i, retList)) {
			continue;
		} else {

			// scan the database cache for hits
			scanCache(i, retList);

			// skip if we hit the end of the DB
			// advance the db until we are ahead of the query. update hits and cache as necessary
			bool stopScanning = false;
			while (_currDbRecs[i] != NULL &&
					_currQueryRec->sameChrom(_currDbRecs[i]) &&
					!stopScanning) {
				if (considerRecord(_currDbRecs[i], i, stopScanning) == DELETE) {
					_dbFRMs[i]->deleteRecord(_currDbRecs[i]);
					_currDbRecs[i] = NULL;
				} else {
					_caches[i].push_back(_currDbRecs[i]);
					_currDbRecs[i] = NULL;
				}
				nextRecord(false, i);
			}
		}
		finalizeSelections(i, retList);
	}
	checkMultiDbs(retList);
}
Beispiel #3
0
bool CloseSweep::chromChange(int dbIdx, RecordKeyVector &retList, bool wantScan)
{
    Record *dbRec = _currDbRecs[dbIdx];

    bool haveQuery = _currQueryRec != NULL;
    bool haveDB = dbRec != NULL;

    if (haveQuery && _currQueryChromName != _prevQueryChromName) {
        _context->testNameConventions(_currQueryRec);
        testChromOrder(_currQueryRec);
    }

    if (haveDB) {
        _context->testNameConventions(dbRec);
        testChromOrder(dbRec);
    }

    // the files are on the same chrom
    if (haveQuery && (!haveDB || _currQueryRec->sameChrom(dbRec))) {

        //if this is the first time the query's chrom is ahead of the chrom that was in this cache,
        //then we have to clear the cache.
        if (!_caches[dbIdx].empty() && queryChromAfterDbRec(_caches[dbIdx].begin()->value())) {
            clearCache(dbIdx);
            clearClosestEndPos(dbIdx);
        }
        return false;
    }

    if (!haveQuery || !haveDB) return false;

    if (!_caches[dbIdx].empty() && (_caches[dbIdx].begin()->value()->sameChrom(_currQueryRec))) {
        //the newest DB record's chrom is ahead of the query, but the cache still
        //has old records on that query's chrom
        scanCache(dbIdx, retList);
        finalizeSelections(dbIdx, retList);
        return true;
    }


    // the query is ahead of the database. fast-forward the database to catch-up.
    if (queryChromAfterDbRec(dbRec)) {
        string oldDbChrom(dbRec->getChrName());

        while (dbRec != NULL &&
                queryChromAfterDbRec(dbRec)) {
            _dbFRMs[dbIdx]->deleteRecord(dbRec);
            if (!nextRecord(false, dbIdx)) break;
            dbRec =  _currDbRecs[dbIdx];
            const string &newDbChrom = dbRec->getChrName();
            if (newDbChrom != oldDbChrom) {
                testChromOrder(dbRec);
                oldDbChrom = newDbChrom;
            }
        }
        clearCache(dbIdx);
        clearClosestEndPos(dbIdx);
        return false;
    }
    // the database is ahead of the query.
    else {
        // 1. scan the cache for remaining hits on the query's current chrom.
        if (wantScan) scanCache(dbIdx, retList);

        return true;
    }

    //control can't reach here, but compiler still wants a return statement.
    return true;
}