Comments (5)
Hi @dongzhang0725,
I think track.scatter()
method can do roughly the same thing.
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
from pycirclize.
Hi @dongzhang0725,
I think
track.scatter()
method can do roughly the same thing.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.
from pycirclize.
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
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.
On another note, is there a way to convert the circular tree to a rectangular mode?
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.
If you want to plot trees in rectangular mode as well as pyCirclize, you may be interested in looking at the phyTreeViz library.
from pycirclize.
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
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.
On another note, is there a way to convert the circular tree to a rectangular mode?
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. If you want to plot trees in rectangular mode as well as pyCirclize, you may be interested in looking at the phyTreeViz library.
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.
def text(
self,
query: str | list[str] | tuple[str],
text,
*,
size: int = 6,
**kwargs,
) -> None:
target_node_name = self.search_target_node_name(query)
# Set markers (x, r) coordinates (include descendent nodes)
x: list[float] = []
r: list[float] = []
rmin, rmax = self.track.r_plot_lim
clade: Clade = next(self.tree.find_clades(target_node_name))
descendent_nodes: list[Clade] = list(clade.find_clades())
for descendent_node in descendent_nodes:
node_x, node_r = self.name2xr[str(descendent_node.name)]
if descendent_node.is_terminal() and self._align_leaf_label:
node_r = rmax if self._outer else rmin
x.append(node_x)
r.append(node_r)
# If `descendent=False`, remove descendent nodes (x, r) coordinate
# if not descendent:
x, r = x[0], r[0]
self.track.text(text, x, r, **kwargs)
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.
If you want to plot trees in rectangular mode as well as pyCirclize, you may be interested in looking at the [phyTreeViz](https://github.com/moshi4/phyTreeViz) library.
It's great to learn that you've developed a separate package for handling rectangular trees. I will explore the source code to attempt combining various plots (barplot, pieplot, scatter, etc.) with it.
Thank you for your helps again,
Dong
from pycirclize.
I close this issue because the issue of the title has been resolved.
Other feature requests raised in the discussion will be considered separately.
from pycirclize.
Related Issues (20)
- Making the color of external nodes to be the same as its corresponding Arcs color to destination HOT 11
- Can't plot more than 3 tracks HOT 2
- DIC object Not callable HOT 6
- Custom colors for each feature HOT 2
- Phylogenetic leaf labels with spaces are truncated HOT 2
- Arrows HOT 2
- Some modifications in my link circos HOT 9
- Issue with ZeroDivisionError in Circos Plot HOT 2
- Is there any way to integrate between heatmap data and tree leaves? HOT 3
- Confused with bar plot HOT 2
- Enable wrapping/bending the text around a circle HOT 1
- Track Heatmap cmap Customization HOT 2
- cannot import name 'SimpleLocation' from 'Bio.SeqFeature' HOT 1
- figuresize HOT 1
- Massive size on save to svg - vectors of sector borders and some other lines have tons of nodes HOT 1
- Doubt regarding pycircilize HOT 3
- How to use vmin argument in `track.line()` method HOT 1
- Question: Linear tree visualization HOT 2
- Highlight different gene functioins with different tick/label colors and jitter labels HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycirclize.