Skip to content

Commit f06e2a9

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

File tree

3 files changed

+89
-12
lines changed

3 files changed

+89
-12
lines changed

Diff for: _static/download_data.py

+18
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)

Diff for: basics.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ concepts behind {program}`tskit`, the tree sequence toolkit.
6565
## Terminology
6666

6767
::::{margin}
68-
:::{seealso}
69-
Many of the terms below are also {ref}`covered <tskit:sec_data_model_definitions>`
70-
in the official {program}`tskit` docs
68+
:::{note}
69+
See {ref}`here <sec_intro_downloading_datafiles>` to run the code in this tutorial on
70+
your own computer
7171
:::
7272
::::
7373

7474
A tree sequence is a data structure which describes a set of
7575
evolutionary trees, together with some associated data that specifies, for example,
7676
the location of mutations in the tree sequence.
7777

78-
Below are the most important terms and concepts that you'll encounter in these tutorials,
79-
but first we'll {func}`~tskit.load` a tree sequence from a `.trees` file using the
78+
Below are the most important {ref}`terms and concepts <tskit:sec_data_model_definitions>`
79+
that you'll encounter in these tutorials, but first we'll {func}`~tskit.load` a tree
80+
sequence from a `.trees` file using the
8081
{ref}`tskit:sec_python_api` (which will be used in the rest of this tutorial):
8182

8283
```{code-cell} ipython3

Diff for: intro.md

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

0 commit comments

Comments
 (0)