-
Notifications
You must be signed in to change notification settings - Fork 17
Description
To encourage people to think of tree sequences as graph objects, I think it would be helpful to add the graph representation to the "What is a Tree Sequence" tutorial, round about here. This is how you might do it:
import tskit_arg_visualizer as viz
arg = viz.D3ARG.from_ts(ts=ts)
arg.set_node_labels({k: (v if k in ts.samples() else "") for k, v in labels.items()})
arg.draw(
variable_edge_width=True,
y_axis_scale="time",
sample_order=sorted({k: v for k, v in labels.items()if k in ts.samples()}, key=lambda x: labels[x]))
Currently this gives a plot like this:

I think a few things would be helpful to make this look simpler. In particular, if we could change the node sizes & shapes such that the internal nodes are (very) small circles and the sample nodes are square, that would match the tree-by-tree plot above it (kitchensjn/tskit_arg_visualizer#30). Allowing the y-axis ticks to be set to user-chosen values would also be helpful, I think.
Perhaps @kitchensjn has some ideas about how to make the plot friendly to a newcomer in this context?
Note that ts
has been produced by code in the nodebook, like that below:
import msprime
import demes
def whatis_example():
demes_yml = """\
description:
Asymmetric migration between two extant demes.
time_units: generations
defaults:
epoch:
start_size: 5000
demes:
- name: Ancestral_population
epochs:
- end_time: 1000
- name: A
ancestors: [Ancestral_population]
- name: B
ancestors: [Ancestral_population]
epochs:
- start_size: 2000
end_time: 500
- start_size: 400
end_size: 10000
migrations:
- source: A
dest: B
rate: 1e-4
"""
graph = demes.loads(demes_yml)
demography = msprime.Demography.from_demes(graph)
# Choose seed so num_trees=3, tips are in same order,
# first 2 trees are topologically different, and all trees have the same root
seed = 12581
ts = msprime.sim_ancestry(
samples={"A": 2, "B": 3},
demography=demography,
recombination_rate=1e-8,
sequence_length=1000,
random_seed=seed)
# Mutate
# Choose seed to give 12 muts, last one above node 14
seed = 1476
return msprime.sim_mutations(ts, rate=1e-7, random_seed=seed)