Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in design of voom object #15

Closed
kelshmo opened this issue Jul 17, 2020 · 9 comments
Closed

Error in design of voom object #15

kelshmo opened this issue Jul 17, 2020 · 9 comments

Comments

@kelshmo
Copy link

kelshmo commented Jul 17, 2020

I'm running varianceParition 1.19.6. To repro the error from voomWithDreamWeights:

data(varPartDEdata)
countMatrix <- countMatrix[1:1000,]
gene_expression <- edgeR::DGEList(countMatrix)
gene_expression <- edgeR::calcNormFactors(gene_expression)
voom_gene_expression <- variancePartition::voomWithDreamWeights(counts = gene_expression$counts,
                                                                formula = "~ Disease + (1 |DiseaseSubtype)",
                                                                data = metadata,
                                                                quiet = TRUE)
voom_gene_expression$design

Error:

Error in x[[what]] : object of type 'closure' is not subsettable
@GabrielHoffman
Copy link
Owner

I will this this tomorrow, but in the meantime the issue is due to the fact that your formula is really a string. If you remove the quotes it should work

@GabrielHoffman
Copy link
Owner

Fixed in v1.19.7. Confirm?

@kelshmo
Copy link
Author

kelshmo commented Jul 17, 2020

The outcome is the same with both an unquoted and a quoted formula.

> voom_gene_expression$design
standardGeneric for "design" defined from package "BiocGenerics"

function (object, ...) 
standardGeneric("design")
<bytecode: 0x7fbbadbae4a8>
<environment: 0x7fbbadbadac0>
Methods may be defined for arguments: object
Use  showMethods("design")  for currently available ones.
$design
Error in x[[what]] : object of type 'closure' is not subsettable

I'm working in R 4.0.2.

@kelshmo
Copy link
Author

kelshmo commented Jul 21, 2020

This error is still a problem in 1.19.8. Here is another minimum reproducible example:

metadata <- tibble::tribble(
  ~samples, ~sex, ~batch, ~age, ~RIN, ~diagnosis,
  "S567", "F", "1", "68", "7.5", "dx",
  "S453", "F", "2", "60", "7", "dx",
  "S231", "M", "2", "54", "7", "dx",
  "S444", "M", "2", "55", "7", "dx",
  "S555", "F", "1", "68", "7.5", "dx",
  "S304", "F", "2", "60", "7", "ct",
  "S232", "M", "2", "54", "7.5", "ct",
  "S447", "M", "2", "55", "7.5", "ct"
)

metadata <- tibble::column_to_rownames(metadata, var = "samples")

counts <- tibble::tribble(
  ~geneId, ~S567, ~S453,~S231, ~S444, ~S555, ~S304, ~S232, ~S447,
  "ENSG1", 0, 0, 500, 0, 10, 43, 432, 45,
  "ENSG2", 23, 25, 29, 30, 56, 89, 73, 70,
  "ENSG3", 84, 82, 0, 0, 98, 80, 200, 201,
  "ENSG4", 0, 204, 350, 790, 353, 456, 555, 890,
  "ENSG5", 0, 0, 0, 70, 0, 0, 0, 70
)

counts <- tibble::column_to_rownames(counts, var = "geneId")

counts <- as.matrix(counts)

gene_expression <- edgeR::DGEList(counts)
gene_expression <- edgeR::calcNormFactors(counts)
voom_gene_expression <- variancePartition::voomWithDreamWeights(counts = gene_expression,
                                                                formula = "~ diagnosis + (1|batch)",
                                                                data = metadata,
                                                                quiet = TRUE)
voom_gene_expression$design

@kelshmo
Copy link
Author

kelshmo commented Jul 21, 2020

In 19.9.9 I'm returning a new error using the above code chunk:

The gene_expression object is length 8 and the colnames match the rownames of metadata and is also length 8.

> voom_gene_expression <- variancePartition::voomWithDreamWeights(counts = gene_expression,
+                                                                 formula = "~ diagnosis + (1|batch)",
+                                                                 data = metadata,
+                                                                 quiet = TRUE)
Error in .fitVarPartModel(exprObj, formula, data, REML = REML, useWeights = useWeights,  : 
  the number of samples in exprObj (i.e. cols) must be the same as in data (i.e rows)

@GabrielHoffman
Copy link
Owner

This error is intended, but not that informative. I have updated it to read:
counts is type 'numeric' and can't be converted to matrix unambiguously

The issue is that that counts you passed was a vector and there is no way to tell if you mean that as the row or a column of a matrix. So it throws the new error in v1.19.10

metadata <- tibble::tribble(
  ~samples, ~sex, ~batch, ~age, ~RIN, ~diagnosis,
  "S567", "F", "1", "68", "7.5", "dx",
  "S453", "F", "2", "60", "7", "dx",
  "S231", "M", "2", "54", "7", "dx",
  "S444", "M", "2", "55", "7", "dx",
  "S555", "F", "1", "68", "7.5", "dx",
  "S304", "F", "2", "60", "7", "ct",
  "S232", "M", "2", "54", "7.5", "ct",
  "S447", "M", "2", "55", "7.5", "ct"
)

metadata <- tibble::column_to_rownames(metadata, var = "samples")

counts <- tibble::tribble(
  ~geneId, ~S567, ~S453,~S231, ~S444, ~S555, ~S304, ~S232, ~S447,
  "ENSG1", 0, 0, 500, 0, 10, 43, 432, 45,
  "ENSG2", 23, 25, 29, 30, 56, 89, 73, 70,
  "ENSG3", 84, 82, 0, 0, 98, 80, 200, 201,
  "ENSG4", 0, 204, 350, 790, 353, 456, 555, 890,
  "ENSG5", 0, 0, 0, 70, 0, 0, 0, 70
)

counts <- tibble::column_to_rownames(counts, var = "geneId")

counts <- as.matrix(counts)

# code from before: running calcNormFactors on counts directly is not what you want.
# gene_expression <- edgeR::DGEList(counts)
# gene_expression <- edgeR::calcNormFactors(counts)

# correct code that avoids this error
DGE <- edgeR::DGEList(counts)
gene_expression <- edgeR::calcNormFactors(DGE)

form = ~ diagnosis + (1|batch)

voom_gene_expression <- variancePartition::voomWithDreamWeights(counts = gene_expression,
                                                                formula = form,
                                                                data = metadata,
                                                                quiet = TRUE)

voom_gene_expression$design

@kelshmo
Copy link
Author

kelshmo commented Jul 21, 2020

Oops that was a typo! Thanks for updating the error message.

However, when I copy and paste the above I still get the error:

Error in variancePartition::voomWithDreamWeights(counts = gene_expression,  : 
  object 'design' not found

Running varianceParition 1.19.10. Since that is a limma error (I think) limma_3.44.3 is in the namespace but not attached to the session.

@GabrielHoffman
Copy link
Owner

GabrielHoffman commented Jul 21, 2020

Wow, this is a mysterious one! Can you send traceback() and sessionInfo()

Also are you running in a fresh R session?

@kelshmo
Copy link
Author

kelshmo commented Jul 21, 2020

This works in a fresh R session. 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants