RockefellerUniversity / RU_VisualizingGenomicsData

GNU General Public License v3.0
2 stars 1 forks source link

"Error in UseMethod("select_")" when trying to make PCA plot of the GO Heart Dev genes #3

Open alicekcassel opened 4 years ago

alicekcassel commented 4 years ago

This is from exercises for session 3. I'm getting an error when I try to use the select function on the OrgDb object before making a PCA plot of the GO heart development genes. Here's the error:

> HeartDev <- select(org.Mm.eg.db,
+                    keytype="GOALL",
+                    keys="GO:0007507",
+                    columns="ENTREZID")
Error in UseMethod("select_") : 
  no applicable method for 'select_' applied to an object of class "c('OrgDb', 'AnnotationDb', 'envRefClass', '.environment', 'refClass', 'environment', 'refObject', 'AssayData')"

I did some googling and it looks like people who had similar issues solved it by unloading dplyr, but I get another error message when I try to unload dplyr.

> detach("package:dplyr", unload=TRUE)
Error in base::detach(...) : invalid 'name' argument

Since I had dplyr loaded through tidyverse, I though maybe I needed to load the dplyr library on it's own, so I did that, then tried to unload dplyr and got a different error.

> library(dplyr)

Attaching package: 'dplyr'

The following object is masked from 'package:testthat':

    matches

The following object is masked from 'package:ShortRead':

    id

The following objects are masked from 'package:GenomicAlignments':

    first, last

The following object is masked from 'package:matrixStats':

    count

The following objects are masked from 'package:Biostrings':

    collapse, intersect, setdiff, setequal, union

The following object is masked from 'package:XVector':

    slice

The following object is masked from 'package:AnnotationDbi':

    select

The following object is masked from 'package:Biobase':

    combine

The following objects are masked from 'package:GenomicRanges':

    intersect, setdiff, union

The following object is masked from 'package:GenomeInfoDb':

    intersect

The following objects are masked from 'package:IRanges':

    collapse, desc, intersect, setdiff, slice, union

The following objects are masked from 'package:S4Vectors':

    first, intersect, rename, setdiff, setequal, union

The following objects are masked from 'package:BiocGenerics':

    combine, intersect, setdiff, union

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

Warning message:
In depth(path) : reached elapsed time limit
> detach("package:dplyr", unload=TRUE)
Warning message:
'dplyr' namespace cannot be unloaded:
  namespace 'dplyr' is imported by 'ggraph', 'dbplyr', 'ChIPseeker', 'broom', 'AnnotationHub', 'BiocFileCache', 'plotly', 'clusterProfiler', 'europepmc', 'tidygraph', 'tidyr', 'DiffBind' so cannot be unloaded 

So anyway, I'm just looking for away to run that select function without getting the "UseMethod("select_") error. Thanks so much in advance! Here is the rest of the code from session 3 exercises up to that point.

> library(tidyverse)
> library(DESeq2)
> load("tissueCounts.RData")
> dds <- DESeqDataSet(geneCounts,design = ~Tissue)
renaming the first element in assays to 'counts'
Warning message:
In DESeqDataSet(geneCounts, design = ~Tissue) :
  some variables in design formula are characters, converting to factors
> dds <- DESeq(dds)
estimating size factors
estimating dispersions
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
> dds2 <- DESeq(dds, test="LRT",reduced= ~1)
using pre-existing size factors
estimating dispersions
found already estimated dispersions, replacing these
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
> AllChanges <- results(dds2)
> rlogTissue <- rlog(dds)
> myPlot <- DESeq2::plotPCA(rlogTissue,intgroup="Tissue")
> myPlot+theme_minimal()
> 
> AllChanges <- results(dds2)
> rlogMatrix <- assay(rlogTissue)
> sigChanges <- rownames(AllChanges)[AllChanges$padj < 0.01 & !is.na(AllChanges$padj)]
> sigMatrix <- rlogMatrix[rownames(rlogMatrix) %in% sigChanges,]
> annoDF <- as.data.frame(colData(rlogTissue)[,1,drop=F])
> library(pheatmap)
> pheatmap(sigMatrix,scale="row",
+          show_rownames = F,
+          annotation_col = annoDF)
> 
> pcRes <- prcomp(t(rlogMatrix))
> PC2_rnk <- sort(pcRes$rotation[,2],decreasing=T)
> PC2_mat <- sigMatrix[match(names(PC2_rnk),rownames(sigMatrix),nomatch=0),]
> pheatmap(PC2_mat,scale="row",
+          cluster_rows = F,
+          show_rownames = F,
+          annotation_col = annoDF)
> 
> library(org.Mm.eg.db)
> HeartDev <- select(org.Mm.eg.db,
+                    keytype="GOALL",
+                    keys="GO:0007507",
+                    columns="ENTREZID")
Error in UseMethod("select_") : 
  no applicable method for 'select_' applied to an object of class "c('OrgDb', 'AnnotationDb', 'envRefClass', '.environment', 'refClass', 'environment', 'refObject', 'AssayData')"
> 
> detach("package:dplyr", unload=TRUE)
Error in base::detach(...) : invalid 'name' argument
> library(dplyr)

Attaching package: 'dplyr'

The following object is masked from 'package:testthat':

    matches

The following object is masked from 'package:ShortRead':

    id

The following objects are masked from 'package:GenomicAlignments':

    first, last

The following object is masked from 'package:matrixStats':

    count

The following objects are masked from 'package:Biostrings':

    collapse, intersect, setdiff, setequal, union

The following object is masked from 'package:XVector':

    slice

The following object is masked from 'package:AnnotationDbi':

    select

The following object is masked from 'package:Biobase':

    combine

The following objects are masked from 'package:GenomicRanges':

    intersect, setdiff, union

The following object is masked from 'package:GenomeInfoDb':

    intersect

The following objects are masked from 'package:IRanges':

    collapse, desc, intersect, setdiff, slice, union

The following objects are masked from 'package:S4Vectors':

    first, intersect, rename, setdiff, setequal, union

The following objects are masked from 'package:BiocGenerics':

    combine, intersect, setdiff, union

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

Warning message:
In depth(path) : reached elapsed time limit
> detach("package:dplyr", unload=TRUE)
Warning message:
'dplyr' namespace cannot be unloaded:
  namespace 'dplyr' is imported by 'ggraph', 'dbplyr', 'ChIPseeker', 'broom', 'AnnotationHub', 'BiocFileCache', 'plotly', 'clusterProfiler', 'europepmc', 'tidygraph', 'tidyr', 'DiffBind' so cannot be unloaded 
> 
matthew-paul-2006 commented 4 years ago

This is a common problem with functions that have generic names i.e. select. The first package loaded in takes precedent.

Once you have both packages how do you specify which one to use without unloading the original?

You can directly specify the function and what package it is coming from using a double colon :: , for example:

dplyr::select() or AnnotationDbi::select()

If you are unsure of the package name just do ?select. This will show all the packages that you have installed with a function of that name. Another part of doing the :: is that you don't have to use the library() function to load in a package of you use the functions in this way. That said it is better to load in the packages with library() so you have a record of what functions you are using as the packages will be attached, when you look at the sessionInfo().

alicekcassel commented 4 years ago

That helps, thank you!