# DESeq
​
#### Note: The same was done for bone marrow files (files can be found in /mnt/storage/r0304818/RNAseqgroepswerk/)

DESeq

Note: The same was done for bone marrow files (files can be found in /mnt/storage/r0304818/RNAseqgroepswerk/)

In [9]:
 
# RNAseq analysis workflow using DESeq2:
# Get the DEseq2 and scales packages out of the library (needs to be in R): 
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 [1]:
 
# Ensure we are in the correct directory:
    # setwd(): returns an absolute filepath representing the current working directory of the R process
        # path.expand(): expand a path name, for example by replacing a leading tilde by the user's home directory. 
setwd(path.expand("~/data/RNAseqgroepswerk//"))
In [2]:
 
# Now we define the the file we created, containing the raw gene counts. 
matrixFile = path.expand("~/data/RNAseqgroepswerk//all.geneCML.counts2.tsv")
In [3]:
 
# Put the data into a matrix:
    # as.matrix(): attempts to turn its argument into a matrix
        # read.csv(): Reads a file in table format and creates a data frame from it, with cases corresponidng to lines
        # and variables to fields in the file.
            # sep= : the field separator character. Values on each line of the file are separated by this character (\t)
            # row.names= : a vector of row names. This can be a vector giving the actual row names, or a single number
            # giving the comun of the table which contains the row names, or character string giving the name of the 
            # table column containing the row names.
CMLcountData2 <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))
head(CMLcountData2)
CML15iCD34ctrl.bamCML15iCD34Imatinib.bamCML17iCD34ctrl.bamCML17iCD34Imatinib.bam
MIR1302-11 0 0 0 0
FAM138A 0 0 0 0
OR4F5 0 0 0 0
RP11-34P13.7 0 3 0 2
RP11-34P13.8 0 0 0 0
AL627309.1150188204176
In [4]:
 
# The column names don't need the .bam suffix, so we'll make it a bit more appealing: 
    # c(): is a generic function which combines its arguments, all arguments are coerced to a common type which is the
    # type of the returned value, and all attributes except names are removed.
    # colnames(): Take the names of the columns of the matrix (countData) and on this we will use the c() function.
colnames(CMLcountData2) <- c("CML15NT", "CML15T","CML17NT", "CML17T")
head(CMLcountData2)
CML15NTCML15TCML17NTCML17T
MIR1302-11 0 0 0 0
FAM138A 0 0 0 0
OR4F5 0 0 0 0
RP11-34P13.7 0 3 0 2
RP11-34P13.8 0 0 0 0
AL627309.1150188204176
In [5]:
 
# Now we'll define the experimental conditions of the samples (treated (T)) or not treated (NT)):
    # factor(c) : The function 'factor' is used to encode a vector as a factor.
​
CMLcondition2 <- factor(c("NT", "T", "NT", "T"))
print(CMLcondition2)
[1] NT T  NT T 
Levels: NT T
In [7]:
 
# The order of the levels is important. Because T is first we will be comparing: T/NT. 
# So positive log fold change values are up in the non-treated samples.
?data.frame
In [10]:
 
#Now we prepare a dataframe which has the names and conditions. This will be fed to DESeq2. (!order has to be the same!)
CMLcolData2 <- data.frame(sampleName = colnames(CMLcountData2),
                      condition = CMLcondition2)
CMLcolData2
sampleNamecondition
CML15NTNT
CML15T T
CML17NTNT
CML17T T
In [11]:
 
# Here we create a DESeq DESeqDataSet object for subsequent analysis:
    # DESeqDataSetFromMatrix:  The DESeqDataSet is a subclass of SummarizedExperiment, used to store the input values,
    # intermediate calculations and results of an analysis of differential expression.
​
CMLdds2 <- DESeqDataSetFromMatrix(countData = CMLcountData2,
                              colData = CMLcolData2,
                              design = ~ condition)
#we need to do this to ensure the column names are correct.
colnames(CMLdds2) <- colnames(CMLcountData2)
In [12]:
 
CMLdds2
class: DESeqDataSet 
dim: 41863 4 
exptData(0):
assays(1): counts
rownames(41863): MIR1302-11 FAM138A ... AC007965.1 RNU6-1314P
rowRanges metadata column names(0):
colnames(4): CML15NT CML15T CML17NT CML17T
colData names(2): sampleName condition
In [13]:
 
# By comparing the condition factor in the dds object to the column names, we can confirm that the order is still correct
CMLdds2$condition
  1. NT
  2. T
  3. NT
  4. T
In [14]:
 
# Run the differential expression:
​
# one function within `DESeq2` runs all steps required: 
    # DESeq : Differential expression analysis based on negative binomial distribution: This function performs a default
    # analysis through the steps: 1) estimation of size factors 2) estimation of dispersion 3) negative ninomial GLM
    # fitting and Wald statistics.
​
CMLdds2 <- DESeq(CMLdds2)
estimating size factors
estimating dispersions
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
In [15]:
 
# Quality Control:
# DESeq2 estimates a factor to correct for the library size:
​
options(repr.plot.width=9, repr.plot.height=5)
barplot(sizeFactors(CMLdds2))
​
# Gene expression upregulation found in samples from non-treated CML15 were different from those found in CML17.
In [16]:
 
barplot(colSums(CMLcountData2))
In [17]:
 
options(repr.plot.width=7, repr.plot.height=7)
plot(data.frame(log10(counts(CMLdds2))), cex=0.1, col=alpha("black", 0.4))
In [18]:
 
rld2 <- rlogTransformation(CMLdds2, blind=TRUE)
In [19]:
 
options(repr.plot.width=7, repr.plot.height=7)
plot(data.frame(assay(rld2)), cex=0.1, col=alpha("black", 0.4))
In [20]:
 
plotPCA(rld2, intgroup=c("condition"))
In [21]:
 
options(repr.plot.width=5, repr.plot.height=4)
plotMA(CMLdds2,ylim=c(-3,3))
In [22]:
 
CMLres2 <- results(CMLdds2)
CMLres2 <- CMLres2[order(CMLres2$padj),]
head(CMLres2)
# $ means 'give me the column' 
log2 fold change (MAP): condition T vs NT 
Wald test p-value: condition T vs NT 
DataFrame with 6 rows and 6 columns
         baseMean log2FoldChange     lfcSE      stat       pvalue         padj
        <numeric>      <numeric> <numeric> <numeric>    <numeric>    <numeric>
C3      2263.6420       2.573103 0.1507173  17.07239 2.382526e-65 3.130401e-61
ALOX5AP 2705.4697       1.825819 0.1441919  12.66242 9.550473e-37 6.274183e-33
LRP1    2117.2048       1.934905 0.1568881  12.33302 6.014658e-35 2.634220e-31
APOE     827.2971       2.313822 0.1893724  12.21837 2.480077e-34 8.146432e-31
C3AR1   1534.4706       1.394743 0.1197544  11.64670 2.385236e-31 6.267924e-28
CD9      768.7049       1.868242 0.1631178  11.45333 2.262863e-30 4.955292e-27
In [23]:
 
CMLres2.sign <- CMLres2[(!is.na(CMLres2$padj)) & (CMLres2$padj < 0.05),]
dim(CMLres2.sign)
  1. 2365
  2. 6
In [24]:
 
write.table(CMLres2, "deseq2.CMLresults.tsv", sep="\t", col.names=NA, quote=FALSE)
In [29]:
 
options(repr.plot.width=9, repr.plot.height=5)
barplot(assay(rld2)["OLFM4",])
# GPR110 is strongly upregulated
# log scale!
# if the difference between S1 and S2 is large you better look at another gene, because you cannot be sure which one is right./
# normally NS1 and NS2 should be the same and S1 and S2 as well. 
In [31]:
 
options(repr.plot.width=9, repr.plot.height=5)
barplot(assay(rld2)["SMAD7",])
In [34]:
 
options(repr.plot.width=9, repr.plot.height=5)
barplot(assay(rld2)["ALOX15B",])
In [ ]:
 
# Upregulated genes mentioned in the article (OLFM4, ALOX15B and SMAD7) were also upregulated in our differential
# gene expression analysis.
In [ ]:
 
​