From c7657cbfed31ebb520279ee616c674154a1bf556 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Tue, 26 Sep 2023 00:52:16 +0200 Subject: [PATCH 1/3] typeerror to runtimeerror --- deeptools/writeBedGraph_bam_and_bw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeptools/writeBedGraph_bam_and_bw.py b/deeptools/writeBedGraph_bam_and_bw.py index fceb2cc6..9debf931 100644 --- a/deeptools/writeBedGraph_bam_and_bw.py +++ b/deeptools/writeBedGraph_bam_and_bw.py @@ -23,7 +23,7 @@ def getCoverageFromBigwig(bigwigHandle, chrom, start, end, tileSize, missingDataAsZero=False): try: coverage = np.asarray(bigwigHandle.values(chrom, start, end)) - except TypeError: + except RuntimeError: # this error happens when chromosome # is not into the bigwig file return [] From d5ff676af81c7e97d5af3e0bb581c753505db759 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Tue, 26 Sep 2023 15:04:28 +0200 Subject: [PATCH 2/3] add meaningful test --- deeptools/test/test_bigwigAverage.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deeptools/test/test_bigwigAverage.py b/deeptools/test/test_bigwigAverage.py index fed8f216..7f863291 100644 --- a/deeptools/test/test_bigwigAverage.py +++ b/deeptools/test/test_bigwigAverage.py @@ -69,3 +69,15 @@ def test_bigwigAverageWithScale(): expected = ['3R\t0\t50\t0\n', '3R\t50\t100\t0.25\n', '3R\t100\t150\t0.75\n', '3R\t150\t200\t1\n'] assert f"{resp}" == f"{expected}", f"{resp} != {expected}" unlink(outfile) + + +def test_bigwigAverageThree(): + outfile = '/tmp/result.bg' + args = "--bigwigs {} {} {} -o {} --outFileFormat bedgraph --scaleFactors 0.75:0.75:.75".format(BIGWIG_A, BIGWIG_A, BIGWIG_B, outfile).split() + bwAve.main(args) + _foo = open(outfile, 'r') + resp = _foo.readlines() + _foo.close() + expected = ['3R\t0\t50\t0\n', '3R\t50\t100\t0.25\n', '3R\t100\t150\t0.75\n', '3R\t150\t200\t1\n'] + assert f"{resp}" == f"{expected}", f"{resp} != {expected}" + unlink(outfile) From f0c8223bf9fb26953c10348f421a5d759dab9a2f Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Tue, 26 Sep 2023 15:22:08 +0200 Subject: [PATCH 3/3] fix cases when chromosome shared by 2 but not all --- deeptools/writeBedGraph_bam_and_bw.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deeptools/writeBedGraph_bam_and_bw.py b/deeptools/writeBedGraph_bam_and_bw.py index 9debf931..c3296bc1 100644 --- a/deeptools/writeBedGraph_bam_and_bw.py +++ b/deeptools/writeBedGraph_bam_and_bw.py @@ -170,7 +170,7 @@ def writeBedGraph( chromNamesAndSize, __ = getCommonChrNames(bamHandles, verbose=verbose) else: genomeChunkLength = int(10e6) - cCommon = [] + cCommon_number = {} chromNamesAndSize = {} for fileName, fileFormat in bamOrBwFileList: if fileFormat == 'bigwig': @@ -180,7 +180,7 @@ def writeBedGraph( for chromName, size in list(fh.chroms().items()): if chromName in chromNamesAndSize: - cCommon.append(chromName) + cCommon_number[chromName] += 1 if chromNamesAndSize[chromName] != size: print("\nWARNING\n" "Chromosome {} length reported in the " @@ -193,6 +193,7 @@ def writeBedGraph( chromNamesAndSize[chromName], size) else: chromNamesAndSize[chromName] = size + cCommon_number[chromName] = 1 fh.close() # get the list of common chromosome names and sizes @@ -200,7 +201,8 @@ def writeBedGraph( chromNamesAndSize = [(k, v) for k, v in chromNamesAndSize.items()] else: chromNamesAndSize = [(k, v) for k, v in chromNamesAndSize.items() - if k in cCommon] + if k in cCommon_number and + cCommon_number[k] == len(bamOrBwFileList)] if region: # in case a region is used, append the tilesize