# RNAseq analysis workflow using DESeq2

RNAseq analysis workflow using DESeq2

In [2]:
​x
 
library("DESeq2")
library(scales)
options(repr.plot.width=4, repr.plot.height=3)
Loading required package: S4Vectors
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: ‘BiocGenerics’

The following objects are masked from ‘package:parallel’:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following object is masked from ‘package:stats’:

    xtabs

The following objects are masked from ‘package:base’:

    anyDuplicated, append, as.data.frame, as.vector, cbind, colnames,
    do.call, duplicated, eval, evalq, Filter, Find, get, intersect,
    is.unsorted, lapply, Map, mapply, match, mget, order, paste, pmax,
    pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce, rep.int,
    rownames, sapply, setdiff, sort, table, tapply, union, unique,
    unlist, unsplit

Creating a generic function for ‘nchar’ from package ‘base’ in package ‘S4Vectors’
Loading required package: IRanges
Loading required package: GenomicRanges
Loading required package: GenomeInfoDb
Loading required package: Rcpp
Loading required package: RcppArmadillo
Warning message:
: replacing previous import ‘S4Vectors::Position’ by ‘ggplot2::Position’ when loading ‘DESeq2’
 
Ensure we're in the correct directory:

Ensure we're in the correct directory:

In [3]:
 
setwd(path.expand("~/data/work-RNAseq/"))
 
Define the file containing the raw counts (the ones we generated last session):

Define the file containing the raw counts (the ones we generated last session):

In [64]:
 
matrixFile = path.expand("/home/luna.kuleuven.be/r0602960/data/work-RNAseq/all.gene.counts")
In [65]:
 
countData <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))
head(countData)
SRR988518.Aligned.out.sam.bamSRR988519.Aligned.out.sam.bamSRR988520.Aligned.out.sam.bamSRR988521.Aligned.out.sam.bamSRR988522.Aligned.out.sam.bam
DDX11L100000
WASH7P00000
LOC10028877800000
MIR6859-400000
MIR6859-200000
MIR6859-300000
 
Make the column names somewhat nicer:

Make the column names somewhat nicer:

In [66]:
 
colnames(countData) <- c( "ctrl","Atra_24h","Atra_48h","2392_24h","2392_48h")
summary(countData)
      ctrl             Atra_24h        Atra_48h           2392_24h       
 Min.   :     0.0   Min.   :    0   Min.   :     0.0   Min.   :     0.0  
 1st Qu.:     0.0   1st Qu.:    0   1st Qu.:     0.0   1st Qu.:     0.0  
 Median :     7.0   Median :    6   Median :     9.0   Median :     8.0  
 Mean   :   680.7   Mean   :  617   Mean   :   693.9   Mean   :   390.3  
 3rd Qu.:   467.0   3rd Qu.:  381   3rd Qu.:   442.0   3rd Qu.:   245.0  
 Max.   :113898.0   Max.   :67891   Max.   :142305.0   Max.   :243529.0  
    2392_48h       
 Min.   :     0.0  
 1st Qu.:     0.0  
 Median :    10.0  
 Mean   :   489.2  
 3rd Qu.:   318.0  
 Max.   :238784.0  
 
Define the experimental conditions - Note the order has to be the same as the column order of the `countData`:
​
Another remark is that it is important that the order of the levels is correct. In this case `NS` comes first, which means that we will be comparing $S \over NS$, so positive log fold change values are up in the stiumulated samples.

Define the experimental conditions - Note the order has to be the same as the column order of the countData:

Another remark is that it is important that the order of the levels is correct. In this case NS comes first, which means that we will be comparing SNS, so positive log fold change values are up in the stiumulated samples.

In [67]:
 
condition <- factor(c("control","t1","t1","t2","t2"))
In [ ]:
 
factor
 
Prepapre a dataframe with the names and conditions. This will be fed to `DESeq2`. Ensure that the order is unchanged!

Prepapre a dataframe with the names and conditions. This will be fed to DESeq2. Ensure that the order is unchanged!

In [68]:
 
colData<- data.frame(sampleName = colnames(countData),
                      condition = condition)
colData
sampleNamecondition
ctrl control
Atra_24ht1
Atra_48ht1
2392_24ht2
2392_48ht2
 
Here we create a DESeq `DESeqDataSet` object for subsequent analysis:

Here we create a DESeq DESeqDataSet object for subsequent analysis:

In [69]:
 
dds <- DESeqDataSetFromMatrix(countData = countData,
                              colData = colData,
                              design = ~ condition)
#we need to do this to ensure the column names are correct.
colnames(dds) <- colnames(countData)
 
By printing `dds` to screen we can see some information

By printing dds to screen we can see some information

In [70]:
 
dds
class: DESeqDataSet 
dim: 26351 5 
exptData(0):
assays(1): counts
rownames(26351): DDX11L1 WASH7P ... TTTY4C TTTY4
rowRanges metadata column names(0):
colnames(5): ctrl Atra_24h Atra_48h 2392_24h 2392_48h
colData names(2): sampleName condition
In [71]:
 
r<-rowSums(counts(dds))
length(r)
26351
 
By comparing the `condition` factor in the `dds` object to the column names, you can confirm that the order is still correct

By comparing the condition factor in the dds object to the column names, you can confirm that the order is still correct

 
## Run the differential expression:
​
one function within `DESeq2` runs all steps required:

Run the differential expression:

one function within DESeq2 runs all steps required:

In [72]:
 
dds<- DESeq(dds)
estimating size factors
estimating dispersions
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
 
## QC

QC

 
DESeq2 estimates a factor to correct for the library size:

DESeq2 estimates a factor to correct for the library size:

In [73]:
 
options(repr.plot.width=4, repr.plot.height=3)
barplot(sizeFactors(dds))
 
This is very comparable to the sum of all reads per sample of the raw data, however, `DESeq2` is less sensitive to outliers:

This is very comparable to the sum of all reads per sample of the raw data, however, DESeq2 is less sensitive to outliers:

In [74]:
 
barplot(colSums(countData))
 
A scatter plot of sample vs sample will show us how the samples compare; are the replicates more similar than beween stimulated and non-stimulated?

A scatter plot of sample vs sample will show us how the samples compare; are the replicates more similar than beween stimulated and non-stimulated?

In [75]:
 
options(repr.plot.width=5, repr.plot.height=5)
plot(data.frame(log10(counts(dds))), cex=0.1, col=alpha("black", 0.4))
 
You may notice that there is a lot of variation (noise) for the low expressing genes. DESeq2 provides a function that minimizes this variation (and normalizes for library size, and log transforms the data): 

You may notice that there is a lot of variation (noise) for the low expressing genes. DESeq2 provides a function that minimizes this variation (and normalizes for library size, and log transforms the data):

In [76]:
 
rld <- rlogTransformation(dds, blind=TRUE)
In [77]:
 
options(repr.plot.width=5, repr.plot.height=5)
plot(data.frame(assay(rld)), cex=0.1, col=alpha("black", 0.4))
 
We can also do a PCA plot to understand inter-sample variation:

We can also do a PCA plot to understand inter-sample variation:

In [78]:
 
plotPCA(rld, intgroup=c("condition"))
 
#### MA plot
​
An MA plot show the mean expression vs the log fold change and is a very common method to visualize the results of a differential expression plot. Significantly differentially expressed genes are colored red:

MA plot

An MA plot show the mean expression vs the log fold change and is a very common method to visualize the results of a differential expression plot. Significantly differentially expressed genes are colored red:

In [79]:
 
options(repr.plot.width=5, repr.plot.height=4)
plotMA(dds,ylim=c(-3,3))
 
### export the results

export the results

In [80]:
 
res <- results(dds)
res <- res[order(res$padj),]
head(res)
log2 fold change (MAP): condition t2 vs control 
Wald test p-value: condition t2 vs control 
DataFrame with 6 rows and 6 columns
          baseMean log2FoldChange     lfcSE      stat       pvalue         padj
         <numeric>      <numeric> <numeric> <numeric>    <numeric>    <numeric>
CCL2    10603.8211       5.369883 0.3443560  15.59399 7.998069e-55 1.054625e-50
ADGRG5   1142.7493       4.741151 0.3273007  14.48561 1.493842e-47 9.848899e-44
FGR      2421.3284       4.601635 0.3300361  13.94282 3.478980e-44 1.529128e-40
ALOX5AP  6027.5018       4.269644 0.3204118  13.32549 1.645513e-40 5.424434e-37
NCF1      876.5263       3.969062 0.3460804  11.46861 1.896712e-30 5.002009e-27
DNAJB9    893.9345       3.597413 0.3461145  10.39371 2.648486e-25 5.820490e-22
In [103]:
 
res_ctrl.t1 <- results(dds, contrast=c("condition","control","t1"))
res_ctrl.t2 <- results(dds, contrast=c("condition","control","t2"))
res_t1.t2 <- results(dds, contrast=c("condition","t1","t2"))
 
How many genes are differentially expressed?

How many genes are differentially expressed?

In [149]:
 
res.sign_ctrl.t1<- res_ctrl.t1[(!is.na(res_ctrl.t1$padj)) & (res_ctrl.t1$padj < 0.05),]
res.sign_ctrl.t1_up<-subset(res.sign_ctrl.t1, log2FoldChange>0)
dim(res.sign_ctrl.t1_up)
res.sign_ctrl.t1_down<-subset(res.sign_ctrl.t1, log2FoldChange<0)
dim(res.sign_ctrl.t1_down)
  1. 416
  2. 6
  1. 692
  2. 6
In [138]:
 
res.sign_ctrl.t2<- res_ctrl.t2[(!is.na(res_ctrl.t2$padj)) & (res_ctrl.t2$padj < 0.05),]
res.sign_ctrl.t2_up<-subset(res.sign_ctrl.t2, log2FoldChange>1)
dim(res.sign_ctrl.t1_up)
res.sign_ctrl.t2_down<-subset(res.sign_ctrl.t2, log2FoldChange< -1)
dim(res.sign_ctrl.t1_down)
  1. 357
  2. 6
  1. 571
  2. 6
In [139]:
 
res.sign_t1.t2<- res_t1.t2[(!is.na(res_t1.t2$padj)) & (res_t1.t2$padj < 0.05),]
res.sign_t1.t2_up<-subset(res.sign_t1.t2, log2FoldChange>1)
dim(res.sign_t1.t2_up)
res.sign_t1.t2_down<-subset(res.sign_t1.t2, log2FoldChange< -1)
dim(res.sign_t1.t2_down)
  1. 487
  2. 6
  1. 530
  2. 6
In [107]:
 
ddsLRT <- DESeq(dds, test="LRT", reduced= ~ 1)
resLRT <- results(ddsLRT)
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
In [109]:
 
res.sign_LRT<- resLRT[(!is.na(resLRT$padj)) & (resLRT$padj < 0.05),]
dim(res.sign_LRT)
  1. 2678
  2. 6
In [141]:
 
ls()
  1. 'A'
  2. 'colData'
  3. 'condition'
  4. 'countData'
  5. 'dds'
  6. 'dds2'
  7. 'ddsLRT'
  8. 'dds_r'
  9. 'idx'
  10. 'matrixFile'
  11. 'r'
  12. 'res'
  13. 'res_ctrl.t1'
  14. 'res_ctrl.t2'
  15. 're.sign_t1.t2'
  16. 'resLRT'
  17. 'res.sign'
  18. 'res.sign_ctrl.t1'
  19. 'res.sign_ctrl.t1_down'
  20. 'res.sign_ctrl.t1_up'
  21. 'res.sign_ctrl.t2'
  22. 'res.sign_ctrl.t2_down'
  23. 'res.sign_ctrl.t2_up'
  24. 'res.sign_LRT'
  25. 'res.sign_t1.t2'
  26. 'res.sign_t1.t2_down'
  27. 'res.sign_t1.t2_up'
  28. 'res_t1.t2'
  29. 'res.t1.t2'
  30. 'rld'
 
Save to disk:

Save to disk:

In [153]:
 
write.table(res.sign_ctrl.t1_up, "deseq1_ctrl.t1_up.tsv", sep="\t", col.names=NA, quote=FALSE)
In [154]:
 
write.table(res.sign_ctrl.t1_down, "deseq1_ctrl.t1_down.tsv", sep="\t", col.names=NA, quote=FALSE)
In [144]:
 
write.table(res.sign_ctrl.t2_up, "deseq_ctrl.t2_up.tsv", sep="\t", col.names=NA, quote=FALSE)
In [146]:
 
write.table(res.sign_ctrl.t2_down, "deseq_ctrl.t2_down.tsv", sep="\t", col.names=NA, quote=FALSE)
In [147]:
 
write.table(res.sign_t1.t2_down, "deseq_t1.t2_down.tsv", sep="\t", col.names=NA, quote=FALSE)
In [148]:
 
write.table(res.sign_t1.t2_up, "deseq_t1.t2_up.tsv", sep="\t", col.names=NA, quote=FALSE)
​
In [117]:
 
write.table(res.sign_LRT, "deseq.LRT.tsv", sep="\t", col.names=NA, quote=FALSE)
 
we get gene list from these tsv files, and run the gene ontology analysis using reactome (http://www.reactome.org/).

we get gene list from these tsv files, and run the gene ontology analysis using reactome (http://www.reactome.org/).

 
<img width="100%" src="/user/r0602960/files/ATRAup.jpg">

 
<img width="100%" src="/user/r0602960/files/ATRAdown.jpg">

 
The differential analysis of RNA seq of ATRA shows that ATRA treatment changed the expression level of genes that are mostly involved in NOTCH1 signaling, which regulates cell differentiation and proliferation, cell fate and apoptosis. 

The differential analysis of RNA seq of ATRA shows that ATRA treatment changed the expression level of genes that are mostly involved in NOTCH1 signaling, which regulates cell differentiation and proliferation, cell fate and apoptosis.

 
<img width="100%" src="/user/r0602960/files/MC2392up.jpg">

 
<img width="100%" src="/user/r0602960/files/MC2392down.jpg">

 
The differential analysis of RNAseq of MC2392 shows that MC2392 treatment increased expression level of genes mostly involved in histone modification and cellular senescence. And MC2392 treatment decreased expression of genes involved in cellular response to heat stress.

The differential analysis of RNAseq of MC2392 shows that MC2392 treatment increased expression level of genes mostly involved in histone modification and cellular senescence. And MC2392 treatment decreased expression of genes involved in cellular response to heat stress.

 
ATRA upregulated genes are enriched in metabolic pathway.
MC2392 downregulated genes are enriched in metabolic process and pathway analysis showed the decreased expression of components in cell-cell communication and cellular response to stress.
MC2392 induce 7 genes expression in apoptosis pathway:  GSN,DAPK2,PSMB9,CASP9,PSMB10,H1F0,PSMB8,
ATRA induce 7 gene expression in apoptosis pathway:VIM, BCL2,UNC5B,MAPT,PLEC,CTSG,CAD
MC2392 induce 7 genes expression in apoptosis pathway: 
E2F1,HIST1H1E,GSN,PLEC,HIST1H1C,H1F0,CTSG,CAD

ATRA upregulated genes are enriched in metabolic pathway. MC2392 downregulated genes are enriched in metabolic process and pathway analysis showed the decreased expression of components in cell-cell communication and cellular response to stress. MC2392 induce 7 genes expression in apoptosis pathway: GSN,DAPK2,PSMB9,CASP9,PSMB10,H1F0,PSMB8, ATRA induce 7 gene expression in apoptosis pathway:VIM, BCL2,UNC5B,MAPT,PLEC,CTSG,CAD MC2392 induce 7 genes expression in apoptosis pathway: E2F1,HIST1H1E,GSN,PLEC,HIST1H1C,H1F0,CTSG,CAD