Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling + cases where with bigwigAverage with more than 2 bigwigs #1257

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions deeptools/test/test_bigwigAverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 6 additions & 4 deletions deeptools/writeBedGraph_bam_and_bw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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':
Expand All @@ -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 "
Expand All @@ -193,14 +193,16 @@ def writeBedGraph(
chromNamesAndSize[chromName], size)
else:
chromNamesAndSize[chromName] = size
cCommon_number[chromName] = 1
fh.close()

# get the list of common chromosome names and sizes
if len(bamOrBwFileList) == 1:
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
Expand Down
Loading