Skip to content

Example notebook

The tour notebook looks at a 24-sequence protein alignment, computes distances and a neighbour-joining tree with nj.rs, and shows a gene model. The interactive version is the notebook exported to HTML: its widgets are the real components, with no Python running behind them.

Open the interactive notebook View on GitHub

To run it yourself, clone the repository and open packages/python/examples/tour.ipynb. Its data files sit next to it in data/.

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

read_fasta loads the records and MSA shows them, here with conservation and logo tracks. Pan, zoom, select and drag labels as in the live examples.

records = read_fasta("data/aux_iaa.fasta")
MSA(msa=records, options={"tracks": ["conservation", "logo"]})
The MSA widget, with conservation and sequence-logo tracks

nj_py takes the same records as MSA. Its distances, under the LG model for proteins, go into a DistanceMatrix.

distances = distance_matrix(records, substitution_model="Lg")
DistanceMatrix(labels=distances["names"], matrix=distances["matrix"])
The DistanceMatrix widget showing pairwise LG distances

nj builds a neighbour-joining tree with bootstrap support, and parse_newick turns its Newick output into the tree PhyloTree draws. Drag a node to rotate the tree, or past the top or bottom to reroot it.

result = nj(records, substitution_model="Lg", n_bootstrap_samples=100)
tree = parse_newick(result["newick"])
PhyloTree(tree=tree, interactive=True)

nj.rs reports support as a count of replicates. The notebook also scales it to the 0–1 values PhyloTree shades branches by.

The PhyloTree widget with a neighbour-joining tree

A GeneModel shows the transcripts, exons and CDSs of a gene.

The GeneModel widget

jupyter nbconvert --to html --execute tour.ipynb exports the notebook with its widgets still interactive.

To link widgets together and respond to them from Python, continue with Linked views.