plotPCA with DESeq2 results in unable to find an inherited method for function plotPCA for signature matrix Error
Entering edit mode
Last seen 2.3 years ago

I'm trying to perform RNASeq analysis with DESeq2 in RStudio, and as one of the quality control steps I am trying to perform Principal Component Analysis on my DESeq2 object. I've included the code chunk below - I am able to create the DESeq2 object just fine, but run into problems plotPCA(). I think there's an issue with the packages talking to each other/masking each other, but I'm not sure how to resolve it. I've also tried DESeq2::plotPCA() and still received the same error message. Any help would be greatly appreciated - thanks!

#code from my script

dataset = "./data/merged.csv"
dataset = read.table(dataset,
                     header = T,
                     sep = ",",
                     row.names = 1,
                     stringsAsFactors = F)

metadata = data.frame(condition = (c("CTL", "TS21", "TS21", "CTL")),
                      row.names = c("NDC", "DSIPS", "THO3B", "THO3F"))

dds_DS <- DESeqDataSetFromMatrix(countData = dataset,
                                 colData = metadata,
                                 design = ~condition)


plotPCA(vst_dds_DS, intgroup="condition")

#Error Message!
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘plotPCA’ for signature ‘"matrix"’

R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices
[6] utils     datasets  methods   base     

other attached packages:
 [1] RColorBrewer_1.1-2          pheatmap_1.0.12            
 [3] DESeq2_1.28.1               SummarizedExperiment_1.18.1
 [5] DelayedArray_0.14.0         matrixStats_0.56.0         
 [7] Biobase_2.48.0              GenomicRanges_1.40.0       
 [9] GenomeInfoDb_1.24.0         IRanges_2.22.2             
[11] S4Vectors_0.26.1            BiocGenerics_0.34.0        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6           locfit_1.5-9.4        
 [3] lattice_0.20-41        digest_0.6.25         
 [5] R6_2.4.1               RSQLite_2.2.0         
 [7] ggplot2_3.3.1          pillar_1.4.4          
 [9] zlibbioc_1.34.0        rlang_0.4.6           
[11] rstudioapi_0.11        annotate_1.66.0       
[13] blob_1.2.1             Matrix_1.2-18         
[15] splines_4.0.0          BiocParallel_1.22.0   
[17] geneplotter_1.66.0     RCurl_1.98-1.2        
[19] bit_1.1-15.2           munsell_0.5.0         
[21] tinytex_0.23           compiler_4.0.0        
[23] xfun_0.14              pkgconfig_2.0.3       
[25] tidyselect_1.1.0       tibble_3.0.1          
[27] GenomeInfoDbData_1.2.3 XML_3.99-0.3          
[29] crayon_1.3.4           dplyr_1.0.0           
[31] bitops_1.0-6           grid_4.0.0            
[33] xtable_1.8-4           gtable_0.3.0          
[35] lifecycle_0.2.0        DBI_1.1.0             
[37] magrittr_1.5           scales_1.1.1          
[39] farver_2.0.3           XVector_0.28.0        
[41] genefilter_1.70.0      ellipsis_0.3.1        
[43] vctrs_0.3.1            generics_0.0.2        
[45] tools_4.0.0            bit64_0.9-7           
[47] glue_1.4.1             purrr_0.3.4           
[49] survival_3.1-12        yaml_2.2.1            
[51] AnnotationDbi_1.50.0   colorspace_1.4-1      
[53] memoise_1.1.0          knitr_1.28            

Any help would be greatly appreciated! Thanks!

deseq2 pheatmap RColorBrewer BiocGenerics • 2.7k views
Entering edit mode
Last seen 3 days ago
United States

I'll give the answer but also how you could find it with some sleuthing.

Let's say I try to call plotPCA on this object x:

> x <- 5
> plotPCA(x)
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘plotPCA’ for signature ‘"numeric"’
Calls: plotPCA -> <Anonymous>
> class(x)
[1] "numeric"

So R is telling me that plotPCA is not designed for objects like x. So what class is it designed for?

> ?plotPCA

After selecting the DESeq2 method, you get:


  object: a ‘DESeqTransform’ object, with data in ‘assay(x)’, produced
          for example by either ‘rlog’ or

So you should provide plotPCA with an object that is a DESeqTransform object as output by rlog or vst or varianceStabilizingTransformation.

What you've likely done is taken out just the assay data and provided this to plotPCA? But that won't work because then how can the function know which samples belong to which group?

Here is an example of use:

Entering edit mode

Thank you Michael! Really appreciate providing the path/method of thinking towards the solution as well as the solution itself!


Login before adding your answer.

Traffic: 246 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6