Skip to content
Snippets Groups Projects
Commit 8a2e3695 authored by Neil Kindlon's avatar Neil Kindlon
Browse files

Bug fixes and more unit tests for closest

parent 897d1a85
No related branches found
No related tags found
No related merge requests found
......@@ -121,6 +121,19 @@ CloseSweep::rateOvlpType CloseSweep::considerRecord(const Record *cacheRec, int
return IGNORE;
}
// If strand is specified, and either record has an unknown strand, ignore
if ((_context->getSameStrand() || _context->getDiffStrand()) && ((_currQueryRec->getStrandVal() == Record::UNKNOWN) || cacheRec->getStrandVal() == Record::UNKNOWN)) {
return IGNORE;
}
// If want same strand, and aren't sure they're the same, ignore
if (_context->getSameStrand() && (_currQueryRec->getStrandVal() != cacheRec->getStrandVal())) {
return IGNORE;
}
// If we want diff strand, and aren't sure they're different, ignore.
if (_context->getDiffStrand() && (_currQueryRec->getStrandVal() == cacheRec->getStrandVal())) {
return IGNORE;
}
// Now determine whether the hit and query intersect, and if so, what to do about it.
int currDist = 0;
......
......@@ -137,6 +137,7 @@ void RecordOutputMgr::printRecord(const Record *record, const QuickString & valu
}
void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *dists) {
const ContextClosest *context = static_cast<const ContextClosest *>(_context);
bool deleteBlocks = false;
RecordKeyVector blockList(keyList.getKey());
if (keyList.getKey()->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE) {
......@@ -148,6 +149,7 @@ void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *
for (RecordKeyVector::const_iterator_type iter = keyList.begin(); iter != keyList.end(); iter = keyList.next()) {
printKey(keyList.getKey());
tab();
addDbFileId((*iter)->getFileIdx());
(*iter)->print(_outBuf);
if (dists != NULL) {
tab();
......@@ -161,7 +163,7 @@ void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *
printKey(keyList.getKey());
tab();
null(true, false);
if ((static_cast<ContextClosest *>(_context))->reportDistance()) {
if (context->reportDistance()) {
tab();
_outBuf.append(-1);
}
......@@ -172,7 +174,6 @@ void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *
_currBamBlockList = NULL;
}
return;
}
......
chr1 5 15
chr1 20 60
chr1 200 220
chr1 5 15 d1.1 1 +
chr1 20 60 d1.2 2 -
chr1 200 220 d1.3 3 -
chr1 15 35
chr1 120 170
chr1 210 230
chr1 15 35 db2.1 1 -
chr1 120 170 db2.2 2 -
chr1 210 230 db3 3 +
chr1 70 90
chr1 70 90 d3.1 3 -
chr1 80 100
chr1 80 100 q1 1 +
......@@ -166,19 +166,45 @@ rm obs exp
###########################################################
echo " closest.t13...\c"
echo \
"chr1 80 100 chr1 20 60
chr1 80 100 chr1 120 170
chr1 80 100 chr1 70 90" > exp
"chr1 80 100 q1 1 + 1 chr1 20 60 d1.2 2 -
chr1 80 100 q1 1 + 2 chr1 120 170 db2.2 2 -
chr1 80 100 q1 1 + 3 chr1 70 90 d3.1 3 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed mdb3.bed > obs
check obs exp
rm obs exp
###########################################################
# test 3 dbs with -names option
###########################################################
echo " closest.t14...\c"
echo \
"chr1 80 100 q1 1 + a chr1 20 60 d1.2 2 -
chr1 80 100 q1 1 + b chr1 120 170 db2.2 2 -
chr1 80 100 q1 1 + c chr1 70 90 d3.1 3 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed mdb3.bed -names a b c > obs
check obs exp
rm obs exp
###########################################################
# test 3 dbs with -filenames option
###########################################################
echo " closest.t15...\c"
echo \
"chr1 80 100 q1 1 + mdb1.bed chr1 20 60 d1.2 2 -
chr1 80 100 q1 1 + mdb2.bed chr1 120 170 db2.2 2 -
chr1 80 100 q1 1 + mdb3.bed chr1 70 90 d3.1 3 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed mdb3.bed -filenames > obs
check obs exp
rm obs exp
###########################################################
# test 3 dbs, -all mode
###########################################################
echo " closest.t13...\c"
echo " closest.t16...\c"
echo \
"chr1 80 100 chr1 70 90" > exp
"chr1 80 100 q1 1 + 3 chr1 70 90 d3.1 3 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed mdb3.bed -mdb all > obs
check obs exp
rm obs exp
......@@ -187,10 +213,10 @@ rm obs exp
###########################################################
# test 2 dbs, tie mode = all
###########################################################
echo " closest.t14...\c"
echo " closest.t17...\c"
echo \
"chr1 80 100 chr1 20 60
chr1 80 100 chr1 120 170" > exp
"chr1 80 100 q1 1 + 1 chr1 20 60 d1.2 2 -
chr1 80 100 q1 1 + 2 chr1 120 170 db2.2 2 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed -t all > obs
check obs exp
rm obs exp
......@@ -198,9 +224,9 @@ rm obs exp
###########################################################
# test 2 dbs, tie mode = first
###########################################################
echo " closest.t15...\c"
echo " closest.t18...\c"
echo \
"chr1 80 100 chr1 20 60" > exp
"chr1 80 100 q1 1 + 1 chr1 20 60 d1.2 2 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed -mdb all -t first > obs
check obs exp
rm obs exp
......@@ -208,10 +234,53 @@ rm obs exp
###########################################################
# test 2 dbs, tie mode = last
###########################################################
echo " closest.t16...\c"
echo " closest.t19...\c"
echo \
"chr1 80 100 chr1 120 170" > exp
"chr1 80 100 q1 1 + 2 chr1 120 170 db2.2 2 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed -mdb all -t last > obs
check obs exp
rm obs exp
###########################################################
# test same strand
###########################################################
echo " closest.t20...\c"
echo \
"chr1 80 100 q1 1 + chr1 5 15 d1.1 1 +" > exp
$BT closest -a mq1.bed -b mdb1.bed -s> obs
check obs exp
rm obs exp
###########################################################
# test diff strand
###########################################################
echo " closest.t21...\c"
echo \
"chr1 80 100 q1 1 + chr1 20 60 d1.2 2 -" > exp
$BT closest -a mq1.bed -b mdb1.bed -S> obs
check obs exp
rm obs exp
###########################################################
# test 2 dbs, tie mode = all, same strand
###########################################################
echo " closest.t22...\c"
echo \
"chr1 80 100 q1 1 + 1 chr1 5 15 d1.1 1 +" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed -t all -mdb all -s > obs
check obs exp
rm obs exp
###########################################################
# test 2 dbs, tie mode = all, diff strand
###########################################################
echo " closest.t23...\c"
echo \
"chr1 80 100 q1 1 + 1 chr1 20 60 d1.2 2 -
chr1 80 100 q1 1 + 2 chr1 120 170 db2.2 2 -" > exp
$BT closest -a mq1.bed -b mdb1.bed mdb2.bed -t all -mdb all -S > obs
check obs exp
rm obs exp
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