drisso / zinbwave

Clone of the Bioconductor repository for the zinbwave package, see https://bioconductor.org/packages/zinbwave
43 stars 10 forks source link

Sample 3 has only 0 counts! #70

Open ambertrujillo opened 2 years ago

ambertrujillo commented 2 years ago

Hello there and thank you in advance for your help!

I am running zinbwave on a single cell dataset with many 0s. The following is my code and error:

Cluster9 <- SingleCellExperiment(list(counts=GetAssayData(object = Aotus.Cluster9, slot = "counts")))
Cluster9

#class: SummarizedExperiment 
#dim: 21456 119 
#metadata(0):
#assays(1): counts
#rownames(21456): Aotus-ENSANAG00000002703 Aotus-LMNB1 ...
#  Aotus-ENSANAG00000028075 Aotus-ENSANAG00000031036
#rowData names(0):
#colnames(119): ACGGAGATCTTCAACT-1_1 ACTGCTCCAATGGATA-1_1 ...
#  GTCATTTCACAAGTAA-1_6 TCTTCGGGTCCGTGAC-1_6
#colData names(0):

# Filter lowly expressed genes, genes that do not have at least 1 reads in at least 1 samples
filter <- rowSums(assay(Cluster9)>1)>1

Cluster9 <- Cluster9[filter,]

# Identify the 100 most variable genes, which will be the input for zinbwave. 
assay(Cluster9) %>% log1p %>% rowVars -> vars
names(vars) <- rownames(Cluster9)
vars <- sort(vars, decreasing = TRUE)

Cluster9 <- Cluster9[names(vars)[1:100],]

assayNames(Cluster9)[1] <- "counts" #To avoid needing to specify which assay we should use for the zinbwave workflow

# ZINB-WaVE

Cluster9_zinb <- zinbwave(Cluster9, K = 2,  BPPARAM=SerialParam(), epsilon=1e12, normalizedValues=TRUE, observationalWeights = TRUE)

I get the following error:

Error in zinbInitialize(m, Y, nb.repeat = nb.repeat.initialize, BPPARAM = BPPARAM) : 
  Sample 3 has only 0 counts!

However, when I check the rowSums there doesn't appear to be any rows that return 0 counts.

table(rowSums(assay(Cluster9)) == 0)
#FALSE 
#  100

Any suggestions/help would be much appreciated!

Best, Amber

hermidalc commented 2 months ago

You are getting this error because your Cluster9 input count matrix has samples with all zero counts. Remember samples are columns not rows in the count matrix, so you should check with table(colSums(assay(Cluster9)) == 0). You need to filter out both samples columns with all zero counts and genes rows with all zero counts from your count matrix before using it with zinbwave.