msaview-widget

A notebook widget for react-msaview: a multiple sequence alignment beside its phylogenetic tree, in JupyterLab, Jupyter Notebook, VS Code and any other host anywidget supports. The distribution is msaview-widget and the import is msaview, because the name msaview on PyPI belongs to another project.

The globin alignment and tree

Install

The wheel ships the widget’s JavaScript, which a checkout builds first:

pnpm install
pnpm --filter msaview-widget build
pip install packages/python

Quick start

from msaview import MSAView

view = MSAView(msa="globin.aln", tree="globin.nh", hide_header=True)
view

Setting a trait updates the widget in place and keeps its scroll and zoom:

view.color_scheme = "clustal"
view.highlights = [{"row": "Human_beta", "start": 64, "end": 64, "label": "distal His"}]

Traits

The traits are the MSAViewer props in USAGE.md, in snake case. highlights and column_tracks take the JSON shapes in docs/layers.md.

TraitValue
msa, tree, gffdocument text or a file path
msa_url, tree_url, gff_urla URL the viewer fetches
color_schemea scheme name, such as "clustal" or "nucleotide"
heightpixels
col_width, row_heightpixels per column and per row
highlightslist of {start, end}, {row, start, end} or {rows}
cladeslist of {mrca or range, tips, mark} clades of the tree to mark
highlight_columnscolumns (0-based) under a persistent overlay
residue_mappingswhich structure residue each row residue is
column_trackslist of bar, text or arc tracks
row_dataextra fields per row name, such as a lineage or a host
encodings{channel, field, scale}: tipLabel, rowTint, branch, featureFill, featureLabel
row_panelsstrip and features panels drawn beside the tree
relative_toa row name; other rows draw as their differences from it
region{start, end} columns or {row, start, end} residues
allowed_gappynesshide columns at least this percent gaps (default 100)
draw_tree, show_branch_lenbooleans, default True
tree_area_widthpixels; auto_tree_area_width sizes it to the labels
residue_encoding"fill" (default) paints the cell; "color" paints the letter
hide_headerboolean, default False
theme"auto" (default), "light", "dark" or MUI theme options

theme="auto" follows JupyterLab’s and Notebook 7’s data-jp-theme-light attribute, then VS Code’s data-vscode-theme-kind, then the browser’s prefers-color-scheme, and switches when the host does.

The widget sets two traits from the browser:

Both are 1-based. column counts every column of the alignment, and residue counts the clicked row’s own letters. The widget keeps hover in the browser, since a comm message per pointer move would flood the kernel.

view.observe(lambda change: print(change["new"]), "clicked")

Python inputs

The package converts only what JSON cannot carry:

Examples

examples/01_quickstart.ipynb opens the globin alignment from packages/examples/data. examples/02_entropy_and_clicks.ipynb draws per-column Shannon entropy as a bar track, highlights the columns above an ipywidgets slider’s threshold, and prints the letter each row has at a clicked column.

Entropy track and highlighted columns
Influenza drift in a notebook is the long version: 25 H3N2 vaccine strains from NCBI, aligned, with a per-column count of how often each column changed and a band on each antigenic site.

scripts/run_examples.py executes both notebooks in a kernel, and scripts/screenshot_examples.mjs renders the widgets they built into docs/media:

pip install -e "packages/python[examples]"
python packages/python/scripts/run_examples.py

Development

pip install -e "packages/python[dev]"
pytest packages/python/tests
pnpm vitest run packages/python