@@ -2143,9 +2143,11 @@ A tree sequence can be treated as a specific form of (directed)
21432143of nodes connected by edges. Standard graph visualization software,
21442144such as [ graphviz] ( https://graphviz.org ) can therefore be used to depict tree sequence
21452145topologies. Alternatively, the [ tskit_arg_visualizer] ( https://github.com/kitchensjn/tskit_arg_visualizer )
2146- project will draw a interactive ` tskit ` graph directly. Below is an example, which uses the
2147- ` variable_edge_width ` option to highlight the spans of genome inherited through different routes.
2148- Nodes can be dragged horizontally and embedded trees highlighted:
2146+ project will draw a interactive ` tskit ` graph directly, in which nodes can be dragged horizontally,
2147+ and embedded (local) trees highlighted by hovering over the "genome bar" underneath the graph.
2148+ Below is an example, showing an ` msprime ` "full ARG" tree sequence. In this case, nodes have only 2 children
2149+ in the graph, so ` edge_type="ortho" ` can be used to draw a traditional
2150+ "[ Ancestral Recombination Graph] ( sec_args ) " style plot:
21492151
21502152``` {code-cell} ipython3
21512153:"tags": ["hide-input"]
@@ -2154,27 +2156,42 @@ require.config({paths: {d3: 'https://d3js.org/d3.v7.min'}});
21542156require(["d3"], function(d3) {window.d3 = d3;});
21552157```
21562158
2159+
21572160``` {code-cell} ipython3
21582161import msprime
21592162import tskit_arg_visualizer
2160- ts = msprime.sim_ancestry(4, sequence_length=1000, recombination_rate=0.001, random_seed=3)
2161- d3arg = tskit_arg_visualizer.D3ARG.from_ts(ts=ts)
2162- tip_order = [0, 6, 3, 1, 2, 7, 4, 5] # Found by trial and error for this seed
2163- d3arg.draw(width=500, height=500, variable_edge_width=True, sample_order=tip_order)
2163+ tip_order = [3, 0, 1, 2, 6, 7, 4, 5] # Found by trial and error for this seed
2164+ full_arg_ts = msprime.sim_ancestry(
2165+ 4, sequence_length=1000, recombination_rate=0.001, record_full_arg=True, random_seed=3)
2166+ d3arg = tskit_arg_visualizer.D3ARG.from_ts(ts=full_arg_ts)
2167+ d3arg.draw(width=500, height=500, edge_type="ortho", sample_order=tip_order);
21642168```
21652169
2166- For an ` msprime ` "full ARG" tree sequence, ` edge_type="ortho" ` can be used to draw a
2167- traditional "[ Ancestral Recombination Graph] ( sec_args ) " style plot (variable edge widths
2168- turned off for clarity):
2170+ For tree sequences that may not be "full ARGs", the default ` edge_type="line" ` is preferable.
2171+ The example below also uses uses the ` variable_edge_width ` option to emphasise which edges have
2172+ wider spans, and ` show_mutations ` to display mutations on edges in an interactive style
2173+ (hovering over the mutation or the genome bar will reveal their locations along the chromosome):
21692174
21702175``` {code-cell} ipython3
21712176import msprime
21722177import tskit_arg_visualizer
2173- tip_order = [3, 0, 1, 2, 6, 7, 4, 5]
2174- full_arg_ts = msprime.sim_ancestry(
2175- 4, sequence_length=1000, recombination_rate=0.001, random_seed=3, record_full_arg=True)
2176- d3arg = tskit_arg_visualizer.D3ARG.from_ts(ts=full_arg_ts)
2177- d3arg.draw(width=500, height=500, edge_type="ortho", sample_order=tip_order)
2178+ ts = msprime.sim_ancestry(
2179+ 4, sequence_length=1000, recombination_rate=0.001, record_full_arg=True, random_seed=3)
2180+ # simplify into a standard (non "full ARG") tree sequence
2181+ ts = ts.simplify()
2182+ ts = msprime.sim_mutations(ts, rate=0.001, random_seed=5)
2183+ d3arg = tskit_arg_visualizer.D3ARG.from_ts(ts=ts)
2184+ tip_order = [3, 0, 1, 2, 6, 7, 4, 5]
2185+ drawinfo = d3arg.draw(
2186+ width=500,
2187+ height=500,
2188+ edge_type="line",
2189+ variable_edge_width=True,
2190+ sample_order=tip_order,
2191+ show_mutations=True,
2192+ label_mutations=True,
2193+ )
2194+ print(f"Extra styling is possible by targetting CSS at this unique id: {drawinfo.uid}")
21782195```
21792196
21802197For more general graph plots, it can be helpful convert the tree sequence to a
0 commit comments