Skip to content

Commit 64b1ece

Browse files
committed
Add visual example
1 parent ce0d8ca commit 64b1ece

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/numba.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,56 @@ print(f"Edges descended from node {test_node}: {descendant_edge_ids[:10]}...")
418418
print(f"Total descendant edges: {np.sum(edge_select)}")
419419
```
420420

421+
```{code-cell} python
422+
:tags: [hide-cell]
423+
# Create a simple hard-coded example for consistent visualization
424+
tables = tskit.TableCollection(sequence_length=10.0)
425+
426+
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0) # node 0
427+
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0) # node 1
428+
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0) # node 2
429+
tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0) # node 3
430+
tables.nodes.add_row(flags=0, time=1) # node 4
431+
tables.nodes.add_row(flags=0, time=2) # node 5
432+
tables.nodes.add_row(flags=0, time=3) # node 6
433+
434+
tables.edges.add_row(left=0, right=5, parent=4, child=0)
435+
tables.edges.add_row(left=0, right=10, parent=4, child=1)
436+
tables.edges.add_row(left=5, right=10, parent=5, child=0)
437+
tables.edges.add_row(left=0, right=10, parent=5, child=2)
438+
tables.edges.add_row(left=0, right=7, parent=6, child=4)
439+
tables.edges.add_row(left=0, right=10, parent=6, child=5)
440+
tables.edges.add_row(left=7, right=10, parent=6, child=3)
441+
442+
tables.sort()
443+
ts_simple = tables.tree_sequence()
444+
```
445+
446+
A tree sequence is easily made from the descendant edges array:
447+
448+
```{code-cell} python
449+
numba_ts_simple = tskit_numba.jitwrap(ts_simple)
450+
node = 5
451+
E = descendant_edges(numba_ts_simple, node)
452+
tables_sub = ts_simple.dump_tables()
453+
tables_sub.edges.replace_with(tables_sub.edges[E])
454+
ts_sub = tables_sub.tree_sequence()
455+
```
456+
457+
As an example, lets visualise the selection of a sub-ARG. Here is the full ARG
458+
with a highlighted node:
459+
460+
```{code-cell} python
461+
css_style = f".node.n{node} > .sym {{ fill: #c41e3a; }}"
462+
ts_simple.draw_svg(size=(400, 200), node_labels={}, y_axis=True, style=css_style)
463+
```
464+
465+
And the sub-ARG from that node:
466+
467+
```{code-cell} python
468+
ts_sub.draw_svg(size=(400, 200), node_labels={}, y_axis=True, style=css_style)
469+
```
470+
421471
In the other direction, we can similarly find the sub-ARG that is ancestral to a given node:
422472

423473
```{code-cell} python

0 commit comments

Comments
 (0)