From f409a5339fe96e0e47d1de88dd7ecbd94e2a3324 Mon Sep 17 00:00:00 2001 From: Devon Ryan Date: Sun, 31 Mar 2019 12:33:53 +0200 Subject: [PATCH 1/7] Implement #816 --- deeptools/bigwigCompare.py | 7 +++++++ deeptools/writeBedGraph_bam_and_bw.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/deeptools/bigwigCompare.py b/deeptools/bigwigCompare.py index bfce8a80c..80738840c 100644 --- a/deeptools/bigwigCompare.py +++ b/deeptools/bigwigCompare.py @@ -61,6 +61,12 @@ def parse_arguments(args=None): type=float, required=False) + parser.add_argument('--skipZeroOverZero', + help='Skip bins where BOTH BAM files lack coverage. ' + 'This is determined BEFORE any applicable pseudocount ' + 'is added.', + action='store_true') + parser.add_argument('--operation', help='The default is to output the log2ratio of the ' 'two samples. The reciprocal ratio returns the ' @@ -159,6 +165,7 @@ def main(args=None): blackListFileName=args.blackListFileName, verbose=args.verbose, numberOfProcessors=args.numberOfProcessors, + skipZeroOverZero=args.skipZeroOverZero, format=args.outFileFormat, smoothLength=False, missingDataAsZero=not args.skipNonCoveredRegions, diff --git a/deeptools/writeBedGraph_bam_and_bw.py b/deeptools/writeBedGraph_bam_and_bw.py index 67cfa9b43..c7abf1535 100644 --- a/deeptools/writeBedGraph_bam_and_bw.py +++ b/deeptools/writeBedGraph_bam_and_bw.py @@ -45,7 +45,7 @@ def writeBedGraph_wrapper(args): def writeBedGraph_worker( chrom, start, end, tileSize, defaultFragmentLength, bamOrBwFileList, func, funcArgs, extendPairedEnds=True, smoothLength=0, - missingDataAsZero=False, fixed_step=False): + skipZeroOverZero=False, missingDataAsZero=False, fixed_step=False): r""" Writes a bedgraph having as base a number of bam files. @@ -102,6 +102,10 @@ def writeBedGraph_worker( "files. Remove this chromosome from the bigwig file " "to continue".format(chrom)) + if skipZeroOverZero and np.sum(tileCoverage) == 0: + previousValue = None + continue + value = func(tileCoverage, funcArgs) if fixed_step: From 18af2b6d02dd592491d76cc330915529874ba1d9 Mon Sep 17 00:00:00 2001 From: Devon Ryan Date: Sun, 31 Mar 2019 13:28:32 +0200 Subject: [PATCH 2/7] expose option --- deeptools/writeBedGraph_bam_and_bw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeptools/writeBedGraph_bam_and_bw.py b/deeptools/writeBedGraph_bam_and_bw.py index c7abf1535..000b6b288 100644 --- a/deeptools/writeBedGraph_bam_and_bw.py +++ b/deeptools/writeBedGraph_bam_and_bw.py @@ -151,7 +151,7 @@ def writeBedGraph( bamOrBwFileList, outputFileName, fragmentLength, func, funcArgs, tileSize=25, region=None, blackListFileName=None, numberOfProcessors=1, format="bedgraph", extendPairedEnds=True, missingDataAsZero=False, - smoothLength=0, fixed_step=False, verbose=False): + skipZeroOverZero=False, smoothLength=0, fixed_step=False, verbose=False): r""" Given a list of bamfiles, a function and a function arguments, this method writes a bedgraph file (or bigwig) file @@ -210,7 +210,7 @@ def writeBedGraph( res = mapReduce.mapReduce((tileSize, fragmentLength, bamOrBwFileList, func, funcArgs, extendPairedEnds, smoothLength, - missingDataAsZero, fixed_step), + skipZeroOverZero, missingDataAsZero, fixed_step), writeBedGraph_wrapper, chromNamesAndSize, genomeChunkLength=genomeChunkLength, From 1eccf65770bcf541c45d3e09c21ec192fe115d3a Mon Sep 17 00:00:00 2001 From: Devon Ryan Date: Sun, 31 Mar 2019 16:43:54 +0200 Subject: [PATCH 3/7] Add a test using pseudocounts and skipZeroOverZero --- .../test_bigwigCompare_and_multiBigwigSummary.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py b/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py index 3cd05b940..b567918ea 100644 --- a/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py +++ b/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py @@ -62,6 +62,18 @@ def test_bigwigCompare_skipnas(): unlink(outfile) +def test_bigwigCompare_skipZeroOverZero(): + outfile = '/tmp/result.bg"' + args = "-b1 {} -b2 {} -o {] --skipZeroOverZero --pseudocount 1 3 --outFileFormat bedgraph".format(BIGWIG_A, BIGWIG_A, outfile).split() + bwComp.main(args) + _foo = open(outfile, 'r') + resp = _foo.readlines() + _foo.close() + expected = ['3R\t100\t200\t0.25\n'] + assert resp == expected, "{} != {}".format(resp, expected) + unlink(outfile) + + def test_multiBigwigSummary(): outfile = '/tmp/result.bg' args = "bins -b {} {} --binSize 50 -o {}".format(BIGWIG_A, BIGWIG_B, outfile).split() From 20797ef2f62c88947b22a31f48ab049fa89f6ca8 Mon Sep 17 00:00:00 2001 From: Devon Ryan Date: Sun, 31 Mar 2019 16:49:31 +0200 Subject: [PATCH 4/7] syntax --- deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py b/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py index b567918ea..867b2131a 100644 --- a/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py +++ b/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py @@ -64,7 +64,7 @@ def test_bigwigCompare_skipnas(): def test_bigwigCompare_skipZeroOverZero(): outfile = '/tmp/result.bg"' - args = "-b1 {} -b2 {} -o {] --skipZeroOverZero --pseudocount 1 3 --outFileFormat bedgraph".format(BIGWIG_A, BIGWIG_A, outfile).split() + args = "-b1 {} -b2 {} -o {} --skipZeroOverZero --pseudocount 1 3 --outFileFormat bedgraph".format(BIGWIG_A, BIGWIG_A, outfile).split() bwComp.main(args) _foo = open(outfile, 'r') resp = _foo.readlines() From 0a8fb305d40ce61d9203e63b52784d1bd54e6ec8 Mon Sep 17 00:00:00 2001 From: dpryan79 Date: Mon, 1 Apr 2019 11:15:45 +0200 Subject: [PATCH 5/7] Fix tests --- deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py b/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py index 867b2131a..831924277 100644 --- a/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py +++ b/deeptools/test/test_bigwigCompare_and_multiBigwigSummary.py @@ -69,7 +69,7 @@ def test_bigwigCompare_skipZeroOverZero(): _foo = open(outfile, 'r') resp = _foo.readlines() _foo.close() - expected = ['3R\t100\t200\t0.25\n'] + expected = ['3R\t100\t200\t-1\n'] assert resp == expected, "{} != {}".format(resp, expected) unlink(outfile) From 2d57f5eaabf646817f78f2fd348a6fe776aea160 Mon Sep 17 00:00:00 2001 From: dpryan79 Date: Mon, 1 Apr 2019 11:22:00 +0200 Subject: [PATCH 6/7] Make --skipZeroOverZero a galaxy macro and add to bigwigCompare --- galaxy/wrapper/bamCompare.xml | 6 +----- galaxy/wrapper/bigwigCompare.xml | 2 ++ galaxy/wrapper/deepTools_macros.xml | 8 ++++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/galaxy/wrapper/bamCompare.xml b/galaxy/wrapper/bamCompare.xml index a63210c8f..4c5e45bb1 100644 --- a/galaxy/wrapper/bamCompare.xml +++ b/galaxy/wrapper/bamCompare.xml @@ -164,11 +164,7 @@ - - - - + + diff --git a/galaxy/wrapper/deepTools_macros.xml b/galaxy/wrapper/deepTools_macros.xml index 28501c281..13b8fe809 100644 --- a/galaxy/wrapper/deepTools_macros.xml +++ b/galaxy/wrapper/deepTools_macros.xml @@ -650,6 +650,14 @@ is vital to you, select Yes below."> (default: False)" /> + + + + + + + Date: Mon, 1 Apr 2019 11:30:08 +0200 Subject: [PATCH 7/7] [ci skip] a bit of formatting --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 1b7c6982d..ad6256d2e 100755 --- a/setup.py +++ b/setup.py @@ -86,8 +86,8 @@ def openREADME(): "scipy >= 0.17.0", "matplotlib >= 2.1.2", "pysam >= 0.14.0", - "numpydoc >=0.5", - "pyBigWig >=0.2.1", + "numpydoc >= 0.5", + "pyBigWig >= 0.2.1", "py2bit >= 0.2.0", "plotly >= 2.0.0", "deeptoolsintervals >= 0.1.7"