Skip to content

Commit 0e38fc3

Browse files
committed
note on debugging
1 parent 5aeadfa commit 0e38fc3

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

docs/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ parts:
2727
- caption: For developers
2828
chapters:
2929
- file: development
30+
- file: debugging
3031
- file: changelogs
3132
- caption: Miscellaneous
3233
chapters:

docs/debugging.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
format_version: 0.12
7+
jupytext_version: 1.9.1
8+
kernelspec:
9+
display_name: Python 3
10+
language: python
11+
name: python3
12+
---
13+
14+
```{currentmodule} tskit
15+
```
16+
17+
(sec_debugging)=
18+
19+
# Debugging non-compliant tree sequences
20+
21+
If you're working on an application that writes out tree sequences
22+
(or more properly, the underlying table collections),
23+
you may find yourself in the situation where you're writing out files
24+
that tskit cannot read because of violations of the {ref}`sec_data_model`.
25+
How to see what's going on?
26+
27+
First, try loading the {class}`.TableCollection` directly (skipping
28+
the convert-to-tree-sequence step that involves additional validation).
29+
This will work if you have errors like a mutation that references a
30+
non-extant node, for instance.
31+
To do this, you simply run:
32+
```{code-cell} python
33+
import tskit
34+
tables = tskit.TableCollection.load("data/basic_tree_seq.trees")
35+
print(tables)
36+
```
37+
Then, the tables can be inspected.
38+
39+
Sometimes the error makes it so the tables cannot even be loaded
40+
as a {class}`.TableCollection`: for instance, if something went wrong
41+
with the {ref}`ragged columns<sec_encoding_ragged_columns>`.
42+
Under the hood, data is stored on disk
43+
with [kastore](https://github.com/tskit-dev/kastore),
44+
so we can use kastore directly:
45+
```{code-cell} python
46+
import kastore
47+
ka = kastore.load("data/basic_tree_seq.trees")
48+
print(ka)
49+
```
50+
The kastore has (by design!) very minimal functionality:
51+
we can ask what *keys* it has, and retrieve the associated values.
52+
So, this one has these keys:
53+
```{code-cell} python
54+
list(ka.keys())
55+
```
56+
The names are self-explanatory.
57+
For instance, we can look at the array of child nodes associated with each edge:
58+
```{code-cell} python
59+
ka.get("edges/child")
60+
```
61+
62+
Good luck!

0 commit comments

Comments
 (0)