# DESeq analysis of RNAseq data

DESeq analysis of RNAseq data

 
Group members

Group members

 
Florian Delbart

Florian Delbart

 
Jens Rummens

Jens Rummens

 
Alexander Sneyers

Alexander Sneyers

 
The DESeq tool was used to analyze the count data of RNAseq and identify upregulated and downregulated genes.

The DESeq tool was used to analyze the count data of RNAseq and identify upregulated and downregulated genes.

In [1]:
​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’
In [2]:
 
setwd(path.expand("~/data/Assignment/DeSEQ"))
#set working directory
 
To be able to perform the DESeq analysis a matrix of the gene count data was constructed

To be able to perform the DESeq analysis a matrix of the gene count data was constructed

In [3]:
 
matrixFile = path.expand("~/data/Assignment/DeSEQ/allgene.gene.counts.tsv")
#define matrix file
In [4]:
 
countData <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))
head(countData)
#making matrix of gene count data
shNS1.bamshNS2.bamshNS3.bamshRUNX1.1.bamshRUNX1.2.bamshRUNX1.3.bam
MIR1302-11 0 0 00 0 0
FAM138A 0 0 00 0 0
OR4F5 0 0 00 0 0
RP11-34P13.7 2 0 00 0 1
RP11-34P13.8 0 0 00 0 0
AL627309.11314216 1512
 
Changing the layout of the matrix

Changing the layout of the matrix

In [5]:
 
colnames(countData) <- c("shNS1", "shNS2", "shNS3", "shRUNX1.1", "shRUNX1.2", "shRUNX1.3")
head(countData)
#Change column names to experimental conditions rather than file name
shNS1shNS2shNS3shRUNX1.1shRUNX1.2shRUNX1.3
MIR1302-11 0 0 00 0 0
FAM138A 0 0 00 0 0
OR4F5 0 0 00 0 0
RP11-34P13.7 2 0 00 0 1
RP11-34P13.8 0 0 00 0 0
AL627309.11314216 1512
 
Defining which samples correspond to control or knockdown conditions 

Defining which samples correspond to control or knockdown conditions

In [6]:
 
#Name of experimental conditions must be the same as data, very important.
condition <- factor(c("shNS", "shNS", "shNS", "shRUNX1", "shRUNX1", "shRUNX1"))
print(condition)
[1] shNS    shNS    shNS    shRUNX1 shRUNX1 shRUNX1
Levels: shNS shRUNX1
In [7]:
 
#Make table with sample names and corresponding conditions
colData <- data.frame(sampleName = colnames(countData),
                      condition = condition)
colData
sampleNamecondition
shNS1 shNS
shNS2 shNS
shNS3 shNS
shRUNX1.1shRUNX1
shRUNX1.2shRUNX1
shRUNX1.3shRUNX1
In [1]:
 
#Reformatting the generated dataset to a DESeq dataset to be able to use the DESeq tool
dds <- DESeqDataSetFromMatrix(countData = countData,
                              colData = colData,
                              design = ~ condition)
#Make sure the column names are correct.
colnames(dds) <- colnames(countData)
Error in eval(expr, envir, enclos): could not find function "DESeqDataSetFromMatrix"
Traceback:


In [9]:
 
#Summary of the DESeq dataset
dds
class: DESeqDataSet 
dim: 41863 6 
exptData(0):
assays(1): counts
rownames(41863): MIR1302-11 FAM138A ... AC007965.1 RNU6-1314P
rowRanges metadata column names(0):
colnames(6): shNS1 shNS2 ... shRUNX1.2 shRUNX1.3
colData names(2): sampleName condition
In [10]:
 
#Check if conditions contain all samples
dds$condition
  1. shNS
  2. shNS
  3. shNS
  4. shRUNX1
  5. shRUNX1
  6. shRUNX1
 
Analysis of differentially expressed genes

Analysis of differentially expressed genes

In [11]:
 
dds <- DESeq(dds)
estimating size factors
estimating dispersions
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
 
Quality control for library size.

Quality control for library size.

In [19]:
 
#Plot of relative library sizes of the different samples
options(repr.plot.width=8, repr.plot.height=5)
barplot(sizeFactors(dds))
 
Large variation in library size was observed between the shNS conditions. Much less variation in library size in shRUNX1 samples.
DeSEQ corrects for variations in library size.

Large variation in library size was observed between the shNS conditions. Much less variation in library size in shRUNX1 samples. DeSEQ corrects for variations in library size.

In [20]:
 
#Plot of absolute library sizes of the different samples
barplot(colSums(countData))
 
Checking for correlation in gene expression between different samples

Checking for correlation in gene expression between different samples

 
Gene expression varies less in samples from the same experimental condition

Gene expression varies less in samples from the same experimental condition

In [21]:
 
options(repr.plot.width=8, repr.plot.height=8)
plot(data.frame(log10(counts(dds))), cex=0.1, col=alpha("black", 0.4))
 
To reduce the large variability at low expression levels a log transformation was performed.

To reduce the large variability at low expression levels a log transformation was performed.

In [22]:
 
rld <- rlogTransformation(dds, blind=TRUE)
​
In [23]:
 
options(repr.plot.width=8, repr.plot.height=8)
plot(data.frame(assay(rld)), cex=0.1, col=alpha("green", 0.4))
In [33]:
 
plotPCA(rld, intgroup=c("condition"))
       
 
Making a MA plot to visualize significantly differentialy expressed genes

Making a MA plot to visualize significantly differentialy expressed genes

In [25]:
 
options(repr.plot.width=8, repr.plot.height=6)
plotMA(dds,ylim=c(-3,3))
 
Plots log2fold change vs mean expression. Significant differentially expressed genes are shown in red. 

Plots log2fold change vs mean expression. Significant differentially expressed genes are shown in red.

 
Exporting the results of DESeq analysis

Exporting the results of DESeq analysis

In [44]:
 
res <- results(dds)
res <- res[order(res$log2FoldChange),]
head(res)
#Ordering the results according to log2foldchange
log2 fold change (MAP): condition shRUNX1 vs shNS 
Wald test p-value: condition shRUNX1 vs shNS 
DataFrame with 6 rows and 6 columns
        baseMean log2FoldChange     lfcSE       stat       pvalue         padj
       <numeric>      <numeric> <numeric>  <numeric>    <numeric>    <numeric>
CYP1A1  69.32013      -4.700095 0.3563651 -13.188988 1.015396e-39 2.541601e-37
PCSK2   69.91344      -4.376865 0.3415849 -12.813402 1.379511e-37 3.015299e-35
MME    248.48050      -3.003275 0.2448537 -12.265589 1.386007e-34 2.560649e-32
MMP13   58.59528      -2.953780 0.2861810 -10.321368 5.641329e-25 5.273963e-23
TPM2    57.97398      -2.846650 0.2900655  -9.813820 9.818026e-23 7.894608e-21
CHKB    12.77972      -2.670959 0.4457153  -5.992521 2.066125e-09 3.685539e-08
In [45]:
 
res.sign <- res[(!is.na(res$padj)) & (res$padj < 0.05),]
dim(res.sign)
#Counting the number of significantly expressed genes, not including NA 
  1. 5395
  2. 6
In [46]:
 
write.table(res, "DeSEQRUNX1logfc.results.tsv", sep="\t", col.names=NA, quote=FALSE)
#Exporting the results as .tsv file
In [40]:
 
barplot(assay(rld)["GLA",])
#Visualizing the expression levels of a specific gene within the different samples
In [ ]:
 
​