edward130603 / BayesSpace

Bayesian model for clustering and enhancing the resolution of spatial gene expression experiments.
http://edward130603.github.io/BayesSpace
Other
96 stars 20 forks source link

Getting gene expression proportion #97

Open rue1996 opened 1 year ago

rue1996 commented 1 year ago

Hi

I have a question, is there a way to transform the enhanced gene expression of each spot to a percentage?

edward130603 commented 1 year ago

Sorry we don't have a function to do this. You can probably write some dplyr code by making a dataframe and then using group_by on the spot index and then mutate (divide by sum) to get this for each gene. Here is a minimal example:

library(BayesSpace)
library(tibble)
library(dplyr)
sce = BayesSpace::exampleSCE()
sce.e = spatialEnhance(sce, q = 3, nrep = 1000, burn.in = 100)
sce.e = enhanceFeatures(sce.e, sce.ref = sce)
data1 = as_tibble(cbind(colData(sce.e), t(logcounts(sce.e))))
gene.names = rownames(sce)
data1 %>%
  group_by(spot.idx) %>%
  mutate(across(any_of(gene.names),~./(sum(.)))) ->
  props