Skip to content

Commit 5cabe3d

Browse files
committed
Add instructions for running the tutes
Fixes tskit-dev#119
1 parent 0b4208f commit 5cabe3d

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

_static/download_data.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Simple script to download all .trees files within the `data` directory on GitHub,
3+
saving to a local `data` directory
4+
"""
5+
6+
import os
7+
import json
8+
import urllib.request
9+
10+
if not os.path.isdir("data"):
11+
os.mkdir("data") # Make a "data" directory within the current folder
12+
# Get the list of data files
13+
info = urllib.request.urlopen("https://api.github.com/repos/tskit-dev/tutorials/git/trees/main?recursive=1")
14+
files = json.loads(info.read().decode(info.info().get_content_charset('utf-8')))['tree']
15+
# Save the data files to the data directory
16+
for path in [file['path'] for file in files]:
17+
if path.startswith("data/") and path.endswith(".trees"):
18+
urllib.request.urlretrieve("https://raw.github.com/tskit-dev/tutorials/main/" + path, path)

_static/requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
jupyter-book>=0.10.0
2+
demes
3+
demesdraw
4+
matplotlib
5+
scikit-allel
6+
numpy
7+
networkx
8+
tskit>=0.3.7
9+
msprime>=1.0

intro.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ such as [msprime](https://tskit.dev/msprime), that use them.
2222
If you are new to the world of tree sequences, we suggest you start with the
2323
first tutorial: {ref}`sec_what_is`
2424

25+
:::{note}
26+
Tutorials are under constant development. Those that are still a work in progress and
27+
not yet ready for use are shown in _italics_ in the list of tutorials.
28+
29+
We very much welcome help developing existing tutorials or writing new ones. Please open
30+
or contribute to a [GitHub issue](https://github.com/tskit-dev/tutorials/issues) if you
31+
would like to help out.
32+
:::
33+
34+
## Other sources of help
35+
36+
Videos and publications about tree sequences are listed on our
37+
[Learn page](https://tskit.dev/learn.html).
38+
2539
We aim to be a friendly, welcoming open source community.
2640
Questions and discussion about using {program}`tskit`, the tree sequence toolkit
2741
should be directed to the
@@ -30,11 +44,53 @@ similar forums for other software in the tree sequence [development community](h
3044
such as for [msprime](https://github.com/tskit-dev/msprime/discussions) and
3145
[tsinfer](https://github.com/tskit-dev/tsinfer/discussions).
3246

33-
:::{note}
34-
Tutorials are under constant development. Those that are still a work in progress and
35-
not yet ready for use are shown in _italics_ in the list of tutorials.
3647

37-
We very much welcome help developing existing tutorials or writing new ones. Please open
38-
or contribute to a [GitHub issue](https://github.com/tskit-dev/tutorials/issues) if you
39-
would like to help out.
40-
:::
48+
## Running tutorial code
49+
50+
It is not necessary to run code in the tutorials yourself: tutorials can be followed by
51+
simply reading each page. However, it is also be possible to run the tutorial code
52+
on your own computer, which will allow you to experiment with the examples provided.
53+
The recommended way to do this is from within a
54+
[Jupyter notebook](https://jupyter.org). As well as installing Jupyter, you will also
55+
need to install the required Python libraries, most importantly
56+
``tskit``, ``msprime``, ``numpy``, and ``matplotlib``. These and other packages are
57+
listed in the [requirements.txt](https://tskit-dev/tutorials/_static/requirements.txt)
58+
file; a shortcut to installing the necessary software is therefore:
59+
60+
```
61+
python3 -m pip install -r https://tskit-dev/tutorials/_static/requirements.txt
62+
```
63+
64+
In addition, to run the R tutorial you will need to install the R
65+
[reticulate](https://rstudio.github.io/reticulate/) library, and if running in a Jupyter,
66+
the [IRkernel](https://irkernel.github.io) library. This can be done by running the
67+
following command within R:
68+
69+
```
70+
install.packages(c("reticulate", "IRkernel")); IRkernel::installspec()
71+
```
72+
73+
(sec_intro_downloading_examples)=
74+
75+
### Downloading example data
76+
77+
Many of the tutorials use pre-existing tree sequences stored in the ``data`` directory.
78+
These can be downloaded from the internet by running the script stored in
79+
[https://tskit-dev/tutorials/_static/download_data.py](https://tskit-dev/tutorials/_static/download_data.py).
80+
If you are running the code in the tutorials from within a Jupyter notebook
81+
then you can simply load this code into a new cell by using the
82+
[%load cell magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-load).
83+
Just run the following in a Jupyter code cell:
84+
85+
```
86+
%load https://tskit-dev/tutorials/_static/download_data.py
87+
```
88+
89+
Executing the resulting Python code should download the data files, allowing code like
90+
the following to run successfully
91+
92+
```{code-cell} ipython3
93+
import tskit
94+
ts = tskit.load("data/basics.trees")
95+
print(f"The file 'data/basics.trees' exists, and contains {ts.num_trees} trees")
96+
```

0 commit comments

Comments
 (0)