rename
rename ¶
rename(
data,
rename,
fromColumn="phenotype",
toColumn="phenotype_renamed",
verbose=True,
outputDir=None,
sdataTable=None,
)
Relabel or merge the categories of an obs column.
Writes a new column rather than editing in place, so the original labels stay available. That matters when you want to plot broad classes and fine phenotypes side by side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
rename
|
(dict, required)
|
The mapping, keyed by the new label:
|
required |
fromColumn
|
str
|
Column in |
'phenotype'
|
toColumn
|
str
|
Column in |
'phenotype_renamed'
|
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
# Merge fine phenotypes into broad classes.
adata = sp.tl.rename(
adata,
rename={"Tumour": "ECAD+",
"Immune": ["Treg", "NK cells", "Dendritic cells"]},
fromColumn="phenotype",
toColumn="broad",
)
# Give cluster numbers names.
adata = sp.tl.rename(
adata,
rename={"Tumour core": "0", "Stroma": "1", "Immune infiltrate": "2"},
fromColumn="kmeans",
toColumn="neighbourhood",
)