Skip to content

Working with a Cell Table

A cell table is a per-cell feature table (a CSV or an AnnData object, e.g. from ark-analysis or scanpy) with one row per segmented cell. Loading one turns UELer from an image viewer into a linked single-cell explorer. This page explains how to load a table, the idea of linked selection that ties everything together, and the tools that operate on the current selection.


Loading a Cell Table

Attach a table to an existing viewer with load_cell_table:

import pandas as pd
from ueler import load_cell_table

cell_table = pd.read_csv(cell_table_path)
load_cell_table(viewer, cell_table=cell_table, auto_display=True, after_plugins=True)

See Get Started for the full launch flow. Once the table is loaded, the analytical plugins appear — most in the right-panel accordion (Histogram, Gallery, FlowSOM, Cell Annotation, Mask painter, Go to, Cell sets, Cell tooltip label), and two in the wide footer below the viewer (Scatter plot and Heatmap, which need the full window width). See the User Interface reference.


AnnData Input

An AnnData object works just as well as a DataFrame — pass the object, or point cell_table_path at an .h5ad file:

import anndata as ad
from ueler import load_cell_table

load_cell_table(viewer, cell_table=ad.read_h5ad("cells.h5ad"), auto_display=True)

# equivalent, straight from disk:
load_cell_table(viewer, cell_table_path="cells.h5ad", auto_display=True)

What becomes selectable. AnnData keeps metadata and measurements apart; UELer offers both:

From the AnnData Appears as Where you'll use it
obs columns metadata columns Class:, Subset on:, mask-painter identifier, tooltip labels
X (or a layers entry), named by var_names one column per marker marker/channel pickers, heatmap, FlowSOM features
obsm arrays up to 3 columns wide, e.g. X_umap X_umap1, X_umap2 scatter X: / Y: axes
obs_names an obs_names column cell identity, tooltips

Markers are listed first in the marker pickers, so they aren't buried under label, area, X and Y.

Your obs must still contain the FOV and mask-label columns that link cells to the images — by default fov and label. If yours are named differently, pick the right ones from the Fov key: / Label key: fields, which the setup dialog shows you when the table loads and which also live under Advanced Settings → Data mapping. Both offer your own column names as suggestions, so you normally pick rather than spell — and either one still accepts a name typed by hand.

Two optional arguments:

  • layer="counts" — read adata.layers["counts"] instead of adata.X.
  • obsm_keys=["X_pca"] — also expose an obsm entry that is too wide to be included by default.

Getting your annotations back out

The object you passed in is kept, and anything the plugins add to the table — FlowSOM clusters, heatmap meta-clusters, labels written from the Cell sets plugin — is written back into its obs:

adata = viewer.get_cell_table_adata()
adata.obs.columns          # now includes e.g. 'FlowSOM_cluster'
adata.write_h5ad("cells_annotated.h5ad")

This also works for a CSV/DataFrame table: get_cell_table_adata() then builds an AnnData for you, using the numeric non-key columns as X.


The Idea: Linked Selection

Most single-cell features in UELer revolve around one shared concept — a current selection of cells. Whenever you select cells in one place, every linked view updates:

Scatter / Histogram / Heatmap ──▶  selected cells  ──▶  highlighted in the image
       ▲                      └────────────────────▶  shown in the Gallery
       │
       └── "Follow main viewer"  ◀──  click / ctrl-click / lasso in the image

The link is opt-in in both directions, and each direction has its own checkbox on the plot's Linked plugins tab:

  • Outward (plot → rest of the UI): tick Main viewer to highlight the selected cells' masks in the image, and Cell gallery to populate the gallery. This is what makes "gate on a marker, see those cells light up in the tissue" work.
  • Inward (image → plot): tick Follow main viewer so that cells you pick in the image appear highlighted in the plot instead. Useful in reverse — click an odd-looking cell in the tissue and see where it falls in the marker distribution.

All of these start off, so a freshly loaded viewer shows no linking until you ask for it. See Scatter & Histogram for the full table.

The selection spans the whole cell table, not just the FOV on screen, so switching FOV keeps it: the image re-highlights the selected cells belonging to the FOV you moved to. Zooming and panning keep the highlight as well. Selections made directly in the image — a click or a lasso — are spatial and stay with the FOV they were drawn in.


Selecting Cells

You can create a selection several ways:

  • Click, Ctrl + click, Ctrl + drag in the image — select one cell, add or remove one cell, or draw a lasso loop; a right click on the background unselects everything; Shift + click puts a cell in the active cart. See The User Interface.
  • Lasso Select — the one-shot toggle at the top of the viewer; draw a freehand loop to add every cell with part of its mask inside it, or, if they are all selected already, to unselect them. It searches the masks ticked under Masks; with none shown it selects nothing, and the selection bar beside the toggle says so.
  • Scatter plot / Histogram — brush or gate on marker values. See Scatter & Histogram.
  • Heatmap / FlowSOM — trace a cluster or meta-cluster. See Clustering & Annotation.

The Gallery plugin shows cropped thumbnails of the currently selected cells (5 per row, with internal scrolling). Each tile is labelled <fov>: <mask id>; click a tile to jump the viewer to that cell.

Useful controls:

  • Cutout Size (px): — crop size around each cell (default 150).
  • Max Displayed Cells: — cap the number of thumbnails (default 20; warns above 100). With more cells than that, the Gallery shows a random sample; the same cells always give the same sample.
  • Refresh re-renders the cells shown, for example after changing a channel's colour. It never swaps them for others.
  • Draw new cells shows another sample, preferring cells not shown yet, so you can go through a large selection screen by screen. It is greyed out when every cell fits.
  • Downsample, Mask colour / Outline px, and Use uniform color (when off, painted colors from the Mask painter are shown). Mask colour outlines the centred cell; it starts in the selection colour and follows it until you change it here.

A line above the thumbnails says what is shown and how much of it: "Selection: histogram gate · showing 20 of 35", or "Cart: cool CD8 · showing 24 of 310 · ★ 5" for a cell set.

When the Gallery shows a cell set, it is where you edit it, because that is where its cells are visible. The Cell sets plugin and the Gallery always agree: a change in one shows in the other straight away.

  • ☆ / ★ in a tile's top-left corner stars the cell in the set shown, or takes the star off. Starred tiles always show a gold ★; the other buttons appear when the mouse is over a tile.
  • ✕ in the top-right corner takes the cell out of the set (and its star), and the tile disappears.
  • ★ only shows only the starred cells.
  • + Cart adds the cells on screen to the active cart. It appears while a cart is active.
  • Save shown as set keeps exactly the cells on screen as a set. With a set shown, the new set is a sub-group of it, listed under it in the Cell sets plugin; it records how many cells it was drawn from and which draw it was, so a figure panel can say "these 24 cells, drawn from cart X". Type a name first, or it is called "Gallery sample".

What ★ and ✕ act on depends on what is shown, and the line above the thumbnails says it:

Shown ★ ✕
A cell set or cart stars in that set takes the cell out of the set
A set's ★ cells (Select ★) takes the star off in the set —
A plain selection, with an active cart adds the cell to the cart and stars it there —
A plain selection, no active cart — —
A snapshot starred cells are marked, nothing can change —

A set shown in the Gallery is shown as it is now: cells added to a cart with Shift + click after you selected it are included.


Acting on the Selection

Three plugins consume the current selection directly:

  • Go to — jump and zoom to a specific cell. Pick the FOV: and Cell ID:, set Width (pixel): (the crop width, default 150), and click Go to.
  • Cell sets — write a value into a column for the cells of the current selection, whichever view made it, and keep selections as named, tagged sets. See Cell Sets.
  • Cell tooltip label — tick the cell-table columns you want to appear in the image hover tooltip. It reacts live to each checkbox.

Next Steps