Skip to content

computeMatrix: decode gzipped BED lines in sortMatrix (fixes #1423) - #1451

Closed
cindykrafft wants to merge 1 commit into
deeptools:masterfrom
cindykrafft:fix/issue-1423-gzipped-bed-sortmatrix
Closed

computeMatrix: decode gzipped BED lines in sortMatrix (fixes #1423)#1451
cindykrafft wants to merge 1 commit into
deeptools:masterfrom
cindykrafft:fix/issue-1423-gzipped-bed-sortmatrix

Conversation

@cindykrafft

Copy link
Copy Markdown

Welcome to deepTools GitHub repository! Please check the following regarding
your pull request :

  • Does the PR contain new feature?
  • Does the PR contain bugfix?
  • Does the PR contain documentation changes?
  • Does the PR contain changes to the galaxy wrapper?

Fixes #1423.

This is the deeptoolsintervals/parse.py#L15 pattern you pointed at in the issue thread: the same if not isinstance(line, str): line = line.decode('ascii') guard that getNext() uses there and that loadGTF() already has a few lines further down in this file, applied to loadBED(). Opening it because the issue is still open since March and unassigned, but obviously please close this if this is not needed.

Cause. With the default --sortRegions keep, computeMatrix re-reads the regions file in computeMatrixOperations.sortMatrix() to restore the input order. deeptoolsintervals.openPossiblyCompressed() opens a gzipped file in binary mode; getNext() decodes the header/first line, but loadBED() then iterates the remaining lines of the handle as bytes, so line.startswith("#") raises TypeError: startswith first arg must be bytes or a tuple of bytes, not str. The matrix itself is computed fine (the deeptoolsintervals parser handles compressed files); the crash happens right before the matrix is written, so every computeMatrix run on a .bed.gz fails unless --sortRegions no/ascend/descend is given. computeMatrixOperations sort -R regions.bed.gz fails the same way. loadGTF() in the same file already decodes its lines.

Fix. Decode non-str lines in loadBED() exactly as loadGTF() does (two lines in deeptools/computeMatrixOperations.py). No change for plain-text BED files.

Tests. test_heatmapper.py::test_computeMatrix_gzipped_bed runs computeMatrix reference-point on a gzipped copy of the existing test2.bed and checks the matrix equals master.mat; test_computeMatrixOperations.py::testsortGzippedBED runs computeMatrixOperations sort on a gzipped copy of computeMatrixOperations.bed and checks the same md5 as the existing testsort. Both fail on master with the TypeError above and pass with the fix.

Run. pytest deeptools/test/test_heatmapper.py deeptools/test/test_computeMatrixOperations.py: 21 passed + 2 failed (the new tests) before, 23 passed after; full suite 100 passed with the fix (the two remaining failures, test_plotCoverage_default and test_tools, fail identically on unmodified master in this environment). flake8 with the CI options is clean on the changed files. A CHANGES.txt bullet is included under an unreleased heading.

Found while working through open issues in Mytochondria, a volunteer project that verifies fixes for the software behind published results (methods and harnesses: https://github.com/cindykrafft/mytochondria/tree/main/audits/deeptools)


Generated by Claude Code

With the default --sortRegions keep, computeMatrix re-reads the regions
file in computeMatrixOperations.sortMatrix to restore the input order.
openPossiblyCompressed opens a gzipped file in binary mode, and while
getNext decodes the header lines, loadBED iterated the remaining lines
as bytes, so every gzipped BED crashed with

    TypeError: startswith first arg must be bytes or a tuple of bytes, not str

loadGTF already decoded its lines; do the same in loadBED.  Tests for
computeMatrix and computeMatrixOperations sort on a gzipped copy of the
existing test BEDs, which fail before this change.

Fixes deeptools#1423

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TaHntBDKuZJpMAAMenkC44
@WardDeb

WardDeb commented Sep 5, 2026

Copy link
Copy Markdown
Member

Thanks for the work, this was adressed in #1452

@WardDeb WardDeb closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failure to parse (compressed) Bed file in computeMatrix

2 participants