JEFworks-Lab / STdeconvolve

Reference-free cell-type deconvolution of multi-cellular spatially resolved transcriptomics data
http://jef.works/STdeconvolve/
102 stars 11 forks source link

Error when using annotateCellTypesGSEA #52

Open d-henness opened 7 months ago

d-henness commented 7 months ago

I'm trying to annotate cell types of visium 10x data using the annotateCellTypesGSEA function. This is a minimal script to reproduce the error

library(STdeconvolve)
library(SpatialExperiment)

se <- SpatialExperiment::read10xVisium(samples = "./116_run",
           type = "sparse",
           data = "filtered")
se

# this is the genes x barcode sparse count matrix
cd <- se@assays@data@listData$counts
pos <- SpatialExperiment::spatialCoords(se)

# change column names to x and y
# for this dataset, we will visualize barcodes using "pxl_col_in_fullres" = "y" coordinates, and "pxl_row_in_fullres" = "x" coordinates
colnames(pos) <- c("y", "x")

counts <- cleanCounts(cd, min.lib.size = 100, min.reads = 10)
corpus <- restrictCorpus(counts, removeAbove=1.0, removeBelow = 0.05, nTopOD = 1000)

#ldas <- fitLDA(t(as.matrix(corpus)), Ks = seq(2, 15, by = 1),
ldas <- fitLDA(t(as.matrix(corpus)), Ks = 10,
               perc.rare.thresh = 0.05,
               plot=TRUE,
               verbose=TRUE)

optLDA <- optimalModel(models = ldas, opt = "min")

results <- getBetaTheta(optLDA, perc.filt = 0.05, betaScale = 1000)
deconProp <- results$theta
deconGexp <- results$beta

gset <- list(
  test_type1 = c("FLG", "FLG2"),
  test_type2 = c("KTR25", "KTR71")
)

celltype_annotations <- annotateCellTypesGSEA(beta = results$beta, gset = gset, qval = 0.05)

The error itself is

initial: [1e+02 - Error in stats::ecdf(as.numeric(rvl$p/s.pm)) :
  'x' must have 1 or more non-missing values
Calls: annotateCellTypesGSEA -> <Anonymous> -> bulk.gsea -> <Anonymous>
Execution halted

I can provide the dataset by email if needed

ChristineHOconnor commented 5 months ago

I am running STdeconvolve 1.3.1 and I get the same error when trying to run annotateCellTypesGSEA. The example commands with the test data in the Annotating Deconvolved Cell Types tutorial work for me, and other STdeconvolve functions work with my dataset.

Umaarasu commented 4 months ago

@ChristineHOconnor and @d-henness ...did you guys fix this issue?

bmill3r commented 3 months ago

Hi @d-henness,

So sorry for the delayed response. My guess is that the number of genes in each of your example test cell types is too small or not well represented in your dataset. I would be happy to take a closer look if you are able to provide your dataset and cell type markers that are causing this error. I admit though that I am in a new position and my time is limited so my response will likely take some time.

Hope this helps and sorry again, Brendan