kBET icon indicating copy to clipboard operation
kBET copied to clipboard

Using kBET with AnnData object

Open LeonHafner opened this issue 3 years ago • 1 comments

Hi together, I would like to use the R version of kBET on an AnnData object (or rather the neighborhood graph stored in this anndata object) for the comparison of two batch correction methods. I don't want to use scib, since that is currently not working for me (gives me only 'nan' for the kBET metric). Which part of the anndata object should I use as input for kBET so that the batch correction stored in the neighbor graph is considered (connectivities or distances)? Can I pass these matrices to the df parameter in kBET or rather to the knn parameter?

Thanks for the help!

LeonHafner avatar Aug 30 '22 20:08 LeonHafner

Hi @LeonHafner,

thank you for your request. I am not quite sure what kind of structure you would like to use to compute kBET, though.

I assume that you want to use the knn-graph in anndata for kBET. You can use the anndata.obsp["connectivities"] for the knn-graph. Please note that you only need the indices of the cells that are nearest neighbours for each cell (i.e. that knn graph is a matrix where the i'th row contains the indices of the k-nearest neighbours if the i'th cell; add +1 to account for 1-based indexing in R). E.g. (not tested, taken from diffusion_nn in scIB)

import numpy as np
T = adata.obsp["connectivities"]
k_indices = np.argpartition(T.A, -k, axis=1)[:, -k:]

Then, the input to kBET should be

  • a data matrix (that is required, though ignored when you set knn = knn)
  • a batch covariate
  • optional: the knn-graph as created above.

I hope that helps you. Please let me know if anything is unclear.

mbuttner avatar Sep 03 '22 16:09 mbuttner

Closed as no reply.

mbuttner avatar Nov 10 '22 15:11 mbuttner