# 1. Calculation of differential expression between WT and KO sampleslibrary("DESeq2")library(scales)options(repr.plot.width=4, repr.plot.height=3)#setting working directorysetwd("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq")getwd()## 1.1 Loading Countfile and preparing it for DeSEQ#Loading gene count filematrixFile = path.expand("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq/all.gene.counts.tsv")#converting gene count matrix to the correct formatcountData <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))head(countData)#Changing collumn headings to biologicaly relevant sample namescolnames(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)#Input of sample information in condition variable required as input for DeSEQcondition <- factor(c("WT", "WT", "WT", "KO", "KO", "KO"))print(condition)#Creating colData data frame from collumn namens of countData and the condition variable, to be used as input for DeSEQcolData <- data.frame(sampleName = colnames(countData), condition = condition)colData#Preparing DESeqDataSet(dds) for DeSEQdds <- DESeqDataSetFromMatrix(countData = countData, colData = colData, design = ~ condition)colnames(dds) <- colnames(countData)#Checking if all prior commands worked correctlydds#confirm correct order of conditionsdds$conditionThe 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)
dds_BetaP <- DESeq(dds, betaPrior=FALSE)#Export of results from dds_BetaP to resBetaPresBetaP <- results(dds_BetaP)resBetaP <- resBetaP[order(resBetaP$padj),]head(resBetaP)Checking differential expression of Sox2 manuallyChecking differential expression of Sox2 manually
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.
estimate a factor to check for possible effect of library size using barplotestimate a factor to check for possible effect of library size using barplot
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 datasum of all reads per sample of the raw data
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 comparescatter plot of sample vs sample will to check how the samples compare
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 dataNormalize for library size by log transformation of the data
rld <- rlogTransformation(dds_BetaP, blind=TRUE)#Checking of the effect of normalization on variationoptions(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 successfulNow the variation stays more or less constant for all, meaning that normalisation of the data was successful
#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 expectedthat 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#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#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)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.
#save results to filewrite.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 membersCould lack of effect, only 64 differentially expressed genes, be due to compensation by other genes from the sox family?Investigate by checking their differential expressionCould 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
library(stringr)#count how many sox family members are present in resultssum(str_count(rownames(resBetaP), "Sox"))#Make vector containing names of these family membersNamesSoxFamily <- c(rownames(resBetaP)[grep("Sox", rownames(resBetaP))])NamesSoxFamily#store expression of Sox family in new matrixSoxFamily <- resBetaP[NamesSoxFamily,]head(SoxFamily)dim(SoxFamily)#Check for significance in SoxFamilySoxFamily.sign <- SoxFamily[(!is.na(SoxFamily$padj)) & (SoxFamily$padj < 0.05),]dim(SoxFamily.sign)#Which Sox genes are differentially expressedrownames(SoxFamily.sign)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.
getwd()setwd("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq")list.files()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.
#Read differential expression tablez<-read.table("deseq_results_NoBetaPrior_Numbers.txt",sep="\t",header=TRUE)sapply(z, class)#Removing NA'srow.has.na <- apply(z, 1, function(x){any(is.na(x))})sum(row.has.na)z_filtered <- z[!row.has.na,]#check removalrow.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 analysisz_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()Genes were split in up and down regulated genes to make further processing easierGenes 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 genesGenes 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
DownRegulated <- subset(RankTable, RankTable$metric > 0)UpRegulated <- subset(RankTable, RankTable$metric < 0)head(UpRegulated)dim(UpRegulated)head(DownRegulated)dim(DownRegulated)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()## 3.2. All GeneIDs were changed to all caps to be used as input for GSEA#All GeneIDs have to be made upper case in order to use them as input for GSEAsapply(RankTable, class)#Change GeneID from facotr to characterRankTable$GeneID <- as.character(RankTable$GeneID)head(RankTable)sapply(RankTable, class)#Make all GeneIDs upper caseRankTable <- data.frame(lapply(RankTable, function(v) { if (is.character(v)) return(toupper(v)) else return(v)}))head(RankTable)#Export as new filewrite.table(RankTable,file="Expression_ranked_on_metricscore_ALLCAPS.rnk",quote=F,sep="\t",row.names=F)list.files()# 4. Analysis of location of Sox2 binding peaks in the WT sample## 4.1. Conversion of narrow peak file to wanted formatsetwd("/mnt/storage/r0372900/Assignment_bioinformatics2/RNAseq")getwd()list.files()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"
#Load file gene closest to peak and this distance.#File contains peak names, gene names and the distance between a peak and nearby genesGREAT_out <- read.table('GREAT_outputWT.csv', header = FALSE, sep = ";" )head(GREAT_out)dim(GREAT_out)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.
#Select first 5 columns, as these contain the data of interestGREAT_out <- GREAT_out[,1:5]head(GREAT_out)#Add column namescolumn_names <- c("PEAK", "Gene", "Distance", "Gene", "Distance")colnames(GREAT_out) <- column_nameshead(GREAT_out)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.
List1 <- GREAT_out[,2:3]List2 <- GREAT_out[,4:5]head(List1)head(List2)dim(List1)dim(List2)GENES <- rbind(List1, List2)head(GENES)dim(GENES)row.has.na <- apply(GENES, 1, function(x){any(is.na(x))})sum(row.has.na)GENES_filtered <- GENES[!row.has.na,]#Check removalrow.has.na_2 <- apply(GENES_filtered, 1, function(x){any(is.na(x))})sum(row.has.na_2)sapply(GENES_filtered, class)dim(GENES_filtered)head(GENES_filtered)## 4.2. Genes with a Sox 2 peak in their promotor regionThe 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)
#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 TSSPromotors <- subset(GENES_filtered,GENES_filtered$Distance<500 & GENES_filtered$Distance> 0)head(Promotors)dim(Promotors)#What is the percentage vs total binding sitesnrow(Promotors)nrow(GREAT_out)percentage_promotors = nrow(Promotors)/nrow(GREAT_out)*100percentage_promotors2,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 site2,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 regionThe upstream region has been defined as up to 10kb from TSSThe upstream region has been defined as up to 10kb from TSS
#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 TSSUpstream <- subset(GENES_filtered, GENES_filtered$Distance<10000 & GENES_filtered$Distance> 0)head(Upstream)dim(Upstream)#What is the percentage vs total binding sitesnrow(Upstream)nrow(GREAT_out)percentage_Upstream = nrow(Upstream)/nrow(GREAT_out)*100percentage_Upstream13,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 expressionWhich 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?
#row(res.sign) contains the gene names of significantly differentially expressed genestoMatch <- c(rownames(res.sign))head(toMatch)length(toMatch)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)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.
res.sign[upstream_matches,]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.