diagram: --gene label filter, directional thresholds, graceful reversed intervals#1104
Merged
Merged
Conversation
… intervals (#248) Extend `cnvkit.py diagram` with three capabilities: - `--gene MYC,ERBB2`: label only the named genes among those passing the threshold, dropping co-binned neighbors. Mirrors scatter's `--gene` (singular; `-g` remains the deprecated `--sample-sex` alias here). - `--threshold-low` / `--threshold-high`: directional log2 cutoffs, mutually exclusive with the symmetric `-t/--threshold`. Label gains at or above `--threshold-high` and losses at or below `--threshold-low`; omitting a side suppresses labels in that direction (e.g. `--threshold-low -25` drops deletion labels while gains still surface). - Graceful handling of reverse-oriented intervals (start > end), which arise when reverse-direction PCR primers are stored that way in the input BED. The interval is taken to span [min, max] rather than crashing Biopython's chromosome renderer. The symmetric threshold maps internally to the directional pair (-t, +t), for which "log2 >= high or log2 <= low" is exactly "abs(log2) >= threshold", so the default diagram output is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
GitHub does not auto-link the gh# prefix; the repo's convention is a bare #N. Fixes two stray references in scatter test docstrings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1104 +/- ##
==========================================
+ Coverage 70.41% 70.73% +0.32%
==========================================
Files 73 73
Lines 7907 7946 +39
Branches 1400 1405 +5
==========================================
+ Hits 5568 5621 +53
+ Misses 1891 1881 -10
+ Partials 448 444 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
cnvkit.py diagramwith finer control over gene labeling, plus a robustness fix for reverse-oriented input intervals.--gene MYC,ERBB2— label only the named genes among those passing the threshold, dropping co-binned neighbors. This is the original request in diagram: -g/--genes option to label only the specified regions #248. Mirrorsscatter's--gene(singular;-gstays the deprecated--sample-sexalias ondiagram, so there is no short form).--threshold-low/--threshold-high— directional log2 cutoffs, mutually exclusive with the symmetric-t/--threshold. Label gains at or above--threshold-highand losses at or below--threshold-low; omitting a side suppresses labels in that direction. For example,--threshold-high 0.5labels gains only, and--threshold-low -25drops deletion labels while gains still surface.start > end(e.g. reverse-direction PCR primers saved that way in the input BED) are now taken to span[min, max]rather than crashing Biopython's chromosome renderer, which asserts0 <= start <= end <= length.Output stability
The symmetric threshold maps internally to the directional pair
(-t, +t), for whichlog2 >= high or log2 <= lowis exactlyabs(log2) >= threshold. Defaultdiagraminvocations therefore produce unchanged output; the new behavior is opt-in via the new flags. No.cnr/.cns/.cnn/SEG/VCF formats are touched.Tests
14 new tests in
test/test_plots.pycovering symmetric-default equivalence, each directional mode, the-t/directional mutual-exclusion guard,--genefiltering (including whitespace tolerance and co-binned-neighbor dropping), reverse-interval coordinate normalization, and an end-to-end render. An AST-walk plumbing test pins the new kwargs through_cmd_diagram→create_diagram. Full plots suite passes; ruff and mypy clean.Docs
doc/plots.rst"Reducing cluttered gene labels" documents the new flags.Fixes #248.
🤖 Generated with Claude Code