drisso / zinbwave

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

Error in getAndCheckWeights(object, modelMatrix) : all(weights.ok) is not TRUE #39

Closed bio-la closed 4 years ago

bio-la commented 5 years ago

Hi, I'd like to estimate the zinbwave weights to use in a differential expression analysis. Some of my tests fail with this error:

Error in getAndCheckWeights(object, modelMatrix) : all(weights.ok) is not TRUE Calls: DESeq ... estimateDispersionsGeneEst -> getAndCheckWeights -> stopifnot Execution halted

I tried to debug using the function getAndCheckWeights

if ("weights" %in% assayNames(object)) {
        useWeights <- TRUE
        weights <- unname(assays(object)[["weights"]])
        stopifnot(all(weights >= 0))
        weights <- weights/apply(weights, 1, max)
        if (is.null(attr(object, "weightsOK"))) {
            m <- ncol(modelMatrix)
            full.rank <- qr(modelMatrix)$rank == m
            weights.ok <- logical(nrow(weights))
            if (full.rank) {
                for (i in seq_len(nrow(weights))) {
                  weights.ok[i] <- qr(weights[i, ] * modelMatrix)$rank == 
                    m
                }
            }
            else {
                weights.ok <- rep(TRUE, nrow(weights))
                for (j in seq_len(ncol(modelMatrix))) {
                  num.zero <- colSums(t(weights) * modelMatrix[, 
                    j] == 0)
                  weights.ok <- weights.ok & (num.zero != nrow(modelMatrix))
                }
            }
            stopifnot(all(weights.ok))
        }

and lucky me, I have only one weight.ok which is false! which(!weights.ok)

[1] 29

Can you give me a hint on what I should do to fix that? I am using a 1000 x 4755 object (top 1000 variable genes) k=10 epsilon=1000

zinb <- zinbwave(se.vars, K=10, epsilon=1000, BPPARAM=BiocParallel::MulticoreParam(10)) dds <- DESeqDataSet(zinb, design = ~pool+cell.type)

estimating size factors estimating dispersions gene-wise dispersion estimates Error in getAndCheckWeights(object, modelMatrix) : all(weights.ok) is not TRUE Calls: DESeq ... estimateDispersionsGeneEst -> getAndCheckWeights -> stopifnot Execution halted

thanks!

drisso commented 5 years ago

Hi @bio-la

what version of the zinbwave package are you using? In an older version of the package it was possible for some weights to be zero and that could be the problem.

I would suggest to update to the newest version of the package and try again. If that doesn't help, it may be helpful to look at the value of your 29th weight.

Best, Davide