Skip to content
Snippets Groups Projects
Commit 5f8020b4 authored by Aaron's avatar Aaron
Browse files

chromsweep no longer overloads results p_q on chrom change.

parent d2fdf4e7
No related branches found
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ ChromSweep::~ChromSweep(void) {
void ChromSweep::ScanCache() {
if (_qy_status != BED_INVALID) {
vector<BED>::iterator c = _cache.begin();
vector<BED>::iterator c = _cache.begin();
while (c != _cache.end())
{
if ((_curr_qy.chrom == c->chrom) && !(after(_curr_qy, *c))) {
......@@ -87,43 +87,40 @@ void ChromSweep::ScanCache() {
}
void ChromSweep::ChromCheck()
bool ChromSweep::ChromChange()
{
// the files are on the chrom
// the files are on the same chrom
if ((_curr_qy.chrom == _curr_db.chrom) || (_db_status == BED_INVALID) || (_qy_status == BED_INVALID)) {
return;
return false;
}
// the query is ahead of the database.
// fast-forward the database to catch-up.
if (_curr_qy.chrom > _curr_db.chrom) {
// the query is ahead of the database. fast-forward the database to catch-up.
else if (_curr_qy.chrom > _curr_db.chrom) {
while (!_bedB->Empty() && _curr_db.chrom < _curr_qy.chrom)
{
_db_status = _bedB->GetNextBed(_curr_db, _db_lineNum);
}
_cache.clear();
return false;
}
// the database is ahead of the query.
// 1. scan the cache for remaining hits on the query's current chrom.
// 2. fast-forward until we catch up and report 0 hits until we do.
else if (_curr_qy.chrom < _curr_db.chrom) {
// report hits for the remaining queries on this chrom
string curr_chrom = _curr_qy.chrom;
while (!_bedA->Empty() && _curr_qy.chrom == curr_chrom)
else {
// 1. scan the cache for remaining hits on the query's current chrom.
if (_curr_qy.chrom == _curr_chrom)
{
ScanCache();
_results.push(make_pair(_curr_qy, _hits));
_qy_status = _bedA->GetNextBed(_curr_qy, _qy_lineNum);
_hits.clear();
}
// now fast forward query to catch up to database
while (!_bedA->Empty() && _curr_qy.chrom < _curr_db.chrom)
// 2. fast-forward until we catch up and report 0 hits until we do.
else if (_curr_qy.chrom < _curr_db.chrom)
{
// hits is empty to reflect the fact that no hits are found in catch-up mode
_hits.clear();
_results.push(make_pair(_curr_qy, _hits));
_qy_status = _bedA->GetNextBed(_curr_qy, _qy_lineNum);
_cache.clear();
}
_cache.clear();
_qy_status = _bedA->GetNextBed(_curr_qy, _qy_lineNum);
_curr_chrom = _curr_qy.chrom;
return true;
}
}
......@@ -131,24 +128,26 @@ void ChromSweep::ChromCheck()
bool ChromSweep::Next(pair<BED, vector<BED> > &next) {
if (!_bedA->Empty()) {
// have we changed chromosomes?
ChromCheck();
// scan the database cache for hits
ScanCache();
// advance the db until we are ahead of the query. update hits and cache as necessary
while (!_bedB->Empty() && _curr_qy.chrom == _curr_db.chrom && !(after(_curr_db, _curr_qy)))
{
if (overlaps(_curr_qy.start, _curr_qy.end, _curr_db.start, _curr_db.end) > 0) {
_hits.push_back(_curr_db);
if (ChromChange() == false) {
// scan the database cache for hits
ScanCache();
// advance the db until we are ahead of the query. update hits and cache as necessary
while (!_bedB->Empty() && _curr_qy.chrom == _curr_db.chrom && !(after(_curr_db, _curr_qy)))
{
if (overlaps(_curr_qy.start, _curr_qy.end, _curr_db.start, _curr_db.end) > 0) {
_hits.push_back(_curr_db);
}
_cache.push_back(_curr_db);
_db_status = _bedB->GetNextBed(_curr_db, _db_lineNum);
}
_cache.push_back(_curr_db);
_db_status = _bedB->GetNextBed(_curr_db, _db_lineNum);
// add the hits for this query to the pump
_results.push(make_pair(_curr_qy, _hits));
// reset for the next query
_hits.clear();
_curr_qy = _nullBed;
_qy_status = _bedA->GetNextBed(_curr_qy, _qy_lineNum);
_curr_chrom = _curr_qy.chrom;
}
// add the hits for this query to the pump
_results.push(make_pair(_curr_qy, _hits));
// reset for the next query
_hits.clear();
_curr_qy = _nullBed;
_qy_status = _bedA->GetNextBed(_curr_qy, _qy_lineNum);
}
// report the next set if hits if there are still overlaps in the pump
if (!_results.empty()) {
......
......@@ -67,6 +67,7 @@ private:
// variables for the current query and db entries.
BED _curr_qy, _curr_db;
string _curr_chrom;
BedLineStatus _qy_status, _db_status;
int _qy_lineNum, _db_lineNum;
......@@ -74,7 +75,7 @@ private:
private:
void ScanCache();
void ChromCheck();
bool ChromChange();
};
#endif /* CHROMSWEEP_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment