How to generate a PCA scree plot in DESeq2?
2
0
Entering edit mode
@candicechudvm-10038
Last seen 3.1 years ago

Hi all,

I've watched this video and wants to visualize the PCA scree plot to check my PCA plot that was generated in DESeq2.

Is there any way I can do it in DESeq2 or in other Bioconductor packages?

pca deseq2 PCA scree plot • 2.0k views
2
Entering edit mode
@mikelove
Last seen 9 hours ago
United States

I'd recommend just using your own code to do the PCA.

You can copy out the first lines of the plotPCA function to get started, see ?plotPCA.

Then you'll just want to plot the amounts in 'percentVar'.

1
Entering edit mode

Hi Michael,

Thank you for your help! Our RNA-seq research has been published in Scientific Reports: https://www.nature.com/articles/s41598-017-16603-y. Your work and technical supports are appreciated and acknowledged in the references and the acknowledgment section.

1
Entering edit mode

Cheers. that's very kind of you.

2
Entering edit mode
@candicechudvm-10038
Last seen 3.1 years ago

Hi Micheal,

Thank you so much!!!

I manage to generate the PCA scree plot by following your instruction.

Here is my script:

library(DESeq2)
library(matrixStats)

#How to get PCA plot?
##how to obtain d.deseq was described in DESeq2 manual

cds=estimateDispersions(dds)
vsd=varianceStabilizingTransformation(cds)
plotPCA(vsd,intgroup=c("condition","timepoints"))

#How to get PCA scree plot?

## calculate the variance for each gene
rv <- rowVars(assay(vsd))

## select the ntop genes by variance
select <- order(rv, decreasing=TRUE)[seq_len(min(500, length(rv)))]

## perform a PCA on the data in assay(x) for the selected genes
pca <- prcomp(t(assay(vsd)[select,]))

## the contribution to the total variance for each component
percentVar <- pca$sdev^2 / sum( pca$sdev^2 )

##plot the "percentVar"
scree_plot=data.frame(percentVar)
scree_plot[,2]<- c(1:24)

colnames(scree_plot)<-c("variance","component_number")
ggplot(scree_plot, mapping=aes(x=component_number, y=variance))+geom_bar(stat="identity")