Skip to content

Clip painted regions to chromosome outlines - #859

Merged
tanghaibao merged 1 commit into
tanghaibao:mainfrom
wyim-pgl:clip-painted-regions
Sep 3, 2026
Merged

tanghaibao merged 1 commit into
tanghaibao:mainfrom
wyim-pgl:clip-painted-regions

Conversation

@wyim-pgl

@wyim-pgl wyim-pgl commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

python -m jcvi.graphics.chromosome features.bed idmap --size=sizes paints each BED feature as a full-width Rectangle, so a feature at a chromosome end sticks out past the rounded cap.

This change keeps painted regions inside the outline:

  • Chromosome, HorizontalChromosome and ChromosomeWithCentromere keep their outline (self.outline, or a compound path of both arms for the centromere glyph) and gain a clip(artist) helper.
  • draw_chromosomes clips 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.
  • The glyphs' own patch= rectangles are clipped the same way. Clipping happens after add_patches() because set_clip_path() captures the outline's transform at call time, and set_transform() re-clips for callers such as karyotype that transform the glyph after construction.
  • Chromosome borders and the centromere circle still draw above the painted regions. --imagemap output is unchanged.

Verified on PNG, PDF and SVG output with and without centromeres. New tests in tests/graphics/test_chromosome.py render each glyph and check pixels inside and just outside the caps; they fail on main and pass with this change.

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.
@Adamtaranto

Copy link
Copy Markdown
Collaborator

Hi @wyim-pgl can you please post example before and after images showing the issue and the fix?

@wyim-pgl

wyim-pgl commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author
compare Here we go.

@Adamtaranto

Copy link
Copy Markdown
Collaborator

I don't see the issue with the feature sticking out past the rounded cap

@holschbachPGL

Copy link
Copy Markdown
Screenshot after Screenshot before

here is some additional context

@tanghaibao

Copy link
Copy Markdown
Owner

looks good, thanks all @wyim-pgl @Adamtaranto @holschbachPGL

@tanghaibao
tanghaibao merged commit bb07674 into tanghaibao:main Sep 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants