Skip to content
Snippets Groups Projects
Commit dc51d7db authored by Aaron Quinlan's avatar Aaron Quinlan
Browse files

Merge pull request #47 from nkindlon/master

Fixed slop bug when slop factor exceeds MAX signed int.
parents a3fefa28 80820201
No related branches found
No related tags found
No related merge requests found
...@@ -50,12 +50,12 @@ void BedSlop::SlopBed() { ...@@ -50,12 +50,12 @@ void BedSlop::SlopBed() {
while (_bed->GetNextBed(bedEntry)) { while (_bed->GetNextBed(bedEntry)) {
if (_bed->_status == BED_VALID) { if (_bed->_status == BED_VALID) {
if (_fractional == false) { if (_fractional == false) {
AddSlop(bedEntry, (int) _leftSlop, (int) _rightSlop); AddSlop(bedEntry);
} }
else { else {
int leftSlop = (int) (_leftSlop * bedEntry.size()); _leftSlop = _leftSlop * (float)bedEntry.size();
int rightSlop = (int) (_rightSlop * bedEntry.size()); _rightSlop = _rightSlop * (float)bedEntry.size();
AddSlop(bedEntry, leftSlop, rightSlop); AddSlop(bedEntry);
} }
_bed->reportBedNewLine(bedEntry); _bed->reportBedNewLine(bedEntry);
} }
...@@ -64,29 +64,29 @@ void BedSlop::SlopBed() { ...@@ -64,29 +64,29 @@ void BedSlop::SlopBed() {
} }
void BedSlop::AddSlop(BED &bed, int leftSlop, int rightSlop) { void BedSlop::AddSlop(BED &bed) {
// special handling if the BED entry is on the negative // special handling if the BED entry is on the negative
// strand and the user cares about strandedness. // strand and the user cares about strandedness.
CHRPOS chromSize = _genome->getChromSize(bed.chrom); float chromSize = (float)_genome->getChromSize(bed.chrom);
if ( (_forceStrand) && (bed.strand == "-") ) { if ( (_forceStrand) && (bed.strand == "-") ) {
// inspect the start // inspect the start
if ( (static_cast<int>(bed.start) - rightSlop) > 0 ) bed.start -= rightSlop; float newStart = (float)bed.start - _rightSlop;
else bed.start = 0; bed.start = (newStart > 0 ) ? (CHRPOS)newStart : 0;
// inspect the start // inspect the end
if ( (static_cast<int>(bed.end) + leftSlop) <= static_cast<int>(chromSize)) bed.end += leftSlop; float newEnd = (float)bed.end + _leftSlop;
else bed.end = chromSize; bed.end = (newEnd < chromSize ) ? (CHRPOS)newEnd : (CHRPOS)chromSize;
} }
else { else {
// inspect the start // inspect the start
if ( (static_cast<int>(bed.start) - leftSlop) > 0) bed.start -= leftSlop; float newStart = (float)bed.start - _leftSlop;
else bed.start = 0; bed.start = (newStart > 0 ) ? (CHRPOS)newStart : 0;
// inspect the end // inspect the end
if ( (static_cast<int>(bed.end) + rightSlop) <= static_cast<int>(chromSize)) bed.end += rightSlop; float newEnd = (float)bed.end + _rightSlop;
else bed.end = chromSize; bed.end = (newEnd < chromSize ) ? (CHRPOS)newEnd : (CHRPOS)chromSize;
} }
} }
......
...@@ -57,5 +57,5 @@ private: ...@@ -57,5 +57,5 @@ private:
void SlopBed(); void SlopBed();
// method to add requested "slop" to a single BED entry // method to add requested "slop" to a single BED entry
void AddSlop(BED &bed, int leftSlop, int rightSlop); void AddSlop(BED &bed);
}; };
...@@ -134,4 +134,16 @@ echo \ ...@@ -134,4 +134,16 @@ echo \
chr1 0 1000 a2 2 -" > exp chr1 0 1000 a2 2 -" > exp
$BT slop -i a.bed -b 2000 -s -g tiny.genome > obs $BT slop -i a.bed -b 2000 -s -g tiny.genome > obs
check obs exp check obs exp
rm obs exp rm obs exp
\ No newline at end of file
###########################################################
# test slop factor being larger than a signed int
###########################################################
echo " slop.t12...\c"
echo \
"chr1 0 1000 a1 1 +
chr1 0 1000 a2 2 -" > exp
$BT slop -i a.bed -b 3000000000 -s -g tiny.genome > 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