Repository navigation
Clip painted regions to chromosome outlines - #859
Merged
Merged
Conversation
In `jcvi.graphics.chromosome`, BED features are painted as full-width rectangles, so features at a chromosome end stick out past the rounded cap. Store the outline polygon on `Chromosome`, `HorizontalChromosome` and `ChromosomeWithCentromere`, expose a `clip()` helper, and clip each painted rectangle to the glyph that contains it. The glyphs' own `patch=` rectangles are clipped the same way, and re-clipped after `set_transform()` since the clip path captures the outline's transform. Add rendering tests covering plain, horizontal, transformed and centromere chromosomes.
Collaborator
|
Hi @wyim-pgl can you please post example before and after images showing the issue and the fix? |
Contributor
Author
Collaborator
|
I don't see the issue with the feature sticking out past the rounded cap |
tanghaibao
approved these changes
Sep 3, 2026
Owner
|
looks good, thanks all @wyim-pgl @Adamtaranto @holschbachPGL |
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.



python -m jcvi.graphics.chromosome features.bed idmap --size=sizespaints each BED feature as a full-widthRectangle, so a feature at a chromosome end sticks out past the rounded cap.This change keeps painted regions inside the outline:
Chromosome,HorizontalChromosomeandChromosomeWithCentromerekeep their outline (self.outline, or a compound path of both arms for the centromere glyph) and gain aclip(artist)helper.draw_chromosomesclips every painted rectangle to the glyph that contains it. Features that extend beyond the chromosome length are clipped at the cap; features entirely beyond it become invisible instead of floating past the end.patch=rectangles are clipped the same way. Clipping happens afteradd_patches()becauseset_clip_path()captures the outline's transform at call time, andset_transform()re-clips for callers such askaryotypethat transform the glyph after construction.--imagemapoutput is unchanged.Verified on PNG, PDF and SVG output with and without centromeres. New tests in
tests/graphics/test_chromosome.pyrender each glyph and check pixels inside and just outside the caps; they fail onmainand pass with this change.