Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to plot annotations (e.g. genes) along the x-axis #3002

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

hyanwong
Copy link
Member

@hyanwong hyanwong commented Sep 25, 2024

Description

Fixes #3000

PR Checklist:

  • Tests that fully cover new/changed functionality.
  • Documentation including tutorial content if appropriate.
  • Changelogs, if there are API changes.

@hyanwong
Copy link
Member Author

hyanwong commented Sep 25, 2024

Example:

import msprime
ts = msprime.simulate(2, length=10, mutation_rate=1, random_seed=9)
ts.draw_svg(x_axis=True, size=(400, 300), x_regions={(1, 3): "foo", (3.2, 5): "bar"})
Screenshot 2024-09-25 at 17 25 19

Also works if trees are skipped:

import msprime
ts = msprime.simulate(2, length=10, mutation_rate=1, recombination_rate=0.2, random_seed=9)
ts.draw_svg(x_axis=True, size=(800, 300), max_num_trees=4, x_regions={(0.5, 3): "foo", (5, 6): "bar"})
Screenshot 2024-09-25 at 17 27 10

I think it should be up to the user to hide X tickmarks if they are deemed to get in the way of the annotation labels, as in the example above. E.g. that could be done by style=".x-axis .tick:nth-child(3) text {display: none}"

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 95.83333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.80%. Comparing base (56a163e) to head (979da99).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
python/tskit/drawing.py 95.83% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3002   +/-   ##
=======================================
  Coverage   89.79%   89.80%           
=======================================
  Files          29       29           
  Lines       31917    31931   +14     
  Branches     6175     6179    +4     
=======================================
+ Hits        28660    28675   +15     
  Misses       1860     1860           
+ Partials     1397     1396    -1     
Flag Coverage Δ
c-tests 86.68% <ø> (ø)
lwt-tests 80.78% <ø> (ø)
python-c-tests 89.03% <ø> (ø)
python-tests 99.01% <95.83%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
python/tskit/trees.py 98.80% <ø> (ø)
python/tskit/drawing.py 99.32% <95.83%> (+0.09%) ⬆️

@hyanwong
Copy link
Member Author

I picked yellow region boxes for no particular reason, other than we are unlikely to use that colour for anything else (yellow symbols are generally impossible to see). I should probably add a tutorial example if this addition is thought to be useful.

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like it.

What happens when you have overlapping regions (which will happen, I'd imagine)?

python/tskit/drawing.py Outdated Show resolved Hide resolved
python/tskit/drawing.py Show resolved Hide resolved
@hyanwong
Copy link
Member Author

hyanwong commented Sep 26, 2024

Nice, I like it.

What happens when you have overlapping regions (which will happen, I'd imagine)?

We just plot overlapping boxes. I guess that's fine? If people want to distinguish them they can colour them using transparency. Actually, I think it would be good to make the boxes semi-opaque by default, so people notice if there are overlaps. A 50% opacity example is below: this LGTM, so I'll change the default style to that, unless anyone objects.

Screenshot 2024-09-26 at 11 34 34

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@petrelharp
Copy link
Contributor

This is excellent!

@jeromekelleher jeromekelleher added the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Sep 27, 2024
@mergify mergify bot merged commit 170cae3 into tskit-dev:main Sep 27, 2024
21 checks passed
@mergify mergify bot removed the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Sep 27, 2024
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.

Ability to add tick positions and annotations to the X axis in draw_svg()
4 participants