monkeybread.util.subset_cells
- monkeybread.util.subset_cells(adata, by, subset, label_obs=None, label=None)
Subsets cells based on gene expression and optionally labels them.
- Parameters
adata (
AnnData
) – Annotated data matrix.by (
Union
[Literal
[‘gene’],Literal
[‘spatial’]]) – Either'gene'
or'spatial'
. Indicates whethersubset
refers to gene counts in each cell or x and y locations of each cell.subset (
Union
[Tuple
[str
,str
,float
],List
[Tuple
[str
,str
,float
]]]) – Either a single condition or a list of conditions. Each condition consists of a length-3 tuple where the first element is either a gene or x/y, the second element is one of gt, gte, lt, lte, or eq, and the third element is a number.label_obs (
Optional
[str
] (default:None
)) – A categorical column inadata.obs
to add a label to if it passes the subset conditions. Creates the column if it does not exist, and sets other values to “Unknown”. If the column exists, existing labels other than “Unknown” will take precedence.label (
Optional
[str
] (default:None
)) – The label to assign to cells passing the subset conditions inadata.obs[label_obs]
.
- Return type
- Returns
A copy of
adata
containing only cells matching the subset conditions.