Skip to content

diagram: --gene label filter, directional thresholds, graceful reversed intervals#1104

Merged
etal merged 2 commits into
masterfrom
feature-cnvkit-5yt-diagram-genes-thresholds
Jun 9, 2026
Merged

diagram: --gene label filter, directional thresholds, graceful reversed intervals#1104
etal merged 2 commits into
masterfrom
feature-cnvkit-5yt-diagram-genes-thresholds

Conversation

@etal

@etal etal commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

Extends cnvkit.py diagram with 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. Mirrors scatter's --gene (singular; -g stays the deprecated --sample-sex alias on diagram, 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-high and losses at or below --threshold-low; omitting a side suppresses labels in that direction. For example, --threshold-high 0.5 labels gains only, and --threshold-low -25 drops deletion labels while gains still surface.
  • Graceful reverse-oriented intervals — intervals stored with 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 asserts 0 <= start <= end <= length.

Output stability

The symmetric threshold maps internally to the directional pair (-t, +t), for which log2 >= high or log2 <= low is exactly abs(log2) >= threshold. Default diagram invocations 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.py covering symmetric-default equivalence, each directional mode, the -t/directional mutual-exclusion guard, --gene filtering (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_diagramcreate_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

etal and others added 2 commits June 8, 2026 22:15
… 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

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.46939% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.73%. Comparing base (34a697e) to head (e2722ee).

Files with missing lines Patch % Lines
cnvlib/commands.py 37.50% 8 Missing and 2 partials ⚠️
cnvlib/diagram.py 90.62% 1 Missing and 2 partials ⚠️
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     
Flag Coverage Δ
unittests 70.73% <73.46%> (+0.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@etal etal merged commit 731d6a3 into master Jun 9, 2026
13 checks passed
@etal etal deleted the feature-cnvkit-5yt-diagram-genes-thresholds branch June 9, 2026 05:39
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.

diagram: -g/--genes option to label only the specified regions

1 participant