# Bioinformatics and Systems Biology: Expression, Regulation and Networks Exam project Emiel Vanhulle r0308983, Jasper Vanhecke r0309321, Lena Smets r03872232e master Biomedical Sciences 2016-2017Emiel Vanhulle r0308983, Jasper Vanhecke r0309321, Lena Smets r0387223
2e master Biomedical Sciences 2016-2017
We first loaded the packages needed for using DESeq2We first loaded the packages needed for using DESeq2
library("DESeq2")library("scales")#scales is helper function for coloursoptions(repr.plot.width=4, repr.plot.height=3)setwd(path.expand("/mnt/storage/r0308983/jupyternotebooks/examwork/RNASeq/DeSEQ")) We define the file containing the raw counts (the ones we generated in the other notebook: gene.counts.test1.tsv)We define the file containing the raw counts (the ones we generated in the other notebook : gene.counts.test1.tsv)
matrixFile = path.expand("/mnt/storage/r0308983/jupyternotebooks/examwork/RNASeq/gene.counts.test1.tsv")countData <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))head(countData)#tab (t) separated#welke file is read.csv??tail(countData)Now we will make this better looking by changing the names of the samples to the corresponding condition. The first sample is the WT sample, the second sample is the KO sample.Now we will make this better looking by changing the names of the samples to the corresponding condition. The first sample is the WT sample, the second sample is the KO sample.
colnames(countData) <- c("Mouse.ES.WT", "Mouse.ES.Prep1_KO")head(countData)Next, we define the experimental conditions. We also check the order of the levels. In this case WT comes first, meaning we will be looking at the ratio of KO/WT, meaning that negative fold changes will be downregulated genes and vice versa.Next, we define the experimental conditions. We also check the order of the levels. In this case WT comes first, meaning we will be looking at the ratio of KO/WT, meaning that negative fold changes will be downregulated genes and vice versa.
condition <- factor (c("WT", "Prep1_KO"))print(condition)Next, we will prepare a dataframe with the names and conditions. This will be fed to `DESeq2`.Next, we will prepare a dataframe with the names and conditions. This will be fed to DESeq2.
colData <- data.frame(sampleName = colnames(countData), condition = condition)colDataThen, we create a DESeq `DESeqDataSet` object for subsequent analysis:Then, we create a DESeq DESeqDataSet object for subsequent analysis:
dds <- DESeqDataSetFromMatrix(countData = countData, colData = colData, design = ~ condition)#we need to do this to ensure the column names are correct.colnames(dds) <- colnames(countData)colnames(dds)ddsBy comparing the `condition` factor in the `dds` object to the column names, we can confirm that the order is still correct.By comparing the condition factor in the dds object to the column names, we can confirm that the order is still correct.
dds$conditionWithin `DESeq2` , one function will run all steps required.Within DESeq2 , one function will run all steps required.
?DESeqDESeq2 is able to estimate a factor to correct for the library size:DESeq2 is able to estimate a factor to correct for the library size:
dds <- DESeq(dds)options(repr.plot.width=5, repr.plot.height=5)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.
barplot(colSums(countData))Scatter plots allows us to compare samples. A scatter plot of sample vs sample shows how the samples compare.Scatter plots allows us to compare samples. A scatter plot of sample vs sample shows how the samples compare.
options(repr.plot.width=6, repr.plot.height=6)plot(data.frame(log10(counts(dds))), cex=0.1, col=alpha("dark blue", 0.4))There is a lot of variation (noise) for the low expressing genes.DESeq2 provides therefore a function that minimizes this variation. So next, we will minimize the variation of genes that have low expression, normalize for library size and perform a log transformation on the data.There is a lot of variation (noise) for the low expressing genes. DESeq2 provides therefore a function that minimizes this variation. So next, we will minimize the variation of genes that have low expression, normalize for library size and perform a log transformation on the data.
rld <- rlogTransformation(dds, blind=TRUE)options(repr.plot.width=6, repr.plot.height=6)plot(data.frame(assay(rld)), cex=0.1, col=alpha("dark blue", 0.4))Next, we do a PCA plot to understand inter-sample variationNext, we do a PCA plot to understand inter-sample variation
plotPCA(rld, intgroup=c("condition"))### MA plotAn MA plot shows 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.An MA plot shows 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.
options(repr.plot.width=10, repr.plot.height=10)plotMA(dds,ylim=c(-3,3))There are no red dots or red coloured genes. This means that there are no significantly differentially expressed genes.There are no red dots or red coloured genes. This means that there are no significantly differentially expressed genes.
res <- results(dds)res <- res[order(res$pvalue),]#sort on adjusted in R, $means give me column of res and ordered op padj (adjusted p-value)head(res)We use the following command to see how many significant differentially expressed genes we have (with a P value lower that 0.05). We filtered in P value instead of on adjusted P value, because if we filter on adjusted P value, there will be no differentially expressed genes...We use the following command to see how many significant differentially expressed genes we have (with a P value lower that 0.05). We filtered in P value instead of on adjusted P value, because if we filter on adjusted P value, there will be no differentially expressed genes...
res.sign <- res[(!is.na(res$pvalue)) & (res$pvalue < 0.05),]dim(res.sign)303 genes are differentially expressed if we look at the pvalues303 genes are differentially expressed if we look at the pvalues
## Note: ReplicatesWe didn't work with the p-adjusted, because in the experiment from the article, there are no replicates.It is not possible to conduct a meaningful statistical analysis such as DESeq2 when comparing just two samples (WT and KO).If a DESeqDataSet is provided with an experimental design without replicates, a warning is printed, that the samples are treated as replicates for estimation of dispersion. This kind of analysis is only useful for exploring the data, but will not provide the kind of proper statistical inference on differences between groups. Without biological replicates, it is not possible to estimate the biological variability of each gene. Experiments without replicates do not allow for estimation of the dispersion of counts around the expected value for each group, which is critical for differential expression analysis. If an experimental design is supplied which does not contain the necessary degrees of freedom for differential analysis, DESeq will provide a message to the user and follow the strategy outlined in Anders and Huber (2010) under the section 'Working without replicates', wherein all the samples are considered as replicates of a single group for the estimation of dispersion. Furthermore, while one may not want to draw strong conclusions from such an analysis, it may still be useful for exploration and hypothesis generation.We didn't work with the p-adjusted, because in the experiment from the article, there are no replicates. It is not possible to conduct a meaningful statistical analysis such as DESeq2 when comparing just two samples (WT and KO). If a DESeqDataSet is provided with an experimental design without replicates, a warning is printed, that the samples are treated as replicates for estimation of dispersion. This kind of analysis is only useful for exploring the data, but will not provide the kind of proper statistical inference on differences between groups. Without biological replicates, it is not possible to estimate the biological variability of each gene. Experiments without replicates do not allow for estimation of the dispersion of counts around the expected value for each group, which is critical for differential expression analysis. If an experimental design is supplied which does not contain the necessary degrees of freedom for differential analysis, DESeq will provide a message to the user and follow the strategy outlined in Anders and Huber (2010) under the section 'Working without replicates', wherein all the samples are considered as replicates of a single group for the estimation of dispersion. Furthermore, while one may not want to draw strong conclusions from such an analysis, it may still be useful for exploration and hypothesis generation.
The difference with what they did in the article, is that they modified their dataset. We worked with the whole dataset as it was original. They considered only those RNAs whose level of expression (number of reads) was >1 and in this group, they set an arbitrary threshold to define Prep1-regulated genes (those in which the effect of the absence of Prep1 resulted in an over 30% decrease or 50% increase in expression). Then they found 910 overexpressed genes and 1802 down-regulated genes. We found (looking at the p-values) 303 genes that were differentially expressed.But we still question why in the article they used DESeq2 when they didn't have replicates?The difference with what they did in the article, is that they modified their dataset. We worked with the whole dataset as it was original. They considered only those RNAs whose level of expression (number of reads) was >1 and in this group, they set an arbitrary threshold to define Prep1-regulated genes (those in which the effect of the absence of Prep1 resulted in an over 30% decrease or 50% increase in expression). Then they found 910 overexpressed genes and 1802 down-regulated genes. We found (looking at the p-values) 303 genes that were differentially expressed.
But we still question why in the article they used DESeq2 when they didn't have replicates?
#### Save to diskFinally, we write our results to a tsv file which we can download and open in Excel.Finally, we write our results to a tsv file which we can download and open in Excel.
write.table(res, "deseq.resultsRNAseq.mouse.tsv", sep="\t", col.names=NA, quote=FALSE)We will manually check a number of diff. expressing genes. We will manually check a number of diff. expressing genes.
barplot(assay(rld)["Pknox1",])As expected, Pknox1 goes down in the Prep1(Pknox1)_KO cellsAs expected, Pknox1 goes down in the Prep1(Pknox1)_KO cells
barplot(assay(rld)["Gm10499",])barplot(assay(rld)["Nxf3",])## Note: EXTRAAs noted before (under replicates) it is not meaningful to use DESeq2 on a dataset without replicates.However, we still wanted to further analyze this data.Now we will use DESeq2's new "rlog transformation". It transforms the average of the genes across samples to a log2 scale but "pulls in" those genes for which the evidence for strong fold changes is weak due to low counts.As noted before (under replicates) it is not meaningful to use DESeq2 on a dataset without replicates. However, we still wanted to further analyze this data. Now we will use DESeq2's new "rlog transformation". It transforms the average of the genes across samples to a log2 scale but "pulls in" those genes for which the evidence for strong fold changes is weak due to low counts.
rld <- rlogTransformation(dds)As this is a logarithm-like scale, the differences between the samples can be considered as a "regularized log2 fold change". Next, we made a result data frame:As this is a logarithm-like scale, the differences between the samples can be considered as a "regularized log2 fold change". Next, we made a result data frame:
res <- data.frame(assay(rld), avgLogExpr = (assay(rld)[,2] + assay(rld)[,1])/2, rLogFC = assay(rld)[,2] - assay(rld)[,1])And now we have a ranking of genes by regularized fold changes:And now we have a ranking of genes by regularized fold changes:
head(res[order(res$rLogFC),])tail(res[order(res$rLogFC),])We search for our gene of interest: Pknox1We search for our gene of interest: Pknox1
res[rownames(res)== 'Pknox1',]This ranking put genes on top which are strongly downregulated in the second sample compared to the first one. If you do this with normal log expressions, the weak genes will appear at the top because they are noisiest and hence tend to have exaggerated fold changes. The advantage of this procedure is that it does not produce any pvalues, which would be misleading anyway.This ranking put genes on top which are strongly downregulated in the second sample compared to the first one. If you do this with normal log expressions, the weak genes will appear at the top because they are noisiest and hence tend to have exaggerated fold changes.
The advantage of this procedure is that it does not produce any pvalues, which would be misleading anyway.