-
Notifications
You must be signed in to change notification settings - Fork 42
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
Is there a way to plot shapes on tracks? #48
Comments
Hi @dongzhang0725, I think Code Example from pycirclize import Circos
from pycirclize.utils import load_example_tree_file, ColorCycler
import random
tree_file = load_example_tree_file("large_example.nwk")
circos, tv = Circos.initialize_from_tree(
tree_file,
r_lim=(40, 90),
leaf_label_size=5,
leaf_label_rmargin=10,
label_formatter=lambda t: t.replace("_", " "),
)
# Add track for marker plot
tree_sector = circos.sectors[0]
track = tree_sector.add_track((90, 100))
# Plot 3 layer markers for leaf labels
for leaf_label in tv.leaf_labels:
x = tv.name2xr[leaf_label][0]
track.scatter(x=[x], y=[0.2], vmin=0, vmax=1, color="salmon")
track.scatter(x=[x], y=[0.5], vmin=0, vmax=1, color="skyblue", marker="s")
if random.random() > 0.5:
track.scatter(x=[x], y=[0.8], vmin=0, vmax=1, color=ColorCycler(), marker="*", s=25)
circos.savefig("example.png", dpi=300) example.png |
Dear @moshi4 , Thank you for your prompt response; it works like a charm. Pycirclize proves to be very powerful and convenient. I am planning to utilize it for tree annotations. I have an additional question regarding the display of support values on the nodes, as this is crucial for phylogenetic tree visualization, and I did not find relevant information on the homepage. Specifically, I am interested in displaying support value text on the branches of MCA, similar to this example: On another note, is there a way to convert the circular tree to a rectangular mode? If so, I believe it could be a promising tool to replace iTOL, an online tree annotation tool that requires a subscription. |
Example Code Plot bootstrap values on each internal node in tree. from pycirclize import Circos
from pycirclize.utils import load_example_tree_file
import random
tree_file = load_example_tree_file("large_example.nwk")
circos, tv = Circos.initialize_from_tree(
tree_file,
r_lim=(20, 100),
leaf_label_size=5,
label_formatter=lambda t: t.replace("_", " "),
line_kws=dict(color="grey"),
)
# Set tentative bootstrap value to internal nodes of tree
# 'large_example.nwk' has no bootstrap value
for innode in tv.tree.get_nonterminals():
innode.confidence = random.randint(90, 100)
# Plot bootstrap value on each internal node in tree
sector = circos.sectors[0]
for innode in tv.tree.get_nonterminals():
x, r =tv.name2xr[innode.name]
if innode.confidence is not None:
bootstrap_value = str(innode.confidence)
sector.text(bootstrap_value, x, r + 0.5, size=5, color="black", orientation="vertical")
circos.savefig("example.png", dpi=300) example.png It may be good idea to add a method to the TreeViz class to more easily perform bootstrap value plots. I will consider this in the next release.
pyCirclize does not provide a way to convert a circular tree to a rectangular tree. Since pyCirclize is a "Circular visualization in Python" library, it is not intended to implement tree plotting in rectangular mode. |
Dear @moshi4 , Thank you for providing the code; it has been very helpful. I am also experimenting with integrating a text() function into the TreeViz class, which is derived from the marker() function, and I have achieved some initial success with it.
If you are planning to add a method to draw text to the TreeViz class, I have an alternative suggestion concerning the text's position (which can also be applied to markers). Specifically, consider finding a way to obtain the position (x and r) of the center of the branch of MCA. This would allow the text to be positioned at the center of the internal branches. Following this, we may also need some adjustments to shift the x position and avoid overlaps between text and branches.
Thank you for your helps again, Dong |
I close this issue because the issue of the title has been resolved. Other feature requests raised in the discussion will be considered separately. |
Can we plot shapes of matplotlib (https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers) on a track of the tree figure? If so, can anyone give me an example? Thank you!
![image](https://private-user-images.githubusercontent.com/15956921/294765674-7d464cbc-6d86-4e96-9826-4fb9a16ae3e7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwNjA2MTYsIm5iZiI6MTcyNDA2MDMxNiwicGF0aCI6Ii8xNTk1NjkyMS8yOTQ3NjU2NzQtN2Q0NjRjYmMtNmQ4Ni00ZTk2LTk4MjYtNGZiOWExNmFlM2U3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDA5MzgzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJjMWJkNWVjYmRhNTQ3M2FjMzg1OWFhMWVhOTdmNjZjM2UyMDIyMmIzYjZkNWNiZDgyZjdiMTUxOTg2ODQ0MDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.46Q8c4jfku6ctmRrR4MknOgDSogKnErozqsUxO5ZcMA)
For example:
The text was updated successfully, but these errors were encountered: