Skip to content

Linked views

This notebook is for building something interactive on top of the widgets: an alignment, a distance matrix and a tree that follow each other, and Python code that reacts to what you do in them. Start with the example notebook for everyday use.

Open the interactive notebook View on GitHub

To run it yourself, clone the repository and open packages/python/examples/linked_views.ipynb.

Terminal window
pip install react-bio-viz nj_py jupyterlab
jupyter lab packages/python/examples/linked_views.ipynb

The alignment and the matrix share a row_order, and the tree’s leaf_order drives both. Drag a node in the tree, and the rows follow.

from ipywidgets import jsdlink, jslink
jslink((msa, "row_order"), (matrix, "row_order"))
jsdlink((phylo, "leaf_order"), (msa, "row_order"))

These run in the browser, which is why they work in the exported page. With a live kernel, traitlets.link and traitlets.dlink do the same in Python.

The notebook reads msa.selection after you select something, prints each new selection into an Output widget, and drives the view from Python:

msa.viewport = {**msa.viewport, "x0": 100, "x1": 160}
msa.options = {**msa.options, "colorStyle": "AA Zappo"}
msa.selection = {"rows": [], "columns": list(range(120, 130))}

Clicks in the tree report the node, its leaves and its descendants to a Python callback. Rename, row-removal and column-removal callbacks apply each edit to msa.msa. See Events for all of them.