Skip to content
Snippets Groups Projects
Commit 60223993 authored by nkindlon's avatar nkindlon
Browse files

handling for unmapped Bam records

parent 3690a614
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,8 @@ const string RegressTest::_randomCmd = "RANDOM"; ...@@ -16,7 +16,8 @@ const string RegressTest::_randomCmd = "RANDOM";
const string RegressTest::_space = " "; const string RegressTest::_space = " ";
const string RegressTest::_redirect = " > "; const string RegressTest::_redirect = " > ";
const string RegressTest::_devNull = " /dev/null "; const string RegressTest::_devNull = " /dev/null ";
const string RegressTest::_bedOpsCmd = "/home/nek3d/testWorkspace/bedops/bin/bedmap --echo --echo-map --bp-ovr 1 "; //const string RegressTest::_bedOpsCmd = "/home/nek3d/testWorkspace/bedops/bin/bedmap --echo --echo-map --bp-ovr 1 ";
const string RegressTest::_bedOpsCmd = "/home/nek3d/testWorkspace/bedops/bin/bedops --intersect ";
RegressTest::RegressTest() RegressTest::RegressTest()
......
...@@ -152,13 +152,25 @@ void FileRecordMgr::assignChromId(Record *record) { ...@@ -152,13 +152,25 @@ void FileRecordMgr::assignChromId(Record *record) {
void FileRecordMgr::testInputSortOrder(Record *record) void FileRecordMgr::testInputSortOrder(Record *record)
{ {
//user specified that file must be sorted. Check that it is so. // User specified that file must be sorted. Check that it is so.
// TBD: In future versions, we might not want/need all files to be sorted, // TBD: In future versions, we might not want/need all files to be sorted,
// even if the -sorted option is used, depending on number of input files // even if the -sorted option is used, depending on number of input files
// and program being run. Should that occur, this block will need adjusting. // and program being run. Should that occur, this block will need adjusting.
// NEK - 9/5/13 // NEK - 9/5/13
// Special: For BAM records that aren't mapped, we actually don't want
// to test the sort order. Another ugly hack sponsored by the letters B, A, and M.
if (record->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE && (static_cast<const BamRecord *>(record))->isUnmapped()) {
return;
}
const QuickString &currChrom = record->getChrName(); const QuickString &currChrom = record->getChrName();
int currStart = record->getStartPos();
if (record->isZeroLength()) {
currStart++;
}
if (currChrom != _prevChrom) { if (currChrom != _prevChrom) {
if ( _foundChroms.find(currChrom) != _foundChroms.end()) { if ( _foundChroms.find(currChrom) != _foundChroms.end()) {
//this is a different chrom than the last record had, but we've already seen this chrom. //this is a different chrom than the last record had, but we've already seen this chrom.
...@@ -179,10 +191,10 @@ void FileRecordMgr::testInputSortOrder(Record *record) ...@@ -179,10 +191,10 @@ void FileRecordMgr::testInputSortOrder(Record *record)
_prevStart = INT_MAX; _prevStart = INT_MAX;
record->setChromId(_prevChromId); record->setChromId(_prevChromId);
} }
} else if (record->getStartPos() < _prevStart) { //same chrom as last record, but with lower startPos, so still out of order. } else if (currStart < _prevStart) { //same chrom as last record, but with lower startPos, so still out of order.
sortError(record, false); sortError(record, false);
} }
_prevStart = record->getStartPos(); _prevStart = currStart;
} }
......
...@@ -43,6 +43,7 @@ bool BamRecord::initFromFile(BamFileReader *bamFileReader) ...@@ -43,6 +43,7 @@ bool BamRecord::initFromFile(BamFileReader *bamFileReader)
setStrand(strandChar); setStrand(strandChar);
_bamAlignment = bamFileReader->getAlignment(); _bamAlignment = bamFileReader->getAlignment();
_isUnmapped = !_bamAlignment.IsMapped();
return true; return true;
} }
......
...@@ -39,14 +39,13 @@ public: ...@@ -39,14 +39,13 @@ public:
int getBamChromId() const { return _bamChromId; } int getBamChromId() const { return _bamChromId; }
protected: protected:
virtual ~BamRecord();
void printRemainingBamFields();
BamTools::BamAlignment _bamAlignment; BamTools::BamAlignment _bamAlignment;
int _bamChromId; //different from chromId, because BAM file may be in different order int _bamChromId; //different from chromId, because BAM file may be in different order
//than the genomeFile. //than the genomeFile.
virtual ~BamRecord();
void printRemainingBamFields();
}; };
......
...@@ -7,7 +7,8 @@ Record::Record() ...@@ -7,7 +7,8 @@ Record::Record()
_startPos(-1), _startPos(-1),
_endPos(-1), _endPos(-1),
_strand(UNKNOWN), _strand(UNKNOWN),
_zeroLength(false) _zeroLength(false),
_isUnmapped(false)
{ {
} }
...@@ -35,6 +36,9 @@ void Record::clear() { ...@@ -35,6 +36,9 @@ void Record::clear() {
_strand = UNKNOWN; _strand = UNKNOWN;
_startPosStr.clear(); _startPosStr.clear();
_endPosStr.clear(); _endPosStr.clear();
_zeroLength = false;
_isUnmapped = false;
} }
void Record::setStrand(char val) void Record::setStrand(char val)
...@@ -130,6 +134,10 @@ bool Record::intersects(const Record *record, ...@@ -130,6 +134,10 @@ bool Record::intersects(const Record *record,
bool Record::sameChromIntersects(const Record *record, bool Record::sameChromIntersects(const Record *record,
bool wantSameStrand, bool wantDiffStrand, float overlapFraction, bool reciprocal) const bool wantSameStrand, bool wantDiffStrand, float overlapFraction, bool reciprocal) const
{ {
// Special: For BAM records that are unmapped, intersect should automatically return false
if (_isUnmapped || record->_isUnmapped) {
return false;
}
//If user requested hits only on same strand, or only on different strands, //If user requested hits only on same strand, or only on different strands,
//rule out different strandedness first. //rule out different strandedness first.
......
...@@ -87,6 +87,11 @@ public: ...@@ -87,6 +87,11 @@ public:
virtual void undoZeroLength(); //change it back just before output; virtual void undoZeroLength(); //change it back just before output;
virtual bool isZeroLength() const { return _zeroLength; } virtual bool isZeroLength() const { return _zeroLength; }
// "Unmapped" only applies to BamRecord, but for design reasons, it has to be here,
// because we want to short circuit the intersects method if either record is an unmapped
// Bam record.
bool isUnmapped() const { return _isUnmapped; }
virtual bool operator < (const Record &other) const; virtual bool operator < (const Record &other) const;
virtual bool operator > (const Record &other) const; virtual bool operator > (const Record &other) const;
...@@ -126,6 +131,7 @@ protected: ...@@ -126,6 +131,7 @@ protected:
QuickString _score; QuickString _score;
strandType _strand; strandType _strand;
bool _zeroLength; bool _zeroLength;
bool _isUnmapped;
}; };
......
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