# 1. Calculation of differential expression between WT and KO samples

1. Calculation of differential expression between WT and KO samples

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 [5]:
 
#setting working directory
setwd("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq")
getwd()
'/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq'
 
## 1.1 Loading Countfile and preparing it for DeSEQ

1.1 Loading Countfile and preparing it for DeSEQ

In [6]:
 
#Loading gene count file
matrixFile = path.expand("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq/all.gene.counts.tsv")
In [7]:
 
#converting gene count matrix to the correct format
countData <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))
head(countData)
SRR3737439.bamSRR3737440.bamSRR3737441.bamSRR3737442.bamSRR3737443.bamSRR3737444.bam
Gm16088000000
Gm26206000000
Xkr4121302
Gm1992020000
Gm27396000000
Rp1000000
In [8]:
 
#Changing collumn headings to biologicaly relevant sample names
colnames(countData) <- c("Sox2_WT_stomach_1", "Sox2_WT_stomach_2", "Sox2_WT_stomach_3", "Sox2_KO_stomach_1", "Sox2_KO_stomach_2", "Sox2_KO_stomach_3")
head(countData)
Sox2_WT_stomach_1Sox2_WT_stomach_2Sox2_WT_stomach_3Sox2_KO_stomach_1Sox2_KO_stomach_2Sox2_KO_stomach_3
Gm16088000000
Gm26206000000
Xkr4121302
Gm1992020000
Gm27396000000
Rp1000000
 
## 1.2 Preparing input for DeSEQ

1.2 Preparing input for DeSEQ

In [9]:
 
#Input of sample information in condition variable required as input for DeSEQ
condition <- factor(c("WT", "WT", "WT", "KO", "KO", "KO"))
print(condition)
[1] WT WT WT KO KO KO
Levels: KO WT
In [10]:
 
#Creating colData data frame from collumn namens of countData and the condition variable, to be used as input for DeSEQ
colData <- data.frame(sampleName = colnames(countData),
                      condition = condition)
colData
sampleNamecondition
Sox2_WT_stomach_1WT
Sox2_WT_stomach_2WT
Sox2_WT_stomach_3WT
Sox2_KO_stomach_1KO
Sox2_KO_stomach_2KO
Sox2_KO_stomach_3KO
In [11]:
 
#Preparing DESeqDataSet(dds) for DeSEQ
dds <- DESeqDataSetFromMatrix(countData = countData,
                              colData = colData,
                              design = ~ condition)
colnames(dds) <- colnames(countData)
In [12]:
 
#Checking if all prior commands worked correctly
dds
#confirm correct order of conditions
dds$condition
class: DESeqDataSet 
dim: 41255 6 
exptData(0):
assays(1): counts
rownames(41255): Gm16088 Gm26206 ... Vmn2r122 Cd99
rowRanges metadata column names(0):
colnames(6): Sox2_WT_stomach_1 Sox2_WT_stomach_2 ... Sox2_KO_stomach_2
  Sox2_KO_stomach_3
colData names(2): sampleName condition
  1. WT
  2. WT
  3. WT
  4. KO
  5. KO
  6. KO
 
## 1.3 DESeq

1.3 DESeq

 
The betaPrior=FALSE argument is added, because without it the MA plot (provided below) proved erronous without it (see image). The DESeq bioconductor manual provided this argument as a solution, see figure 18 in the manual (http://tinyurl.com/zzbmr5z)

The betaPrior=FALSE argument is added, because without it the MA plot (provided below) proved erronous without it (see image). The DESeq bioconductor manual provided this argument as a solution, see figure 18 in the manual (http://tinyurl.com/zzbmr5z)

In [13]:
 
dds_BetaP <- DESeq(dds, betaPrior=FALSE)
estimating size factors
estimating dispersions
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
In [14]:
 
#Export of results from dds_BetaP to resBetaP
resBetaP <- results(dds_BetaP)
resBetaP <- resBetaP[order(resBetaP$padj),]
head(resBetaP)
log2 fold change (MLE): condition WT vs KO 
Wald test p-value: condition WT vs KO 
DataFrame with 6 rows and 6 columns
          baseMean log2FoldChange     lfcSE       stat       pvalue
         <numeric>      <numeric> <numeric>  <numeric>    <numeric>
Sox2      335.1898       4.908697 0.2651380  18.513744 1.599841e-76
Esr1      152.3786      -3.581911 0.2761780 -12.969573 1.820408e-38
Atp6v0d2  678.9927      -3.002065 0.2463867 -12.184364 3.765789e-34
Gsdmc2    190.1434       2.970243 0.2681350  11.077414 1.614692e-28
Tph1      654.0020       2.527675 0.2535660   9.968509 2.093486e-23
Stc2      889.7713       1.547183 0.1883615   8.213900 2.141171e-16
                 padj
            <numeric>
Sox2     3.138088e-72
Esr1     1.785365e-34
Atp6v0d2 2.462198e-30
Gsdmc2   7.918047e-25
Tph1     8.212747e-20
Stc2     6.999844e-13
 
Checking differential expression of Sox2 manually

Checking differential expression of Sox2 manually

In [15]:
 
barplot(assay(dds_BetaP)["Sox2",], xaxt='n')
axis(side=1, at = seq(0.5, 7, 1.25), labels=colnames(countData), las=2, cex.axis = 0.45)
 
We see strong loss of Sox2 expression. This is a good preliminary result as it validates the efficacy of the knock out procedure.

We see strong loss of Sox2 expression. This is a good preliminary result as it validates the efficacy of the knock out procedure.

 
## 1.4 Quality control and normalization

1.4 Quality control and normalization

 
estimate a factor to check for possible effect of library size using barplot

estimate a factor to check for possible effect of library size using barplot

In [16]:
 
options(repr.plot.width=4, repr.plot.height=3)
barplot(sizeFactors(dds_BetaP))
 
There appears to be some difference in library size, however it appears minimal.

There appears to be some difference in library size, however it appears minimal.

 
sum of all reads per sample of the raw data

sum of all reads per sample of the raw data

In [17]:
 
barplot(colSums(countData))
 
There appears to be some difference in read count, however it is not extremely siginificant.

There appears to be some difference in read count, however it is not extremely siginificant.

 
scatter plot of sample vs sample will to check how the samples compare

scatter plot of sample vs sample will to check how the samples compare

In [18]:
 
options(repr.plot.width=5, repr.plot.height=5)
plot(data.frame(log10(counts(dds_BetaP))), cex=0.1, col=alpha("black", 0.4))
 
Plots show increased variation for genes with lower expression, indicating that normalization might be required.

Plots show increased variation for genes with lower expression, indicating that normalization might be required.

 
Normalize for library size by log transformation of the data

Normalize for library size by log transformation of the data

In [19]:
 
rld <- rlogTransformation(dds_BetaP, blind=TRUE)
In [20]:
 
#Checking of the effect of normalization on variation
options(repr.plot.width=5, repr.plot.height=5)
plot(data.frame(assay(rld)), cex=0.1, col=alpha("black", 0.4))
 
Now the variation stays more or less constant for all, meaning that normalisation of the data was successful

Now the variation stays more or less constant for all, meaning that normalisation of the data was successful

In [21]:
 
#A PCA plot allows us to check variation between samples.
plotPCA(rld, intgroup=c("condition"))
 
Ko samples cluster nicely together, WT samples appear more diffuse. However this is not necessarily a problem as it is expected
that WT samples are more variable. The limited number of samples also prevents us from making any declaration on outliers.

Ko samples cluster nicely together, WT samples appear more diffuse. However this is not necessarily a problem as it is expected that WT samples are more variable. The limited number of samples also prevents us from making any declaration on outliers.

 
## 1.5 Visualization of differential expression via MA plot

1.5 Visualization of differential expression via MA plot

In [22]:
 
#Plotting the mean expression vs the log fold change allows identification of significantly differentially expressed genes.
#Differentially expressed genes will be marked in red.
options(repr.plot.width=5, repr.plot.height=4)
plotMA(dds_BetaP,ylim=c(-10,10))
 
The MA plot shows significantly differentially expressed genes as marked in red.
The betaPrior=FALSE argument ensures normal shape of the MA plot, as dicussed above.

The MA plot shows significantly differentially expressed genes as marked in red. The betaPrior=FALSE argument ensures normal shape of the MA plot, as dicussed above.

 
## 1.6 Selction of significantly differentially expressed genes and export to file

1.6 Selction of significantly differentially expressed genes and export to file

In [23]:
 
#Selection of genes differentially expressed on the 5% statistical significance level.
res.sign <- resBetaP[(!is.na(resBetaP$padj)) & (resBetaP$padj < 0.05),]
dim(res.sign)
head(res.sign)
  1. 64
  2. 6
log2 fold change (MLE): condition WT vs KO 
Wald test p-value: condition WT vs KO 
DataFrame with 6 rows and 6 columns
          baseMean log2FoldChange     lfcSE       stat       pvalue
         <numeric>      <numeric> <numeric>  <numeric>    <numeric>
Sox2      335.1898       4.908697 0.2651380  18.513744 1.599841e-76
Esr1      152.3786      -3.581911 0.2761780 -12.969573 1.820408e-38
Atp6v0d2  678.9927      -3.002065 0.2463867 -12.184364 3.765789e-34
Gsdmc2    190.1434       2.970243 0.2681350  11.077414 1.614692e-28
Tph1      654.0020       2.527675 0.2535660   9.968509 2.093486e-23
Stc2      889.7713       1.547183 0.1883615   8.213900 2.141171e-16
                 padj
            <numeric>
Sox2     3.138088e-72
Esr1     1.785365e-34
Atp6v0d2 2.462198e-30
Gsdmc2   7.918047e-25
Tph1     8.212747e-20
Stc2     6.999844e-13
 
Only 64 genes are differentially expressed. This low effect of Sox2KO on gene expression is in agreement with the lack of a microscopic phenotype, as shown in figure 2 of the source paper.

Only 64 genes are differentially expressed. This low effect of Sox2KO on gene expression is in agreement with the lack of a microscopic phenotype, as shown in figure 2 of the source paper.

In [25]:
 
#save results to file
write.table(resBetaP, "deseq_results.tsv", sep="\t", col.names=NA, quote=FALSE)
write.table(res.sign, "deseq_results_sign_BetaP.tsv", sep="\t", col.names=NA, quote=FALSE)
 
# 2. Checking possible compensation for loss of Sox2 activity by Sox family members

2. Checking possible compensation for loss of Sox2 activity by Sox family members

 
Could lack of effect, only 64 differentially expressed genes, be due to compensation by other genes from the sox family?
Investigate by checking their differential expression

Could lack of effect, only 64 differentially expressed genes, be due to compensation by other genes from the sox family? Investigate by checking their differential expression

In [26]:
 
library(stringr)
In [27]:
 
#count how many sox family members are present in results
sum(str_count(rownames(resBetaP), "Sox"))
27
In [28]:
 
#Make vector containing names of these family members
NamesSoxFamily <- c(rownames(resBetaP)[grep("Sox", rownames(resBetaP))])
NamesSoxFamily
  1. 'Sox2'
  2. 'Sox2ot'
  3. 'Sox17'
  4. 'Sox13'
  5. 'Sox12'
  6. 'Sox18'
  7. 'Sox5'
  8. 'Sox6'
  9. 'Sox6os'
  10. 'Sox7'
  11. 'Sox21'
  12. 'Sox30'
  13. 'Sox9'
  14. 'Sox4'
  15. 'Sox11'
  16. 'Sox10'
  17. 'Sox8'
  18. 'Sox3'
  19. 'Sox5os1'
  20. 'Sox5os2'
  21. 'Sox5it'
  22. 'Sox5os3'
  23. 'Sox5os4'
  24. 'Sox5os5'
  25. 'Sox1'
  26. 'Sox14'
  27. 'Sox15'
In [29]:
 
#store expression of Sox family in new matrix
SoxFamily <- resBetaP[NamesSoxFamily,]
head(SoxFamily)
dim(SoxFamily)
log2 fold change (MLE): condition WT vs KO 
Wald test p-value: condition WT vs KO 
DataFrame with 6 rows and 6 columns
         baseMean log2FoldChange     lfcSE        stat       pvalue
        <numeric>      <numeric> <numeric>   <numeric>    <numeric>
Sox2    335.18979     4.90869721 0.2651380 18.51374418 1.599841e-76
Sox2ot   37.67070    -1.74962657 0.3890449 -4.49723597 6.884257e-06
Sox17    89.99057    -0.18324094 0.3586401 -0.51093269 6.093982e-01
Sox13  1790.42259     0.31316213 0.1816917  1.72359107 8.478169e-02
Sox12   204.44087     0.01745866 0.2352892  0.07420083 9.408506e-01
Sox18   259.88350     0.03236683 0.3634347  0.08905818 9.290357e-01
               padj
          <numeric>
Sox2   3.138088e-72
Sox2ot 3.000771e-03
Sox17  9.999885e-01
Sox13  9.999885e-01
Sox12  9.999885e-01
Sox18  9.999885e-01
  1. 27
  2. 6
In [30]:
 
#Check for significance in SoxFamily
SoxFamily.sign <- SoxFamily[(!is.na(SoxFamily$padj)) & (SoxFamily$padj < 0.05),]
dim(SoxFamily.sign)
  1. 2
  2. 6
In [31]:
 
#Which Sox genes are differentially expressed
rownames(SoxFamily.sign)
  1. 'Sox2'
  2. 'Sox2ot'
 
The only member from the sox family that is differentially expressed is Sox2. The ohter Sox genes are not differentially expressed, making it highly unlikely that they are compensating for Sox2 activity in the KO. Confirming the lack of a phenotype in the Sox2 KO observed microscopically is not due to compensation by its family members.

The only member from the sox family that is differentially expressed is Sox2. The ohter Sox genes are not differentially expressed, making it highly unlikely that they are compensating for Sox2 activity in the KO. Confirming the lack of a phenotype in the Sox2 KO observed microscopically is not due to compensation by its family members.

 
# 3. Generation of the rank list file

3. Generation of the rank list file

In [32]:
 
getwd()
'/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq'
In [34]:
 
setwd("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq")
list.files()
  1. 'all.counts'
  2. 'all.counts.summary'
  3. 'all.gene.counts'
  4. 'all.gene.counts-RNAseq-Sox2.tsv'
  5. 'all.gene.counts.tsv'
  6. 'all.genedata.tsv'
  7. 'deseq_results_sign_BetaP.tsv'
  8. 'deseq_results.tsv'
  9. 'Mus_musculus.GRCm38.76.chr.gtf'
  10. 'SRR3737439.bam'
  11. 'SRR3737439.bam.bai'
  12. 'SRR3737439.fastq'
  13. 'SRR3737439_fastqc'
  14. 'SRR3737439_fastqc.zip'
  15. 'SRR3737439.sra'
  16. 'SRR3737440.bam'
  17. 'SRR3737440.bam.bai'
  18. 'SRR3737440_fastqc'
  19. 'SRR3737440_fastqc.zip'
  20. 'SRR3737440.sra'
  21. 'SRR3737441.bam'
  22. 'SRR3737441.bam.bai'
  23. 'SRR3737441_fastqc'
  24. 'SRR3737441_fastqc.zip'
  25. 'SRR3737441.sra'
  26. 'SRR3737442.bam'
  27. 'SRR3737442.bam.bai'
  28. 'SRR3737442_fastqc'
  29. 'SRR3737442_fastqc.zip'
  30. 'SRR3737442.sra'
  31. 'SRR3737443.bam'
  32. 'SRR3737443.bam.bai'
  33. 'SRR3737443_fastqc'
  34. 'SRR3737443_fastqc.zip'
  35. 'SRR3737443.sra'
  36. 'SRR3737444.bam'
  37. 'SRR3737444.bam.bai'
  38. 'SRR3737444_fastqc'
  39. 'SRR3737444_fastqc.zip'
  40. 'SRR3737444.genedata.tsv'
  41. 'SRR3737444.sra'
  42. 'STAR.SRR3737439.Log.final.out'
  43. 'STAR.SRR3737439.Log.out'
  44. 'STAR.SRR3737439.Log.progress.out'
  45. 'STAR.SRR3737439.SJ.out.tab'
  46. 'STAR.SRR3737440.Log.final.out'
  47. 'STAR.SRR3737440.Log.out'
  48. 'STAR.SRR3737440.Log.progress.out'
  49. 'STAR.SRR3737440.SJ.out.tab'
  50. 'STAR.SRR3737441.Log.final.out'
  51. 'STAR.SRR3737441.Log.out'
  52. 'STAR.SRR3737441.Log.progress.out'
  53. 'STAR.SRR3737441.SJ.out.tab'
  54. 'STAR.SRR3737442.Log.final.out'
  55. 'STAR.SRR3737442.Log.out'
  56. 'STAR.SRR3737442.Log.progress.out'
  57. 'STAR.SRR3737442.SJ.out.tab'
  58. 'STAR.SRR3737443.Log.final.out'
  59. 'STAR.SRR3737443.Log.out'
  60. 'STAR.SRR3737443.Log.progress.out'
  61. 'STAR.SRR3737443.SJ.out.tab'
  62. 'STAR.SRR3737444.Log.final.out'
  63. 'STAR.SRR3737444.Log.out'
  64. 'STAR.SRR3737444.Log.progress.out'
  65. 'STAR.SRR3737444.SJ.out.tab'
 
deseq_results_NoBetaPrior_Numbers.txt was created by converting numbers from European writing style using a "," as decimal mark to the American style using a "." decimal mark. This was done using the advanced options menu in Excel. We also added "_Numbers" to make the distinction clear.

deseq_results_NoBetaPrior_Numbers.txt was created by converting numbers from European writing style using a "," as decimal mark to the American style using a "." decimal mark. This was done using the advanced options menu in Excel. We also added "_Numbers" to make the distinction clear.

In [35]:
 
#Read differential expression table
z<-read.table("deseq_results_NoBetaPrior_Numbers.txt",sep="\t",header=TRUE)
sapply(z, class)
#Removing NA's
row.has.na <- apply(z, 1, function(x){any(is.na(x))})
sum(row.has.na)
z_filtered <- z[!row.has.na,]
#check removal
row.has.na_2 <- apply(z_filtered, 1, function(x){any(is.na(x))})
sum(row.has.na_2)
head(z_filtered)
sapply(z_filtered, class)
​
#generate a new column that is the sign of fold change. (code from here on relied on "attatch" command)
z_filtered$fcSign=sign(z_filtered$log2FoldChange)
#generates a new column that is the negative log10 of the p-value.
z_filtered$logP=-log10(z_filtered$pvalue)
#generates a new column that is the metric score that we'll use for ranking and pathway analysis
z_filtered$metric=z_filtered$logP/z_filtered$fcSign
#makes a new table called "RankTable" that consists only of gene names and metric scores. 
RankTable<-z_filtered[,c("GeneID", "metric")]
head(RankTable)
write.table(RankTable,file="Expression_ranked_on_metricscore.rnk",quote=F,sep="\t",row.names=F)
list.files()
GeneID
'factor'
baseMean
'numeric'
log2FoldChange
'numeric'
lfcSE
'numeric'
stat
'numeric'
pvalue
'numeric'
padj
'numeric'
21640
0
GeneIDbaseMeanlog2FoldChangelfcSEstatpvaluepadj
Sox2 335.1898 4.908697 0.2651380 18.5137441.60e-76 3.14e-72
Esr1 152.3786 -3.581911 0.2761780 -12.9695731.82e-38 1.79e-34
Atp6v0d2 678.9927 -3.002065 0.2463867 -12.1843643.77e-34 2.46e-30
Gsdmc2 190.1434 2.970243 0.2681350 11.0774141.61e-28 7.92e-25
Tph1 654.0020 2.527675 0.2535660 9.9685092.09e-23 8.21e-20
Stc2 889.7713 1.547183 0.1883615 8.2139002.14e-16 7.00e-13
GeneID
'factor'
baseMean
'numeric'
log2FoldChange
'numeric'
lfcSE
'numeric'
stat
'numeric'
pvalue
'numeric'
padj
'numeric'
GeneIDmetric
Sox2 75.79588
Esr1 -37.73993
Atp6v0d2 -33.42366
Gsdmc2 27.79317
Tph1 22.67985
Stc2 15.66959
  1. 'all.counts'
  2. 'all.counts.summary'
  3. 'all.gene.counts'
  4. 'all.gene.counts-RNAseq-Sox2.tsv'
  5. 'all.gene.counts.tsv'
  6. 'all.genedata.tsv'
  7. 'deseq_results_NoBetaPrior_Numbers.txt'
  8. 'deseq_results_sign_BetaP.tsv'
  9. 'deseq_results.tsv'
  10. 'Expression_ranked_on_metricscore.rnk'
  11. 'Mus_musculus.GRCm38.76.chr.gtf'
  12. 'SRR3737439.bam'
  13. 'SRR3737439.bam.bai'
  14. 'SRR3737439.fastq'
  15. 'SRR3737439_fastqc'
  16. 'SRR3737439_fastqc.zip'
  17. 'SRR3737439.sra'
  18. 'SRR3737440.bam'
  19. 'SRR3737440.bam.bai'
  20. 'SRR3737440_fastqc'
  21. 'SRR3737440_fastqc.zip'
  22. 'SRR3737440.sra'
  23. 'SRR3737441.bam'
  24. 'SRR3737441.bam.bai'
  25. 'SRR3737441_fastqc'
  26. 'SRR3737441_fastqc.zip'
  27. 'SRR3737441.sra'
  28. 'SRR3737442.bam'
  29. 'SRR3737442.bam.bai'
  30. 'SRR3737442_fastqc'
  31. 'SRR3737442_fastqc.zip'
  32. 'SRR3737442.sra'
  33. 'SRR3737443.bam'
  34. 'SRR3737443.bam.bai'
  35. 'SRR3737443_fastqc'
  36. 'SRR3737443_fastqc.zip'
  37. 'SRR3737443.sra'
  38. 'SRR3737444.bam'
  39. 'SRR3737444.bam.bai'
  40. 'SRR3737444_fastqc'
  41. 'SRR3737444_fastqc.zip'
  42. 'SRR3737444.genedata.tsv'
  43. 'SRR3737444.sra'
  44. 'STAR.SRR3737439.Log.final.out'
  45. 'STAR.SRR3737439.Log.out'
  46. 'STAR.SRR3737439.Log.progress.out'
  47. 'STAR.SRR3737439.SJ.out.tab'
  48. 'STAR.SRR3737440.Log.final.out'
  49. 'STAR.SRR3737440.Log.out'
  50. 'STAR.SRR3737440.Log.progress.out'
  51. 'STAR.SRR3737440.SJ.out.tab'
  52. 'STAR.SRR3737441.Log.final.out'
  53. 'STAR.SRR3737441.Log.out'
  54. 'STAR.SRR3737441.Log.progress.out'
  55. 'STAR.SRR3737441.SJ.out.tab'
  56. 'STAR.SRR3737442.Log.final.out'
  57. 'STAR.SRR3737442.Log.out'
  58. 'STAR.SRR3737442.Log.progress.out'
  59. 'STAR.SRR3737442.SJ.out.tab'
  60. 'STAR.SRR3737443.Log.final.out'
  61. 'STAR.SRR3737443.Log.out'
  62. 'STAR.SRR3737443.Log.progress.out'
  63. 'STAR.SRR3737443.SJ.out.tab'
  64. 'STAR.SRR3737444.Log.final.out'
  65. 'STAR.SRR3737444.Log.out'
  66. 'STAR.SRR3737444.Log.progress.out'
  67. 'STAR.SRR3737444.SJ.out.tab'
 
## 3.1. Splitting of up and down regulated genes

3.1. Splitting of up and down regulated genes

 
Genes were split in up and down regulated genes to make further processing easier

Genes were split in up and down regulated genes to make further processing easier

 
Genes with a positive metric score correlate to upregulated genes, due to the way the differential expression was calculated.
Naturally, genes with a negative metric score correlate to downregulated genes

Genes with a positive metric score correlate to upregulated genes, due to the way the differential expression was calculated. Naturally, genes with a negative metric score correlate to downregulated genes

In [36]:
 
DownRegulated <- subset(RankTable, RankTable$metric > 0)
UpRegulated <- subset(RankTable, RankTable$metric < 0)
head(UpRegulated)
dim(UpRegulated)
head(DownRegulated)
dim(DownRegulated)
GeneIDmetric
2Esr1 -37.739929
3Atp6v0d2 -33.423659
8Hck -13.913640
9Itln1 -13.772113
12Spib -9.954677
15Sh2d6 -9.240332
  1. 9851
  2. 2
GeneIDmetric
1Sox2 75.79588
4Gsdmc2 27.79317
5Tph1 22.67985
6Stc2 15.66959
7Pcyt1b 15.57349
10Trerf1 12.36957
  1. 9764
  2. 2
In [37]:
 
write.table(UpRegulated,file="UpRegulatedgenes.rnk",quote=F,sep="\t",row.names=F)
write.table(DownRegulated,file="DownRegulatedgenes.rnk",quote=F,sep="\t",row.names=F)
list.files()
  1. 'all.counts'
  2. 'all.counts.summary'
  3. 'all.gene.counts'
  4. 'all.gene.counts-RNAseq-Sox2.tsv'
  5. 'all.gene.counts.tsv'
  6. 'all.genedata.tsv'
  7. 'deseq_results_NoBetaPrior_Numbers.txt'
  8. 'deseq_results_sign_BetaP.tsv'
  9. 'deseq_results.tsv'
  10. 'DownRegulatedgenes.rnk'
  11. 'Expression_ranked_on_metricscore.rnk'
  12. 'Mus_musculus.GRCm38.76.chr.gtf'
  13. 'SRR3737439.bam'
  14. 'SRR3737439.bam.bai'
  15. 'SRR3737439.fastq'
  16. 'SRR3737439_fastqc'
  17. 'SRR3737439_fastqc.zip'
  18. 'SRR3737439.sra'
  19. 'SRR3737440.bam'
  20. 'SRR3737440.bam.bai'
  21. 'SRR3737440_fastqc'
  22. 'SRR3737440_fastqc.zip'
  23. 'SRR3737440.sra'
  24. 'SRR3737441.bam'
  25. 'SRR3737441.bam.bai'
  26. 'SRR3737441_fastqc'
  27. 'SRR3737441_fastqc.zip'
  28. 'SRR3737441.sra'
  29. 'SRR3737442.bam'
  30. 'SRR3737442.bam.bai'
  31. 'SRR3737442_fastqc'
  32. 'SRR3737442_fastqc.zip'
  33. 'SRR3737442.sra'
  34. 'SRR3737443.bam'
  35. 'SRR3737443.bam.bai'
  36. 'SRR3737443_fastqc'
  37. 'SRR3737443_fastqc.zip'
  38. 'SRR3737443.sra'
  39. 'SRR3737444.bam'
  40. 'SRR3737444.bam.bai'
  41. 'SRR3737444_fastqc'
  42. 'SRR3737444_fastqc.zip'
  43. 'SRR3737444.genedata.tsv'
  44. 'SRR3737444.sra'
  45. 'STAR.SRR3737439.Log.final.out'
  46. 'STAR.SRR3737439.Log.out'
  47. 'STAR.SRR3737439.Log.progress.out'
  48. 'STAR.SRR3737439.SJ.out.tab'
  49. 'STAR.SRR3737440.Log.final.out'
  50. 'STAR.SRR3737440.Log.out'
  51. 'STAR.SRR3737440.Log.progress.out'
  52. 'STAR.SRR3737440.SJ.out.tab'
  53. 'STAR.SRR3737441.Log.final.out'
  54. 'STAR.SRR3737441.Log.out'
  55. 'STAR.SRR3737441.Log.progress.out'
  56. 'STAR.SRR3737441.SJ.out.tab'
  57. 'STAR.SRR3737442.Log.final.out'
  58. 'STAR.SRR3737442.Log.out'
  59. 'STAR.SRR3737442.Log.progress.out'
  60. 'STAR.SRR3737442.SJ.out.tab'
  61. 'STAR.SRR3737443.Log.final.out'
  62. 'STAR.SRR3737443.Log.out'
  63. 'STAR.SRR3737443.Log.progress.out'
  64. 'STAR.SRR3737443.SJ.out.tab'
  65. 'STAR.SRR3737444.Log.final.out'
  66. 'STAR.SRR3737444.Log.out'
  67. 'STAR.SRR3737444.Log.progress.out'
  68. 'STAR.SRR3737444.SJ.out.tab'
  69. 'UpRegulatedgenes.rnk'
 
## 3.2. All GeneIDs were changed to all caps to be used as input for GSEA

3.2. All GeneIDs were changed to all caps to be used as input for GSEA

In [38]:
 
#All GeneIDs have to be made upper case in order to use them as input for GSEA
sapply(RankTable, class)
#Change GeneID from facotr to character
RankTable$GeneID <- as.character(RankTable$GeneID)
head(RankTable)
sapply(RankTable, class)
#Make all GeneIDs upper case
RankTable <- data.frame(lapply(RankTable, function(v) {
  if (is.character(v)) return(toupper(v))
  else return(v)
}))
head(RankTable)
#Export as new file
write.table(RankTable,file="Expression_ranked_on_metricscore_ALLCAPS.rnk",quote=F,sep="\t",row.names=F)
list.files()
GeneID
'factor'
metric
'numeric'
GeneIDmetric
Sox2 75.79588
Esr1 -37.73993
Atp6v0d2 -33.42366
Gsdmc2 27.79317
Tph1 22.67985
Stc2 15.66959
GeneID
'character'
metric
'numeric'
GeneIDmetric
SOX2 75.79588
ESR1 -37.73993
ATP6V0D2 -33.42366
GSDMC2 27.79317
TPH1 22.67985
STC2 15.66959
  1. 'all.counts'
  2. 'all.counts.summary'
  3. 'all.gene.counts'
  4. 'all.gene.counts-RNAseq-Sox2.tsv'
  5. 'all.gene.counts.tsv'
  6. 'all.genedata.tsv'
  7. 'deseq_results_NoBetaPrior_Numbers.txt'
  8. 'deseq_results_sign_BetaP.tsv'
  9. 'deseq_results.tsv'
  10. 'DownRegulatedgenes.rnk'
  11. 'Expression_ranked_on_metricscore_ALLCAPS.rnk'
  12. 'Expression_ranked_on_metricscore.rnk'
  13. 'Mus_musculus.GRCm38.76.chr.gtf'
  14. 'SRR3737439.bam'
  15. 'SRR3737439.bam.bai'
  16. 'SRR3737439.fastq'
  17. 'SRR3737439_fastqc'
  18. 'SRR3737439_fastqc.zip'
  19. 'SRR3737439.sra'
  20. 'SRR3737440.bam'
  21. 'SRR3737440.bam.bai'
  22. 'SRR3737440_fastqc'
  23. 'SRR3737440_fastqc.zip'
  24. 'SRR3737440.sra'
  25. 'SRR3737441.bam'
  26. 'SRR3737441.bam.bai'
  27. 'SRR3737441_fastqc'
  28. 'SRR3737441_fastqc.zip'
  29. 'SRR3737441.sra'
  30. 'SRR3737442.bam'
  31. 'SRR3737442.bam.bai'
  32. 'SRR3737442_fastqc'
  33. 'SRR3737442_fastqc.zip'
  34. 'SRR3737442.sra'
  35. 'SRR3737443.bam'
  36. 'SRR3737443.bam.bai'
  37. 'SRR3737443_fastqc'
  38. 'SRR3737443_fastqc.zip'
  39. 'SRR3737443.sra'
  40. 'SRR3737444.bam'
  41. 'SRR3737444.bam.bai'
  42. 'SRR3737444_fastqc'
  43. 'SRR3737444_fastqc.zip'
  44. 'SRR3737444.genedata.tsv'
  45. 'SRR3737444.sra'
  46. 'STAR.SRR3737439.Log.final.out'
  47. 'STAR.SRR3737439.Log.out'
  48. 'STAR.SRR3737439.Log.progress.out'
  49. 'STAR.SRR3737439.SJ.out.tab'
  50. 'STAR.SRR3737440.Log.final.out'
  51. 'STAR.SRR3737440.Log.out'
  52. 'STAR.SRR3737440.Log.progress.out'
  53. 'STAR.SRR3737440.SJ.out.tab'
  54. 'STAR.SRR3737441.Log.final.out'
  55. 'STAR.SRR3737441.Log.out'
  56. 'STAR.SRR3737441.Log.progress.out'
  57. 'STAR.SRR3737441.SJ.out.tab'
  58. 'STAR.SRR3737442.Log.final.out'
  59. 'STAR.SRR3737442.Log.out'
  60. 'STAR.SRR3737442.Log.progress.out'
  61. 'STAR.SRR3737442.SJ.out.tab'
  62. 'STAR.SRR3737443.Log.final.out'
  63. 'STAR.SRR3737443.Log.out'
  64. 'STAR.SRR3737443.Log.progress.out'
  65. 'STAR.SRR3737443.SJ.out.tab'
  66. 'STAR.SRR3737444.Log.final.out'
  67. 'STAR.SRR3737444.Log.out'
  68. 'STAR.SRR3737444.Log.progress.out'
  69. 'STAR.SRR3737444.SJ.out.tab'
  70. 'UpRegulatedgenes.rnk'
 
# 4. Analysis of location of Sox2 binding peaks in the WT sample

4. Analysis of location of Sox2 binding peaks in the WT sample

 
## 4.1. Conversion of narrow peak file to wanted format

4.1. Conversion of narrow peak file to wanted format

In [67]:
 
setwd("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq")
getwd()
list.files()
'/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq'
  1. 'all.counts'
  2. 'all.counts.summary'
  3. 'all.gene.counts'
  4. 'all.gene.counts-RNAseq-Sox2.tsv'
  5. 'all.gene.counts.tsv'
  6. 'all.genedata.tsv'
  7. 'deseq_results_NoBetaPrior_Numbers.txt'
  8. 'deseq_results_sign_BetaP.tsv'
  9. 'deseq_results.tsv'
  10. 'DownRegulatedgenes.rnk'
  11. 'Expression_ranked_on_metricscore_ALLCAPS.rnk'
  12. 'Expression_ranked_on_metricscore.rnk'
  13. 'GREAT_outputWT.csv'
  14. 'Mus_musculus.GRCm38.76.chr.gtf'
  15. 'SRR3737439.bam'
  16. 'SRR3737439.bam.bai'
  17. 'SRR3737439.fastq'
  18. 'SRR3737439_fastqc'
  19. 'SRR3737439_fastqc.zip'
  20. 'SRR3737439.sra'
  21. 'SRR3737440.bam'
  22. 'SRR3737440.bam.bai'
  23. 'SRR3737440_fastqc'
  24. 'SRR3737440_fastqc.zip'
  25. 'SRR3737440.sra'
  26. 'SRR3737441.bam'
  27. 'SRR3737441.bam.bai'
  28. 'SRR3737441_fastqc'
  29. 'SRR3737441_fastqc.zip'
  30. 'SRR3737441.sra'
  31. 'SRR3737442.bam'
  32. 'SRR3737442.bam.bai'
  33. 'SRR3737442_fastqc'
  34. 'SRR3737442_fastqc.zip'
  35. 'SRR3737442.sra'
  36. 'SRR3737443.bam'
  37. 'SRR3737443.bam.bai'
  38. 'SRR3737443_fastqc'
  39. 'SRR3737443_fastqc.zip'
  40. 'SRR3737443.sra'
  41. 'SRR3737444.bam'
  42. 'SRR3737444.bam.bai'
  43. 'SRR3737444_fastqc'
  44. 'SRR3737444_fastqc.zip'
  45. 'SRR3737444.genedata.tsv'
  46. 'SRR3737444.sra'
  47. 'STAR.SRR3737439.Log.final.out'
  48. 'STAR.SRR3737439.Log.out'
  49. 'STAR.SRR3737439.Log.progress.out'
  50. 'STAR.SRR3737439.SJ.out.tab'
  51. 'STAR.SRR3737440.Log.final.out'
  52. 'STAR.SRR3737440.Log.out'
  53. 'STAR.SRR3737440.Log.progress.out'
  54. 'STAR.SRR3737440.SJ.out.tab'
  55. 'STAR.SRR3737441.Log.final.out'
  56. 'STAR.SRR3737441.Log.out'
  57. 'STAR.SRR3737441.Log.progress.out'
  58. 'STAR.SRR3737441.SJ.out.tab'
  59. 'STAR.SRR3737442.Log.final.out'
  60. 'STAR.SRR3737442.Log.out'
  61. 'STAR.SRR3737442.Log.progress.out'
  62. 'STAR.SRR3737442.SJ.out.tab'
  63. 'STAR.SRR3737443.Log.final.out'
  64. 'STAR.SRR3737443.Log.out'
  65. 'STAR.SRR3737443.Log.progress.out'
  66. 'STAR.SRR3737443.SJ.out.tab'
  67. 'STAR.SRR3737444.Log.final.out'
  68. 'STAR.SRR3737444.Log.out'
  69. 'STAR.SRR3737444.Log.progress.out'
  70. 'STAR.SRR3737444.SJ.out.tab'
  71. 'UpRegulatedgenes.rnk'
 
The output file obtained from GREAT was named "GREAT_outputWT.csv". Excel was used to preprocess the file, the header and brackets were removed. The file was then uploaded in the folder: "/mnt/storage/r0372900/jupyternotebooks/Assignment_Bioinformatics2/ChIPseq"

The output file obtained from GREAT was named "GREAT_outputWT.csv". Excel was used to preprocess the file, the header and brackets were removed. The file was then uploaded in the folder: "/mnt/storage/r0372900/jupyternotebooks/Assignment_Bioinformatics2/ChIPseq"

In [70]:
 
#Load file gene closest to peak and this distance.
#File contains peak names, gene names and the distance between a peak and nearby genes
GREAT_out <- read.table('GREAT_outputWT.csv', header = FALSE, sep = ";" )
head(GREAT_out)
dim(GREAT_out)
V1V2V3V4V5V6V7V8V9V10V11V12V13
SRR3737445_WT_peak_1Sox17 -226401 Mrpl15 62925 NA NA NA NA
SRR3737445_WT_peak_2Pcmtd1 -115077 St18 486612 NA NA NA NA
SRR3737445_WT_peak_3Arfgef1 -467358 Cpa6 19917 NA NA NA NA
SRR3737445_WT_peak_4Prdm14 -139788 Ncoa2 107132 NA NA NA NA
SRR3737445_WT_peak_5Rdh10 122814 Stau2 290718 NA NA NA NA
SRR3737445_WT_peak_6Mcm3 -58 NA NA NA NA NA
  1. 3431
  2. 13
 
The amount of rows in the GREAT_out table tells us that we have detected 3431 Sox2 peaks in total.

The amount of rows in the GREAT_out table tells us that we have detected 3431 Sox2 peaks in total.

In [71]:
 
#Select first 5 columns, as these contain the data of interest
GREAT_out <- GREAT_out[,1:5]
head(GREAT_out)
V1V2V3V4V5
SRR3737445_WT_peak_1Sox17 -226401 Mrpl15 62925
SRR3737445_WT_peak_2Pcmtd1 -115077 St18 486612
SRR3737445_WT_peak_3Arfgef1 -467358 Cpa6 19917
SRR3737445_WT_peak_4Prdm14 -139788 Ncoa2 107132
SRR3737445_WT_peak_5Rdh10 122814 Stau2 290718
SRR3737445_WT_peak_6Mcm3 -58 NA
In [72]:
 
#Add column names
column_names <- c("PEAK", "Gene", "Distance", "Gene", "Distance")
colnames(GREAT_out) <- column_names
head(GREAT_out)
PEAKGeneDistanceGeneDistance
SRR3737445_WT_peak_1Sox17 -226401 Mrpl15 62925
SRR3737445_WT_peak_2Pcmtd1 -115077 St18 486612
SRR3737445_WT_peak_3Arfgef1 -467358 Cpa6 19917
SRR3737445_WT_peak_4Prdm14 -139788 Ncoa2 107132
SRR3737445_WT_peak_5Rdh10 122814 Stau2 290718
SRR3737445_WT_peak_6Mcm3 -58 NA
 
The two gene columns were combined to allow removal of rows containing NAs. In this way we were able to remove rows with NAs, without removing the gene in the other column with a viable value.

The two gene columns were combined to allow removal of rows containing NAs. In this way we were able to remove rows with NAs, without removing the gene in the other column with a viable value.

In [82]:
 
List1 <- GREAT_out[,2:3]
List2 <- GREAT_out[,4:5]
head(List1)
head(List2)
dim(List1)
dim(List2)
GeneDistance
Sox17 -226401
Pcmtd1 -115077
Arfgef1-467358
Prdm14 -139788
Rdh10 122814
Mcm3 -58
GeneDistance
Mrpl15 62925
St18 486612
Cpa6 19917
Ncoa2 107132
Stau2 290718
NA
  1. 3431
  2. 2
  1. 3431
  2. 2
In [92]:
 
GENES <- rbind(List1, List2)
head(GENES)
dim(GENES)
GeneDistance
Sox17 -226401
Pcmtd1 -115077
Arfgef1-467358
Prdm14 -139788
Rdh10 122814
Mcm3 -58
  1. 6862
  2. 2
In [93]:
 
row.has.na <- apply(GENES, 1, function(x){any(is.na(x))})
sum(row.has.na)
GENES_filtered <- GENES[!row.has.na,]
#Check removal
row.has.na_2 <- apply(GENES_filtered, 1, function(x){any(is.na(x))})
sum(row.has.na_2)
805
0
In [94]:
 
sapply(GENES_filtered, class)
dim(GENES_filtered)
head(GENES_filtered)
Gene
'factor'
Distance
'integer'
  1. 6057
  2. 2
GeneDistance
Sox17 -226401
Pcmtd1 -115077
Arfgef1-467358
Prdm14 -139788
Rdh10 122814
Mcm3 -58
 
## 4.2. Genes with a Sox 2 peak in their promotor region

4.2. Genes with a Sox 2 peak in their promotor region

 
The promotor region has been defined as 500 bases upstream from TSS(Transcription start site)

The promotor region has been defined as 500 bases upstream from TSS(Transcription start site)

In [48]:
 
#selecting all genes with a binding site in promotor from Gene1
#greater than 0 as a negative distance means peak location is downstream from the TSS
Promotors <- subset(GENES_filtered,GENES_filtered$Distance<500 & GENES_filtered$Distance> 0)
head(Promotors)
dim(Promotors)
GeneDistance
134931408C20Rik112
255Enpp3 79
337Timm13 8
459Zfp62 26
521Pipox 25
560Zfp652 23
  1. 76
  2. 2
In [49]:
 
#What is the percentage vs total binding sites
nrow(Promotors)
nrow(GREAT_out)
percentage_promotors = nrow(Promotors)/nrow(GREAT_out)*100
percentage_promotors
76
3431
2.21509763917225
 
2,22% of Sox2 binding peaks is situated in the promotor region of a gene.This is a very nice percentage, seeing as the promotor was defined as being only the first 500 bases upstream of the transcription start site

2,22% of Sox2 binding peaks is situated in the promotor region of a gene.This is a very nice percentage, seeing as the promotor was defined as being only the first 500 bases upstream of the transcription start site

 
## 4.3. Genes with a Sox2 peak in their upstream region

4.3. Genes with a Sox2 peak in their upstream region

 
The upstream region has been defined as up to 10kb from TSS

The upstream region has been defined as up to 10kb from TSS

In [50]:
 
#selecting all genes with a binding site in promotor from Gene1
#greater than 0 as a negative distance means peak location is downstream from the TSS
Upstream <- subset(GENES_filtered, GENES_filtered$Distance<10000 & GENES_filtered$Distance> 0)
head(Upstream)
dim(Upstream)
GeneDistance
134931408C20Rik 112
17Hs6st1 1293
19Mgat4a 3095
27Mfsd9 865
66Cxcr1 9130
68Tmbim1 8753
  1. 450
  2. 2
In [51]:
 
#What is the percentage vs total binding sites
nrow(Upstream)
nrow(GREAT_out)
percentage_Upstream = nrow(Upstream)/nrow(GREAT_out)*100
percentage_Upstream
450
3431
13.1157097056252
 
13,12 percent of Sox2 binding peaks can be found in the upstream region of genes. This percentage highlights Sox2's role as a modulator of gene transcription, as this process is primarily regulated upstream fromt the transcription start site.

13,12 percent of Sox2 binding peaks can be found in the upstream region of genes. This percentage highlights Sox2's role as a modulator of gene transcription, as this process is primarily regulated upstream fromt the transcription start site.

 
# 5. Exploration of the effect of Sox2 binding on differential expression

5. Exploration of the effect of Sox2 binding on differential expression

 
Which genes with Sox2 binding in WT are differentially expressed in WT vs KO?

Which genes with Sox2 binding in WT are differentially expressed in WT vs KO?

In [57]:
 
#row(res.sign) contains the gene names of significantly differentially expressed genes
toMatch <- c(rownames(res.sign))
head(toMatch)
length(toMatch)
  1. 'Sox2'
  2. 'Esr1'
  3. 'Atp6v0d2'
  4. 'Gsdmc2'
  5. 'Tph1'
  6. 'Stc2'
64
In [61]:
 
upstream_matches <- unique (grep(paste(toMatch,collapse="|"), 
                        Upstream$Gene, value=TRUE))
​
promotor_matches <- unique (grep(paste(toMatch,collapse="|"), 
                        Promotors$Gene, value=TRUE))
​
length(upstream_matches)
head(upstream_matches)
length(promotor_matches)
head(promotor_matches)
2
  1. 'Cxcl17'
  2. 'Acsm3'
0
 
We can conclude that only 2 significantly differentially expressed genes have a Sox2 binding peak in their upstream region, while none of the significantly differentially expressed genes have a Sox2 binding peak in their promotor region.

We can conclude that only 2 significantly differentially expressed genes have a Sox2 binding peak in their upstream region, while none of the significantly differentially expressed genes have a Sox2 binding peak in their promotor region.

 
Check the differential expression of these genes.

Check the differential expression of these genes.

In [65]:
 
res.sign[upstream_matches,]
log2 fold change (MLE): condition WT vs KO 
Wald test p-value: condition WT vs KO 
DataFrame with 2 rows and 6 columns
        baseMean log2FoldChange     lfcSE      stat       pvalue        padj
       <numeric>      <numeric> <numeric> <numeric>    <numeric>   <numeric>
Cxcl17  1834.894      0.5248832 0.1385391  3.788700 1.514375e-04 0.048695841
Acsm3   3433.758     -0.6780687 0.1467366 -4.620993 3.819077e-06 0.001763326
 
Cxcl17 shows singificant downregulation upon knock down, albeit the padj value (0.048695841) is on the verge of non-significance and its log2FoldChange is also low. Acsm3 is significantly upregulated on knock down, though the log2FoldChange value is again on the low side.
Here the results provide evidence for both activation and repression of transcription by Sox2.

Cxcl17 shows singificant downregulation upon knock down, albeit the padj value (0.048695841) is on the verge of non-significance and its log2FoldChange is also low. Acsm3 is significantly upregulated on knock down, though the log2FoldChange value is again on the low side. Here the results provide evidence for both activation and repression of transcription by Sox2.