Question: RSEM_R differential expression and PCA plot
gravatar for mxlsherry1992
17 months ago by
mxlsherry199240 wrote:

Dear all,

I have a species without reference genome, so I did the RNA-SEQ analysis using " -RSEM" pipeline, and got two files:


Then, I used and to do the differential expression analysis.

But now, I want to use R studio to do some PCA plot and heatmap, here is part of my R script, I just want to know which file should I used as the input file for R? (in the position of "pan_all_counts")


## Input the count data
countData <- read.table("pan_all_counts", header=TRUE, row.names=1)

##Import the metadata that inlcudes the treatment assignments and if single or paired reads.
colData <- read.table("pan_all_count_sample", header=TRUE, row.names=1)

# check the order of treatment assignments in colData and countData
all(rownames(colData) %in% colnames(countData))
countData <- countData[, rownames(colData)]
all(rownames(colData) == colnames(countData))

##e Creat the dataset and define model
dds <- DESeqDataSetFromMatrix(countData = countData,
                              colData = colData,
                              design = ~ condition)

##########remove genes with no counts
dds <- dds[rowSums(counts(dds)) > 1,]

###########PCA plot
#rlog This function transforms the count data to the log2 scale in a way which minimizes differences between samples for rows with small counts, 
#and which normalizes with respect to library size.

#perform DESeq, DESeq will do the following things:
#estimating dispersions
#found already estimated dispersions, replacing these
#gene-wise dispersion estimates
#mean-dispersion relationship
#final dispersion estimates
#fitting model and testing
jumpy <- DESeq(dds)
#make sure results look okay
res <- results(jumpy)

#reduce alpha to .05 for analysis of results
res05 <- results(jumpy, alpha =.05)
#find out how many genes are differentially expressed below the maximum adjusted p-value cutoff
#sum(res05$padj < .05, na.rm=TRUE)
sum(res05$padj < .05, na.rm=TRUE)
#order all the genes by padj
#resOrdered <- res05[order(res05$padj),]
resOrdered <- res05[order(res05$padj),]
#store the number of DE genes as a variable
#numDEgenes <- sum(res05$padj < .05, na.rm=TRUE) should use padj
numDEgenes <- sum(res05$padj < .05 & (res05$log2FoldChange > 1 | res05$log2FoldChange < -1), na.rm=TRUE)
#get only the DEgenes ordered by padj
DEgenes <- head(resOrdered, numDEgenes)
#write only these genes to a CSV file
write.csv(, file="starfishtopDEgenes1.csv")
rna-seq • 751 views
ADD COMMENTlink modified 17 months ago • written 17 months ago by mxlsherry199240

But now, I want to use R studio to do some PCA plot and heatmap,

If above is your aim, I wonder why you want to do DEseq as you already did differential analysis using RSEM. You can use your .results files to generate heatmap and pca plot. I assume it has count matrix where rows are genes / isoforms and columns are samples.

ADD REPLYlink written 17 months ago by Chirag Parsania1.9k

Hi, Thanks for the reply! so you means I can use the results of


directly for PCA and heatmap?

Here is part of the RSEM.genes.results, if I need to extracted one columns to do that? ( And I have 7 sample, 2 replicated, so I got 14 RSEM.genes.results files together, will want to do the PCA and heatmap together, if you know which software can do that ..)

gene_id transcript_id(s)    length  effective_length    expected_count  TPM FPKM
TRINITY_DN0_c0_g1   TRINITY_DN0_c0_g1_i1    249.00  80.67   0.00    0.00    0.00
TRINITY_DN100000_c0_g1  TRINITY_DN100000_c0_g1_i1   851.00  680.67  8.00    1.19    2.55
ADD REPLYlink written 17 months ago by mxlsherry199240

It seems RSEM.genes.results contains normalised expression values which are TPM and FPKM. As you said, you have already performed differential analysis using you must have fold change matrix as well. Depending upon your purpose of analysis you can use either FPKM/ TPM or fold change value to plot the heatmap. One of the purposes of PCA analysis is to check how good replicates are. If you also want to use PCA for same purpose, I would suggest you to use log2(FPKM) values to generate PCA plot. There are several tutorial available online for PCA. For I heamap my personal favourite us ComplexHeatmap

ADD REPLYlink modified 17 months ago • written 17 months ago by Chirag Parsania1.9k

Thanks for your kindly reply!! So it seems FPKM/FPM and log2foldchange value works for heatmap plotting..? I just copy and paste my results for different samples and input them to do heatmap is ok...?:)

Thank you!

ADD REPLYlink written 17 months ago by mxlsherry199240

This is very vague question to answer. It depends on for what purpose you want to plot the heatmap

ADD REPLYlink written 17 months ago by Chirag Parsania1.9k
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: 1552 users visited in the last hour