Use selections downstream¶
Carry lasso, rectangle, and inspect selections into pandas, Scanpy, or other Python analysis.
Goal¶
Turn the cells inside a map selection into an observation subset or a boolean column on adata.obs.
Steps¶
- Open milume on AnnData with spatial coordinates (ileum demo):
-
Draw a selection in the browser (Select regions). Each edit updates
w.selections. -
Read the latest selection id and the cell names it covers:
- Join to observations by name (not row index):
- Run downstream code on the subset or the flag. Example summary table:
import pandas as pd
summary = pd.DataFrame(
{"cell_type": adata.obs.loc[hits, "cell_type"].value_counts()}
)
Use w.get_obs_names("focus") when the focused selection in the UI is the one you want (Methods).
Result¶
hits and adata_sel (or adata.obs["in_selection"]) stay aligned with the map. Re-run steps 3–5 after you change selections in the widget.
Landmarks (w.landmarks) are durable geometry; selections are analysis regions. Traitlets and edge cases are in the LandmarksWidget API.