/use-milume:use-milumefrom use-milume
Provides the notebook API for milume 2.0+ spatial omics visualization: open LandmarksWidget with milume.peek, recolor by gene or annotation, query cells in drawn regions, match plot colors, and convert landmarks to/from GeoDataFrame/SpatialData.
Ships in use-milume. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Notebook API for milume 2.0+. Only the entries listed under
Public API are supported; every other synced trait is internal
and can change without notice.
The examples assume an AnnData adata with obsm["spatial"], an
obs["cell_type"] column and a gene APOB in var_names; the Inspect
example uses a SpatialData sdata with a 3D image. CI runs every
python block on this page in order against a small fixture
(tests/test_use_milume_skill.py).
import milume
w = milume.peek(adata, color="cell_type")
w
milume.peek(sdata) takes a SpatialData too: the table, per-slice cell polygons
and 3D image are inferred (shapes= / image= to override). color= takes the
same keys as w.color.
w.color = "APOB" # a gene: expression ramp
w.color = "cell_type" # an obs column: categorical palette
w.color takes an adata.obs column (categorical or numeric), a gene in
var_names, a list of genes (blend), or an obsm embedding key. A column
added to adata.obs after the widget was built works.milume.ColorKeyError (a KeyError). A gene the
widget's catalog doesn't include (genes= left it out), or a category column with more
than 128 levels, raises milume.ColorValueError (a ValueError). Nothing
changes when it raises.Selections are drawn in the browser; each has an id in w.selections. You
can also write one from Python:
w.selections = [
{"id": "crypt", "type": "rectangle", "cx": 50.0, "cy": 50.0,
"width": 40.0, "height": 40.0, "angle": 0.0},
]
cells = w.get_obs_names("crypt") # pd.Index of obs_names
adata.obs["in_crypt"] = adata.obs_names.isin(cells)
focused = w.get_obs_names("focus") # the focused selection or category groups
get_obs_names(region) needs a selection id or "focus". An unknown id
raises KeyError. A hidden selection still returns its cells.adata.obs_names; there is no "all".obs_names, never by position.palette = w.category_colors("cell_type") # {label: "#rrggbb"}, as the map draws it
Pass it to scanpy / matplotlib (palette=) so plots match the widget.
from milume import geodataframe_to_landmarks, landmarks_to_geodataframe
w.landmarks = [{"id": "crypt-axis", "type": "line", "vertices": [[10.0, 10.0], [90.0, 90.0]]}]
gdf = landmarks_to_geodataframe(w.landmarks)
w.landmarks = geodataframe_to_landmarks(gdf)
vertices column; geometry is a GIS proxy.
Round-trip through these two functions, not through geometry.sdata["landmarks"] = gdf
yourself.geopandas and shapely.The Inspect cube needs a 3D image, so build the widget from SpatialData:
v = milume.peek(sdata)
v.inspect_open = True # no window placed yet: opens at the volume centre
v.inspect_open = False # closes the cube and exits Inspect
v.inspect_cx, v.inspect_cy = 120.0, 140.0 # window centre, in spatial units (µm)
v.inspect_open = True # the cube opens there, no click needed
v.inspect_cx = 150.0 # moves the window and the open cube
v.volume_cut = [*v.volume_cut[:4], 0.0, 32.0] # keep z between 0 and 32 µm
v.inspect_open = False # closes the cube and exits Inspect; the window stays put
inspect_open = True with no
window placed (inspect_cx/inspect_cy still None) opens the cube there.
Without a 3D image it raises ValueError.True switches the widget to Inspect; False closes the cube and exits
Inspect, like the Exit button. In the browser, one Esc (or Exit) closes the
cube and leaves Inspect, and sets inspect_open back to False; Python and
the widget never disagree.volume_cut is [x0, x1, y0, y1, z0, z1] in µm. The browser writes it when
a cut slider is released; X and Y are clipped to the window when drawn.v.volume describes the 3D image ({} without one). Read it, don't set it.Optional (pip install squidpy scanpy leidenalg). Full walkthrough with screenshots:
docs/how-to/recipes/.
Contributors adding a recipe: Writing a recipe (dev doc, not in the public nav).
Neighborhood niches on a selection mask, then recolour by the column Squidpy
writes (nhood_niche_res=<resolution>, e.g. nhood_niche_res=0.5 when
resolutions=0.5):
import pandas as pd
import scanpy as sc
import squidpy as sq
w_niche = milume.peek(adata, color="cell_type")
w_niche.selections = [
{"id": "patch", "type": "rectangle", "cx": 50.0, "cy": 50.0,
"width": 70.0, "height": 70.0, "angle": 0.0},
]
mask = pd.Series(adata.obs_names.isin(w_niche.get_obs_names("patch")), index=adata.obs_names)
sc.pp.neighbors(adata)
sq.gr.spatial_neighbors_knn(adata, n_neighs=6)
sq.gr.calculate_niche(
adata,
flavor="neighborhood",
groups="cell_type",
n_neighbors=6,
resolutions=0.5,
mask=mask,
)
w_niche.color = "nhood_niche_res=0.5"
Top Moran's I gene on the packed genes:
import scanpy as sc
import squidpy as sq
w_moran = milume.peek(adata, color="cell_type", genes=["APOB", "Lgr5", "Muc2"])
sc.pp.neighbors(adata)
sq.gr.spatial_neighbors_knn(adata, n_neighs=6)
sq.gr.spatial_autocorr(adata, mode="moran")
w_moran.color = adata.uns["moranI"]["I"].idxmax()
colon_a2) and Pyxa (small,
xsmall, mouse brain) are different tissues, and their obs_names and
label ids do not correspond._color_state, _look, _category_columns, …)
to recolour; use w.color. active_category and active_genes are
deprecated and derived from color.| Name | Kind | What it is |
|---|---|---|
w.color | trait | obs column, gene, gene list (blend), or obsm embedding key; assign to recolour (raises ColorKeyError / ColorValueError). |
w.selections | trait | Drawn selections as dicts with id, name, geometry and point indices. |
w.landmarks | trait | Drawn landmarks (points, lines, splines, shapes) as dicts. |
w.pseudospace | trait | Per-cell position along the ordered pseudospace group, one float per adata.obs_names row (pd.Series(w.pseudospace, index=adata.obs_names)). None when grouping is off or the group has fewer than 2 landmarks. Outside cells are NaN. The browser writes it. Read it, don't set it. |
w.selected_kind | trait | Kind of the focused item: selection, landmark, type, or empty. |
w.selected_index | trait | Index of the focused item within its kind, or -1. |
w.selected_type_indices | trait | Focused category label indices when selected_kind is type. |
w.inspect_cx | trait | Inspect window centre x in spatial units, or None before placement; set it to move the window and the open cube. |
w.inspect_cy | trait | Inspect window centre y in spatial units, or None before placement; set it to move the window and the open cube. |
w.inspect_size_um | trait | Inspect window side length in µm. |
w.inspect_open | trait | Whether the Inspect cube is open; True opens it at inspect_cx/cy, or at the volume centre when no window is placed; False closes it and exits Inspect. ValueError without a 3D image. |
w.volume | trait | The 3D image behind the Inspect cube (image path, cell polygons path and size, voxel size, origin, contrast); {} without one. Read it, don't set it. |
w.volume_cut | trait | Cube cut box [x0, x1, y0, y1, z0, z1] in µm; the browser writes it on slider release, assign it to cut from Python. |
w.active_category | trait | Deprecated: derived from color; removed in 3.0. |
w.active_genes | trait | Deprecated: derived from color; removed in 3.0. |
w.category_colors() | method | Label to hex colour map of a categorical column as drawn. |
w.clear_selections() | method | Remove every selection. |
w.clear_landmarks() | method | Remove every landmark. |
w.clear() | method | Remove all selections and landmarks. |
w.select_type() | method | Focus one category group of the active column. |
w.get_obs_names() | method | pd.Index of obs_names in a selection id or 'focus'; KeyError on unknown ids. |
w.set_points() | method | Move the scatter points to new x/y; colour is set with color. |
w.set_expression() | method | Replace the gene catalogue from a table. |
w.set_render_mode() | method | Switch between points and raster bins. |
w.set_raster_basis() | method | Pick the raster aggregation basis: genes, embedding or composition. |
w.clear_raster_query() | method | Clear the pinned raster similarity query. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub ckmah/milume --plugin use-milumeOther plugins' skills for the same job