Select, mask and delete¶
A selection is the set of cells you are working with right now: drawn with a lasso, picked by category, or chosen by an expression threshold. From a selection you can label cells, set comparison groups, narrow what analyses see (the mask) or remove cells from the dataset. This page covers each of those and how they differ.
Where to find it
Select in the toolbar (its arrow picks Lasso or Polygon). The selection count with Invert and Clear appears in the toolbar while cells are selected; the actions on a selection are at the bottom of the Cells panel.
Make a selection¶
Lasso and polygon¶
- Click Select. Use its arrow to choose the tool:
- Lasso: click and drag to draw a freehand loop.
- Polygon: click to add vertices, double-click to close.
- Draw around the cells. Hold Shift while drawing to add to the current selection instead of replacing it.
- Press Esc to leave selection mode.
Selected cells are drawn in yellow and larger than the rest. In the 3D view, Select draws a freehand loop on the screen and takes every cell whose projection falls inside it, including cells hidden behind others.
The toolbar shows the count with two buttons:
- Invert selects every cell that is not selected now, and deselects the rest.
- Clear empties the selection.
The lasso does not skip masked cells
A loop takes every cell inside it, including masked cells drawn in gray. Cells with no coordinates in the current embedding (outside a subset's UMAP, for example) are never selected.
By category¶
In the Cells panel's Categorical tab, expand a column:
- Click a category's name to select its cells (replacing the selection).
- Tick a category's checkbox to add its cells to the selection; untick to remove them. Checkboxes work within one column at a time.
By expression threshold¶
You can select cells by a threshold on a gene or a gene-set score, with a histogram to set the cutoff instead of judging colors by eye.
- In the Genes panel, open the ⋯ menu on a gene or gene-set row and choose Select cells…. The plot switches to that gene or set's coloring (a set is scored as Display says; see Color cells) and the modal shows a histogram of the values.
- Choose the Threshold mode: Above, Below or Between, and drag the red cutoff line or lines, or type the value. The match counter updates as you drag.
- Choose the Action:
- Update selection with Replace, Add (to the current selection) or Intersect (keep only selected cells that also pass).
- Label cells writes a new categorical
.obscolumn. Give it an Annotation name; under More options set the High label and Low label (defaulthighandlow) and the Context: the Current selection (the default), in which case cells outside it are labeledunassigned, or All cells.
- Click Apply.
After Label cells, Open Diff Exp ▸ opens differential expression with the two new groups already chosen. A common use is finding the genes that differ between expressing and non-expressing cells within one region: lasso the region, ⋯ → Select cells… on a gene, set the threshold, Label cells with the selection as context, then Open Diff Exp ▸.
Downsample¶
Downsample… (beside the selection count in the Cells panel, or Analyze → Cells → Downsample) replaces the selection with a random sample of cells.
| Field | What it does |
|---|---|
| Sample from | The current selection, the active (unmasked) cells, or all cells. Defaults to the selection when there is one. |
| Balance by | Optional label column. The sample then holds the same number of cells from each of the column's labels, counted within the pool. The line below the field gives the number of labels and the smallest and largest. Cells without a label are left out. |
| Keep / Keep per label | A number of cells or a % of pool. With Balance by set: the number of cells per label; blank takes the smallest label's count, which keeps every label and makes them equal. |
| Labels with fewer cells | With Balance by and a number above the smallest label: such labels are left out, so the groups in the result are equal, or are kept whole, which caps the large labels and leaves the small ones as they are. |
| Seed | An integer. Blank draws one at random; the seed used is reported, and the same seed gives the same cells. |
To balance a dataset across cell types or samples, pick the column under Balance by, leave the number blank, then Invert and Mask or Delete, or Set Active on the sample itself. The line beside the number says what the selection will hold before you run, for example 4 groups × 100 = 400 cells; 1 group under 100 left out. A target that would select every cell of the pool is refused, as it is without a column.
The sample is an ordinary selection. To thin one dominant cluster and leave the others intact: lasso the cluster, downsample it, Invert, then Delete or Mask (inverting selects every other cell too, so check what is selected before deleting).
What you can do with a selection¶
The bottom of the Cells panel shows the selection count and these actions.
| Button | What it does |
|---|---|
| Set as Group 1, Set as Group 2 | Make the selection a comparison group (below). |
| Set Active | Make the selected cells the only active cells (the mask). |
| Add to Active | Add the selected cells to the active cells. |
| Mask | Remove the selected cells from the active cells. |
| Delete | Remove the selected cells from the dataset. Click again to confirm. |
| Label with annotation… | Pick a categorical column, type a label and click Apply to write that label for the selected cells. See Labels and annotations. |
The cell mask¶
The mask is the set of active cells. Masked cells stay in the dataset and in every .obs column, but analyses that honor the mask leave them out: for example marker genes compare each group with the rest of the active cells, and HVG, PCA, Neighbors, UMAP and Leiden run on the active cells only.
While a mask is set, a Cell Mask bar in the Cells panel shows how many cells are active and has:
- Show masked cells: on (default) draws masked cells small and gray at 30% opacity; off hides them.
- Save as subset, with a name field: turns the mask into a named subset, so HVG, PCA, Neighbors, UMAP and Leiden run on it write to the subset's own keys instead of over the dataset's. If you start one of these on an unsaved mask, the Analyze modal asks for a subset name first.
- Reset Mask: makes every cell active again. If the current embedding has no coordinates for some cells (a subset's UMAP), it also switches back to an embedding that shows them all.
An unsaved mask lives only in the browser: a reload loses it. A saved subset can be made the mask again at any time with Activate.
Mask or delete?
Mask is reversible and keeps the cells in the file. Delete removes the cells from the dataset in the backend, with every row of .obs, .obsm and the expression matrices; Skopia has no undo for it. The .h5ad on disk is not changed until you save over it, so reopening that file brings the cells back, at the cost of everything else done since it was loaded. Prefer masking, or a named subset, when you may want the cells later.
Comparison groups¶
Set as Group 1 and Set as Group 2 store the current selection as one side of a comparison. A Comparison bar then shows each group's cell count and offers:
- Compare: runs differential expression between the two groups and clears the selection.
- Options: opens the differential expression modal with its settings.
- Clear: forgets both groups.
The method and its parameters are described in Differential expression and markers.
Related¶
- Labels and annotations
- Named subsets and the subset tree
- Differential expression and markers
- Display settings and highlights: mark a selection in color without selecting it