, query, field, n_neighbors=30, use_rep=None, key_added=None, **kwargs)[source]

Transfer discrete labels from reference dataset to query dataset

  • ref (AnnData) – Reference dataset

  • query (AnnData) – Query dataset

  • field (str) – Field to be transferred in ref.obs (must be discrete)

  • n_neighbors (int) – Number of nearest neighbors used for label transfer

  • use_rep (typing.Optional[str]) – Data representation based on which to find nearest neighbors, by default uses {ref, query}.X.

  • key_added (typing.Optional[str]) – New query.obs key added for the transfered labels, by default the same as field.

  • **kwargs – Additional keyword arguments are passed to sklearn.neighbors.NearestNeighbors

Return type:



First, nearest neighbors between reference and query cells are searched and weighted by Jaccard index of SNN (shared nearest neighbors). The Jaccard indices are then normalized per query cell to form a mapping matrix. To obtain predictions for query cells, we multiply the above mapping matrix to the one-hot matrix of reference labels. The category with the highest score is taken as the final prediction, while its score is interpreted as transfer confidence (stored as “{key_added}_confidence” in query.obs).