classify
classify ¶
classify(
data,
pos=None,
neg=None,
classifyLabel="passed_classify",
failedLabel="failed_classify",
phenotype=None,
subclassifyPhenotype=None,
threshold=0.5,
collapseFailed=True,
label="classify",
showPhenotypeLabel=False,
verbose=True,
outputDir=None,
sdataTable=None,
)
Label cells by positive and negative marker thresholds.
A cell passes when it is at or above threshold for every marker in pos and
below it for every marker in neg. Passing cells get classifyLabel; the rest
get failedLabel, or keep their existing phenotype when collapseFailed=True.
Marker values are read from .raw.X when it exists, otherwise .X, so run
sp.pp.rescale first if you want 0.5 to mean
positive.
phenotype plus subclassifyPhenotype restricts the rule to cells that already
carry particular labels — the way to split an existing population without
touching the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
pos
|
str | list
|
Markers a cell must be positive for. |
None
|
neg
|
str | list
|
Markers a cell must be negative for. |
None
|
classifyLabel
|
str
|
Label given to cells that pass. |
'passed_classify'
|
failedLabel
|
str
|
Label given to cells that fail, unless |
'failed_classify'
|
phenotype
|
str
|
Column in |
None
|
subclassifyPhenotype
|
str | list
|
Apply the rule only to cells already labelled one of these in
|
None
|
threshold
|
float
|
The value at which a marker counts as positive. |
0.5
|
collapseFailed
|
bool
|
Give failing cells their existing |
True
|
label
|
str
|
Column in |
'classify'
|
showPhenotypeLabel
|
bool
|
Label passing cells |
False
|
verbose
|
bool
|
Print progress messages. |
True
|
outputDir
|
str
|
Directory to write the updated object to. With |
None
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
adata |
AnnData | SpatialData | None
|
The updated object with |
Example
# Pull out one population.
adata = sp.tl.classify(
adata, pos=["CD3", "CD8"], neg=["FOXP3"],
classifyLabel="CD8 T cell", label="cd8",
)
# Split an existing phenotype without disturbing the others.
adata = sp.tl.classify(
adata,
pos=["PD1"],
phenotype="phenotype",
subclassifyPhenotype=["Treg"],
classifyLabel="PD1+",
collapseFailed=True,
showPhenotypeLabel=True,
label="phenotype_refined",
)