[med-svn] [bedtools] 04/13: Fixed slop bug when slop factor exceeds MAX signed int.

Charles Plessy plessy at moszumanska.debian.org
Fri Mar 21 07:23:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

plessy pushed a commit to branch debian/unstable
in repository bedtools.

commit 80820201274c45047c2d7d9863ea803fc5fddb24
Author: nkindlon <nek3d at virginia.edu>
Date:   Tue Mar 18 18:16:57 2014 -0400

    Fixed slop bug when slop factor exceeds MAX signed int.
---
 src/slopBed/slopBed.cpp | 30 +++++++++++++++---------------
 src/slopBed/slopBed.h   |  2 +-
 test/slop/test-slop.sh  | 14 +++++++++++++-
 3 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/src/slopBed/slopBed.cpp b/src/slopBed/slopBed.cpp
index bce7797..8657402 100644
--- a/src/slopBed/slopBed.cpp
+++ b/src/slopBed/slopBed.cpp
@@ -50,12 +50,12 @@ void BedSlop::SlopBed() {
     while (_bed->GetNextBed(bedEntry)) {    
         if (_bed->_status == BED_VALID) {
             if (_fractional == false) {
-                AddSlop(bedEntry, (int) _leftSlop, (int) _rightSlop);
+                AddSlop(bedEntry);
             }
             else {
-                int leftSlop  = (int) (_leftSlop  * bedEntry.size());
-                int rightSlop = (int) (_rightSlop * bedEntry.size());
-                AddSlop(bedEntry, leftSlop, rightSlop);
+                _leftSlop  = _leftSlop  * (float)bedEntry.size();
+                _rightSlop = _rightSlop * (float)bedEntry.size();
+                AddSlop(bedEntry);
             }
             _bed->reportBedNewLine(bedEntry);
         }
@@ -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
     // strand and the user cares about strandedness.
-    CHRPOS chromSize = _genome->getChromSize(bed.chrom);
+    float chromSize = (float)_genome->getChromSize(bed.chrom);
 
     if ( (_forceStrand) && (bed.strand == "-") ) {
         // inspect the start
-        if ( (static_cast<int>(bed.start) - rightSlop) > 0 ) bed.start -= rightSlop;
-        else bed.start = 0;
+    	float newStart = (float)bed.start - _rightSlop;
+    	bed.start = (newStart > 0 ) ? (CHRPOS)newStart : 0;
 
-        // inspect the start
-        if ( (static_cast<int>(bed.end) + leftSlop) <= static_cast<int>(chromSize)) bed.end += leftSlop;
-        else bed.end = chromSize;
+        // inspect the end
+    	float newEnd = (float)bed.end + _leftSlop;
+    	bed.end = (newEnd < chromSize ) ? (CHRPOS)newEnd : (CHRPOS)chromSize;
     }
     else {
         // inspect the start
-        if ( (static_cast<int>(bed.start) - leftSlop) > 0) bed.start -= leftSlop;
-        else bed.start = 0;
+    	float newStart = (float)bed.start - _leftSlop;
+    	bed.start = (newStart > 0 ) ? (CHRPOS)newStart : 0;
 
         // inspect the end
-        if ( (static_cast<int>(bed.end) + rightSlop) <= static_cast<int>(chromSize)) bed.end += rightSlop;
-        else bed.end = chromSize;
+    	float newEnd = (float)bed.end + _rightSlop;
+    	bed.end = (newEnd < chromSize ) ? (CHRPOS)newEnd : (CHRPOS)chromSize;
     }
 }
 
diff --git a/src/slopBed/slopBed.h b/src/slopBed/slopBed.h
index 1fd1aba..119c3d8 100644
--- a/src/slopBed/slopBed.h
+++ b/src/slopBed/slopBed.h
@@ -57,5 +57,5 @@ private:
     void SlopBed();
 
     // method to add requested "slop" to a single BED entry
-    void AddSlop(BED &bed, int leftSlop, int rightSlop);
+    void AddSlop(BED &bed);
 };
diff --git a/test/slop/test-slop.sh b/test/slop/test-slop.sh
index d11ce3a..33a8983 100644
--- a/test/slop/test-slop.sh
+++ b/test/slop/test-slop.sh
@@ -134,4 +134,16 @@ echo \
 chr1	0	1000	a2	2	-" > exp
 $BT slop -i a.bed -b 2000 -s -g tiny.genome > obs
 check obs exp
-rm obs exp
\ No newline at end of file
+rm obs exp
+
+###########################################################
+# 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
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/bedtools.git



More information about the debian-med-commit mailing list