grassp.tl.knn_annotation#
- knn_annotation(data, obs_ann_col, key_added='consensus_graph_annotation', exclude_category=None, inplace=True)[source]#
Propagate categorical annotations along the k-NN graph.
For each observation the function inspects its neighbourhood in
adata.obsp['distances']
(generated byscanpy.pp.neighbors()
) and assigns the majority category found inobs_ann_col
. Ties are broken arbitrarily usingpandas.DataFrame.mode()
.- Parameters:
- data
AnnData
anndata.AnnData
with a populated neighbour graph (distances or connectivities).- obs_ann_col
str
Observation column containing the source annotations to be propagated.
- key_added
str
(default:'consensus_graph_annotation'
) Name of the new column that will hold the consensus annotation (default
"consensus_graph_annotation"
).- exclude_category
Union
[str
,List
[str
],None
] (default:None
) One or multiple category labels that should be ignored when computing the neighbourhood majority (useful for unknown / NA categories).
- inplace
bool
(default:True
) If
True
(default) modify data in place. Otherwise return a copy with the additional column.
- data
- Return type:
- Returns:
Modified object when
inplace
isFalse
with a new column in .obs[key_added].