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 GitHubTo run it yourself, clone the repository and open packages/python/examples/linked_views.ipynb.
pip install react-bio-viz nj_py jupyterlabjupyter lab packages/python/examples/linked_views.ipynbLink views
Section titled “Link views”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.
Read, observe and drive state
Section titled “Read, observe and drive state”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))}Respond to clicks and edits
Section titled “Respond to clicks and edits”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.