saeyslab / nichenetr

NicheNet: predict active ligand-target links between interacting cells
452 stars 113 forks source link

NicheNet in R #227

Closed cathalgking closed 8 months ago

cathalgking commented 9 months ago

Is it possible to use NicheNet with a SingleCellExperiment (SCE) object? or a python anndata object? The vignettes and notes seem to be focused on use with Seurat objects only (?). I am currently experiencing an issue with a v5 Seurat object and looking for a work-around. Also related to this past listed issue: https://github.com/saeyslab/nichenetr/issues/198

Thanks.

csangara commented 9 months ago

Hi,

There is no built-in support for other object types, but to run the main function of NicheNet (predict_ligand_activities), you essentially need just three vectors:

  1. potential ligands = expressed ligands whose cognate receptors are also expressed
  2. background genes = all genes expressed in the receiver cell type
  3. gene set interest = (generally) differential expressed genes between two conditions

The vignette is meant as a guideline on how to obtain these three vectors, but the workflow is easily adaptable to other objects as well, as seen by how the first vignette only uses a list containing the count matrix and metadata.

If you want to use the same definition of "expressed genes" as we do in the get_expressed_genes function (=get genes that are expressed in at least 10% of the cells), you can implement it yourself with something like this:

# Example data - HNSCC
# Note that the count matrix here is cell x gene, so we transpose it later
hnscc <- readRDS(url("https://zenodo.org/record/3260758/files/hnscc_expression.rds"))

# Get expressed genes of CAFs
pct <- 0.1
hnscc_subset <- t(hnscc$expression[hnscc$sample_info$`non-cancer cell type` == "CAF",])
expressed_genes <- hnscc_subset %>% apply(1, function(x) {
  sum(x > 0)/ncol(hnscc_subset)
}) %>% .[. >= pct] %>% names()

Hope this helps!