Skip to content

Commit ba44c3e

Browse files
authored
Merge pull request #261 from hyanwong/prettify-welcome
Put a picture on the tutorial welcome page
2 parents c3e1686 + d34ee00 commit ba44c3e

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

intro.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,62 @@ kernelspec:
1616
# Welcome!
1717

1818
This site contains a number of tutorials to develop your understanding of
19-
[succinct tree sequences](https://tskit.dev/learn/) as implemented in the
20-
[tree sequence toolkit](https://tskit.dev/tskit/docs/), along with software
21-
programs, such as [msprime](https://tskit.dev/msprime/docs), that use them.
19+
genetic genealogies, ancestral recombination graphs, and the
20+
[succinct tree sequence](https://tskit.dev/learn/) storage format,
21+
as implemented in [`tskit`: the tree sequence toolkit](https://tskit.dev/tskit/docs/).
22+
Also included are a number of tutorials showing advanced use of
23+
[software programs](https://tskit.dev/software/),
24+
such as [`msprime`](https://tskit.dev/msprime/docs), that form part of the
25+
[`tskit` ecosystem](https://tskit.dev).
26+
27+
```{code-cell} ipython3
28+
:tags: [remove-input]
29+
import math
30+
import msprime
31+
32+
def make_7_tree_4_tip_ts():
33+
ts = msprime.sim_ancestry(
34+
4, ploidy=1, random_seed=889, sequence_length=1000, recombination_rate=0.001)
35+
ts = msprime.sim_mutations(ts, rate=2e-3, random_seed=123)
36+
37+
# Check we have picked a random seed that gives a nice plot of 7 trees
38+
tip_orders = {
39+
tuple(u for u in t.nodes(order="minlex_postorder") if t.is_sample(u))
40+
for t in ts.trees()
41+
}
42+
topologies = {tree.rank() for tree in ts.trees()}
43+
assert tip_orders == {(0, 1, 2, 3)} and len(topologies) > 1 and ts.num_trees == 7
44+
45+
return ts
46+
47+
48+
ts = make_7_tree_4_tip_ts()
49+
50+
# Set some parameters: these can be adjusted to your liking
51+
tree_width = 80
52+
height = 200 # Normal height for tree + x-axis
53+
y_step = 20 # Stagger between trees (i.e. 0 for all trees in a horizontal line)
54+
skew = 0.7 # How skewed the trees are, in radians
55+
56+
width = tree_width * ts.num_trees + 20 + 20 # L & R margins in draw_svg = 20px
57+
angle = math.atan(y_step/tree_width)
58+
ax_mv = y_step, (ts.num_trees - 1) * y_step - 90 + math.tan(skew) * (tree_width * .9)
59+
60+
# CSS transforms used to skew the axis and stagger + skew the trees
61+
style = f".x-axis {{transform: translate({ax_mv[0]}px, {ax_mv[1]}px) skewY(-{angle}rad)}}"
62+
for i in range(ts.num_trees):
63+
# Stagger each tree vertically by y_step, transforming the "plotbox" tree container
64+
style += (
65+
f".tree.t{i} > .plotbox " + "{transform:" +
66+
f"translateY({(ts.num_trees - i - 1) * y_step-85}px) skewY({skew}rad)" + "}"
67+
)
68+
69+
# Define a bigger canvas size so we don't crop the moved trees from the drawing
70+
size = (width, height)
71+
canvas_size = (width + y_step, height + math.tan(skew)*tree_width)
72+
73+
ts.draw_svg(size=size, x_scale="treewise", style=style, canvas_size=canvas_size)
74+
```
2275

2376
If you are new to the world of tree sequences, we suggest you start with the
2477
first tutorial: {ref}`sec_what_is`

0 commit comments

Comments
 (0)