Question: DESeq2: subset dds or vsd to plot PCA with specific genes only
gravatar for Cece
18 months ago by
United States/Houston
Cece0 wrote:

Hi All,

I've run DESeq2 on my counts comparing two conditions, treated vs untreated. I have my dds object and have generated my vsd object using the command:

vsd <- vst(dds, blind = FALSE)

then plotted my PCA using:

plotPCA(vsd, intgroup = "condition", ntop = 500)

However, I'd like to produce another plot using just a subset, which is those genes I identified as DE (padj < 0.05). My problem is, when I try to extract a subset from the vsd data using:

de <- rownames(res[res$padj<0.05 & !$padj), ])
de_mat <- assay(vsd)[de,]

Then try to use this object to plot the PCA:

plotPCA(de_mat, intgroup = "condition", ntop = 500)

I receive the error message:

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

Which makes sense because de_mat is a matrix and vsd is not. Can anyone help me with another way to extract my subset of genes from the dds/ vsd object so I can use the subsequent object to plot a PCA?

I need to confirm, via PCA, that this subset does indeed discriminate between the two groups sufficient to justify my downstream analyses. My PCA using the full gene set shows mixing of the groups and it would be great to be able to justify using a great visual like a PCA for just the DE genes at this point, so that I can show clear separation of the groups.

I greatly appreciate all help in advance. If anyone has ideas on other visuals, I'm open to those as well. I've already covered heatmaps and volcano plots, though; it's just that my PI really likes the idea of the DE genes only PCA.

subset rna-seq plotpca deseq2 R • 2.2k views
ADD COMMENTlink modified 18 months ago by Kevin Blighe65k • written 18 months ago by Cece0
gravatar for Kevin Blighe
18 months ago by
Kevin Blighe65k
Kevin Blighe65k wrote:


The issue is that plotPCA() is a DESeq2-specific function - it does not work with data-matrices or data-frames. To generate your PCA bi-plot, you will have to do:

plotPCA(vsd, intgroup = "condition", ntop = 500)


plotPCA(vsd[de,], intgroup = "condition", ntop = 500)

For now, I will not discuss the validity of running PCA in a biased fashion.

If you want to run PCA analyses on a simple data-matrix or data-frame, then you can use my own package:


ADD COMMENTlink modified 18 months ago • written 18 months ago by Kevin Blighe65k

Thanks, Kevin,

Subsetting vsd worked great for me. I've also looked at PCATools, which looks really comprehensive but a little intimidating to me. My counts data is in a text file, with genes as rows and columns as samples:

          sample1   sample2    sample3
gene1    1063       1092       1487
gene2    240        309        329
gene3    47         26         31

My phenotypic data is also a text file, with samples as rows and each column representing a different phenotypic trait:

           Age    Gender    condition
sample2    13     Female    treated
sample2    15     Male      treated
sample3    8      Female    untreated

How do I import this data into PCATools?

Cheers, Cece

ADD REPLYlink modified 18 months ago • written 18 months ago by Cece0

Hey, you would just have to do:

p <- pca(x = MyData, metadata = MyMetadata, removeVar = 0.1)

However, I have a strict check in place whereby the rownames of MyMetadata have to be the same as the colnames of MyData (same names and in same order).

For this, as per DESeq2's function, the input data should be the transformed counts.

Don't worry if you just want to generate a bi-plot - that is easy with DESeq2's function.

ADD REPLYlink modified 18 months ago • written 18 months ago by Kevin Blighe65k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1714 users visited in the last hour