Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 bedtools (2.19.1-2) unstable; urgency=medium
 .
   * debian/tests/control: Add "Depends: @, samtools" as advised in
     #747337
   * debian/tests/upstream: Use content from bedtools-test package to
     actually run the test suite
     Closes: #747337
   * debian/rules: Use dh to easily enable unit tests at package build
     time
   * Build-Depends: samtools to run the full test suite
Author: Andreas Tille <tille@debian.org>
Bug-Debian: http://bugs.debian.org/747337

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- bedtools-2.19.1.orig/docs/index.rst
+++ bedtools-2.19.1/docs/index.rst
@@ -7,12 +7,25 @@ for a wide-range of genomics analysis ta
 tools enable *genome arithmetic*: that is, set theory on the genome.  For 
 example, **bedtools** allows one to *intersect*, *merge*, *count*, *complement*,
 and *shuffle* genomic intervals from multiple files in widely-used 
-genomic file formats such as BAM, BED, GFF/GTF, VCF. 
-
-While each individual tool is designed to do a relatively simple task (e.g., 
+genomic file formats such as BAM, BED, GFF/GTF, VCF. While each individual tool is designed to do a relatively simple task (e.g., 
 *intersect* two interval files), quite sophisticated analyses can be conducted
 by combining multiple bedtools operations on the UNIX command line.
 
+==========================
+Interesting usage examples
+==========================
+To whet your appetite, here are a few examples of ways in which bedtools has been used for genome research. If you have interesteding examples, please send them our way and we will add them to the list.
+
+
+- `Coverage analysis for targeted DNA capture <http://gettinggeneticsdone.blogspot.com/2014/03/visualize-coverage-exome-targeted-ngs-bedtools.html>`_. Thanks to `Stephen Turner <https://twitter.com/genetics_blog>`_.
+- `Measuring similarity of DNase hypersensitivity among many cell types <https://github.com/arq5x/bedtools-protocols/blob/master/bedtools.md#bp6--measuring-dataset-similarity>`_
+- `Extracting promoter sequences from a genome <http://www.biostars.org/p/17162/>`_
+- `Comparing intersections among many genome interval files <http://www.biostars.org/p/13516/>`_
+- `RNA-seq coverage analysis <http://www.cureffi.org/2013/11/18/an-mrna-seq-pipeline-using-gsnap-samtools-cufflinks-and-bedtools/>`_. Thanks to `Erik Minikel <https://twitter.com/cureffi>`_.
+- `Identifying targeted regions that lack coverage <https://twitter.com/aaronquinlan/status/421786507511205888>`_. Thanks to `Brent Pedersen <https://twitter.com/brent_p>`_.
+- `Calculating GC content for CCDS exons <http://www.biostars.org/p/47047/>`_.
+
+
 =================
 Table of contents
 =================
--- bedtools-2.19.1.orig/src/slopBed/slopBed.cpp
+++ bedtools-2.19.1/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;
     }
 }
 
--- bedtools-2.19.1.orig/src/slopBed/slopBed.h
+++ bedtools-2.19.1/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);
 };
--- bedtools-2.19.1.orig/src/utils/fileType/fileType.cpp
+++ bedtools-2.19.1/src/utils/fileType/fileType.cpp
@@ -48,24 +48,31 @@ bool isGzipFile(istream *file) {
        without triggering the "fail" bit.  This was necessary to support
        FIFOs, per version 2.13.0
     */
-    struct  {
-        unsigned char id1;
+//    struct  {
+//        unsigned char id1;
 //      unsigned char id2;
 //      unsigned char cm;
-    } gzip_header;
+//    } gzip_header;
 
-    if (!file->read((char*)&gzip_header, sizeof(gzip_header))) {
-        return false;
-    }
-
-    if ( gzip_header.id1 == 0x1f )
+//   if (!file->read((char*)&gzip_header, sizeof(gzip_header))) {
+//       return false;
+//   }
+//  if ( gzip_header.id1 == 0x1f )
 //       &&
 //       gzip_header.id2 == 0x8b
 //       &&
 //       gzip_header.cm == 8 )
+
+/*
+        26-Dec-2012 and again 20-Mar-2014:
+        Just peek at the first byte instead of reading it so that we don't
+        affect the istream's failbit.  This modification was wisely proposed
+        by John Marshall in response to Issue 30:
+        https://github.com/arq5x/bedtools/issues/30
+ */
+    if (file->peek() != 0x1f)
     {
         return true;
     }
-    file->putback(gzip_header.id1);
     return false;
 }
--- bedtools-2.19.1.orig/test/map/test-map.sh
+++ bedtools-2.19.1/test/map/test-map.sh
@@ -694,7 +694,7 @@ echo \
 "
 *****
 ***** ERROR: There are 1 columns given, but there are 2 operations."  > exp
-../../bin/bedtools map -a ivls.bed -b values.bed -o count,sum 2>&1 > /dev/null | head -3 > obs
+$BT map -a ivls.bed -b values.bed -o count,sum 2>&1 > /dev/null | head -3 > obs
 check obs exp
 rm obs exp
 
@@ -708,7 +708,7 @@ echo \
 "
 *****
 ***** ERROR: There are 3 columns given, but there are 2 operations."  > exp
-../../bin/bedtools map -a ivls.bed -b values.bed -c 5,1,2 -o count,sum 2>&1 > /dev/null | head -3 > obs
+$BT map -a ivls.bed -b values.bed -c 5,1,2 -o count,sum 2>&1 > /dev/null | head -3 > obs
 check obs exp
 rm obs exp
 
@@ -721,7 +721,7 @@ echo \
 "
 *****
 ***** ERROR: Column 1 is not a numeric field for database file values.bed."  > exp
-../../bin/bedtools map -a ivls.bed -b values.bed -c 1 -o sum 2>&1 > /dev/null | head -3 > obs
+$BT map -a ivls.bed -b values.bed -c 1 -o sum 2>&1 > /dev/null | head -3 > obs
 check obs exp
 rm obs exp
 
@@ -738,7 +738,7 @@ chr2	0	100	.	.
 chr2	100	200	.	.
 chr3	0	100	6	7
 chr3	100	200	8	23" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 5,7 -o sum > obs
+$BT map -a ivls.bed -b values4.bed -c 5,7 -o sum > obs
 check obs exp
 rm obs exp
 
@@ -755,7 +755,7 @@ chr2	0	100	.	.	.
 chr2	100	200	.	.	.
 chr3	0	100	10	6	7
 chr3	100	200	120	8	23" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 2,5,7 -o mean,sum,sum > obs
+$BT map -a ivls.bed -b values4.bed -c 2,5,7 -o mean,sum,sum > obs
 check obs exp
 rm obs exp
 
@@ -771,7 +771,7 @@ chr2	0	100	.
 chr2	100	200	.
 chr3	0	100	76.2222
 chr3	100	200	0.25" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 7 -o stddev > obs
+$BT map -a ivls.bed -b values4.bed -c 7 -o stddev > obs
 check obs exp
 rm obs exp
 
@@ -786,7 +786,7 @@ chr2	0	100	.
 chr2	100	200	.
 chr3	0	100	114.333
 chr3	100	200	0.5" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 7 -o sample_stddev > obs
+$BT map -a ivls.bed -b values4.bed -c 7 -o sample_stddev > obs
 check obs exp
 rm obs exp
 
--- bedtools-2.19.1.orig/test/reldist/test-reldist.sh
+++ bedtools-2.19.1/test/reldist/test-reldist.sh
@@ -1,4 +1,5 @@
 BT=${BT-../../bin/bedtools}
+DATA=${DATA-../../data}
 
 check()
 {
@@ -17,8 +18,8 @@ echo "    reldist.t01...\c"
 echo \
 "reldist	count	total	fraction
 0.00	43424	43424	1.000" > exp
-$BT reldist -a ../../data/refseq.chr1.exons.bed.gz \
-            -b ../../data/refseq.chr1.exons.bed.gz > obs
+$BT reldist -a $DATA/refseq.chr1.exons.bed.gz \
+            -b $DATA/refseq.chr1.exons.bed.gz > obs
 check obs exp
 rm obs exp
 
@@ -79,8 +80,8 @@ echo \
 0.47	850	43408	0.020
 0.48	1006	43408	0.023
 0.49	937	43408	0.022" > exp
-$BT reldist -a ../../data/refseq.chr1.exons.bed.gz \
-            -b ../../data/aluY.chr1.bed.gz > obs
+$BT reldist -a $DATA/refseq.chr1.exons.bed.gz \
+            -b $DATA/aluY.chr1.bed.gz > obs
 check obs exp
 rm obs exp
 
@@ -143,7 +144,7 @@ echo \
 0.48	365	43422	0.008
 0.49	336	43422	0.008
 0.50	38	43422	0.001" > exp
-$BT reldist -a ../../data/refseq.chr1.exons.bed.gz \
-            -b ../../data/gerp.chr1.bed.gz > obs
+$BT reldist -a $DATA/refseq.chr1.exons.bed.gz \
+            -b $DATA/gerp.chr1.bed.gz > obs
 check obs exp
-rm obs exp
\ No newline at end of file
+rm obs exp
--- bedtools-2.19.1.orig/test/slop/test-slop.sh
+++ bedtools-2.19.1/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
+
