Visualization¶
Throughout this documentation you have likely seen many examples of visualizations. Here we explain the options for each of these in greater detail.
import toytree
import ipcoal
Test dataset¶
Simulate sequence data for a 5-tip species tree scenario.
sptree = toytree.rtree.unittree(ntips=5, treeheight=2e5, seed=123)
sptree.set_node_data("Ne", data={0:1e4, 1:2e4}, default=3e4, inplace=True)
model = ipcoal.Model(sptree, store_tree_sequences=True)
model.sim_loci(10, 1e4)
draw_genealogy¶
The draw_genealogy
method takes two unique arguments, idx
and show_substitutions
, as well as a large set of optional arguments that can be passed as kwargs (described below). The idx
argument selects the genealogy from the Model.df
simulation table, where each simulated genealogy has a unique index in the table. This provides a simple and convenient shortcut to select a newick string from the Model.df table, load it as a ToyTree, and draw it.
model.draw_genealogy(idx=0);
All additional kwargs that can be passed to this function include any styling options that are supported by the toytree library for drawing trees (i.e., args to ToyTree.draw
). Below are some examples.
model.draw_genealogy(idx=1, edge_widths=3, tip_labels_style={"font-size": 15}, height=275);
Finally, the show_substitutions
arg can be used to show mutations on each branch. This requires that the Model object was initialized with store_tree_sequences=True
to store the mutation info. (This is currently very simple and does not take additional options to style the mutation markers. We hope to add more soon.)
model.draw_genealogy(idx=0, show_substitutions=True);
draw_genealogies¶
Similar to how the function above selects a single genealogy and draws it as a ToyTree, this method loads a set of multiple newick strings and draws them as a toytree.MultiTree
drawing. Thus, it accepts any kwargs accepted by toytree.Multitree.draw
. This is used to draw a grid of multiple trees on separate or shared axes.
model.draw_genealogies(idxs=[0, 1, 2, 3]);
model.draw_genealogies(idxs=range(1, 5), shared_axes=True, scale_bar=True);
model.draw_genealogies(idxs=range(4, 10), shape=(2, 3), shared_axes=True, scale_bar=1_000, height=400);
draw_cloud_tree¶
model.draw_cloud_tree();
model.draw_cloud_tree(idxs=range(10, 20), edge_colors="darkcyan", edge_style={"stroke-opacity": 0.1});
draw_sptree¶
This is similar to the toytree method ...
model.draw_sptree();
draw_demography¶
model.draw_demography();
model.draw_demography(idx=0);
model.draw_demography(idx=13, container_blend=True);
There are many additional styling arguments, but not all are fully tested together yet. Please provide feedback/requests.
model.draw_demography(
idx=0,
container_blend=True, container_width=500, container_height=300,
container_fill="red", container_fill_opacity=0.4, container_fill_opacity_alternate=0.2,
container_root_height=50_000,
# container_interval_spacing=1000, container_interval_minwidth=1, container_interval_maxwidth=2,
# container_stroke="blue", container_stroke_width=3, container_stroke_opacity=0.2,
);
draw_tree_sequence¶
model.draw_tree_sequence(width=700);
draw_seqview¶
model.draw_seqview(idx=0, start=0, end=200, show_text=True);
draw_embedded_genealogy¶
The method draw_embedded_genealogy
is similar to Model.draw_demography
but does not require that you create a Model object. Instead, given a species tree, genealogy, and mapping of genealogy tips to species tree lineages, you can draw an embedding.
S, G, I = ipcoal.msc.get_test_data(nloci=10, nsites=1, seed=123)
ipcoal.draw.draw_embedded_genealogy(S, G[0], I);