library("DESeq2")library(scales)options(repr.plot.width=4, repr.plot.height=3)Ensure we're in the correct directory:Ensure we're in the correct directory:
setwd(path.expand("~/data/work-RNAseq/"))Define the file containing the raw counts (the ones we generated last session):Define the file containing the raw counts (the ones we generated last session):
matrixFile = path.expand("/home/luna.kuleuven.be/r0602960/data/work-RNAseq/all.gene.counts")countData <- as.matrix(read.csv(matrixFile, sep="\t", row.names="Geneid"))head(countData)Make the column names somewhat nicer:Make the column names somewhat nicer:
colnames(countData) <- c( "ctrl","Atra_24h","Atra_48h","2392_24h","2392_48h")summary(countData)Define the experimental conditions - Note the order has to be the same as the column order of the `countData`:Another remark is that it is important that the order of the levels is correct. In this case `NS` comes first, which means that we will be comparing $S \over NS$, so positive log fold change values are up in the stiumulated samples.Define the experimental conditions - Note the order has to be the same as the column order of the countData:
Another remark is that it is important that the order of the levels is correct. In this case NS comes first, which means that we will be comparing , so positive log fold change values are up in the stiumulated samples.
condition <- factor(c("control","t1","t1","t2","t2"))factorPrepapre a dataframe with the names and conditions. This will be fed to `DESeq2`. Ensure that the order is unchanged!Prepapre a dataframe with the names and conditions. This will be fed to DESeq2. Ensure that the order is unchanged!
colData<- data.frame(sampleName = colnames(countData), condition = condition)colDataHere we create a DESeq `DESeqDataSet` object for subsequent analysis:Here 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)By printing `dds` to screen we can see some informationBy printing dds to screen we can see some information
ddsr<-rowSums(counts(dds))length(r)By comparing the `condition` factor in the `dds` object to the column names, you can confirm that the order is still correctBy comparing the condition factor in the dds object to the column names, you can confirm that the order is still correct
## Run the differential expression:one function within `DESeq2` runs all steps required:one function within DESeq2 runs all steps required:
dds<- DESeq(dds)DESeq2 estimates a factor to correct for the library size:DESeq2 estimates a factor to correct for the library size:
options(repr.plot.width=4, repr.plot.height=3)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))A scatter plot of sample vs sample will show us how the samples compare; are the replicates more similar than beween stimulated and non-stimulated?A scatter plot of sample vs sample will show us how the samples compare; are the replicates more similar than beween stimulated and non-stimulated?
options(repr.plot.width=5, repr.plot.height=5)plot(data.frame(log10(counts(dds))), cex=0.1, col=alpha("black", 0.4))You may notice that there is a lot of variation (noise) for the low expressing genes. DESeq2 provides a function that minimizes this variation (and normalizes for library size, and log transforms the data): You may notice that there is a lot of variation (noise) for the low expressing genes. DESeq2 provides a function that minimizes this variation (and normalizes for library size, and log transforms the data):
rld <- rlogTransformation(dds, blind=TRUE)options(repr.plot.width=5, repr.plot.height=5)plot(data.frame(assay(rld)), cex=0.1, col=alpha("black", 0.4))We can also do a PCA plot to understand inter-sample variation:We can also do a PCA plot to understand inter-sample variation:
plotPCA(rld, intgroup=c("condition"))#### MA plotAn MA plot show 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 show 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=5, repr.plot.height=4)plotMA(dds,ylim=c(-3,3))res <- results(dds)res <- res[order(res$padj),]head(res)res_ctrl.t1 <- results(dds, contrast=c("condition","control","t1"))res_ctrl.t2 <- results(dds, contrast=c("condition","control","t2"))res_t1.t2 <- results(dds, contrast=c("condition","t1","t2"))How many genes are differentially expressed?How many genes are differentially expressed?
res.sign_ctrl.t1<- res_ctrl.t1[(!is.na(res_ctrl.t1$padj)) & (res_ctrl.t1$padj < 0.05),]res.sign_ctrl.t1_up<-subset(res.sign_ctrl.t1, log2FoldChange>0)dim(res.sign_ctrl.t1_up)res.sign_ctrl.t1_down<-subset(res.sign_ctrl.t1, log2FoldChange<0)dim(res.sign_ctrl.t1_down)res.sign_ctrl.t2<- res_ctrl.t2[(!is.na(res_ctrl.t2$padj)) & (res_ctrl.t2$padj < 0.05),]res.sign_ctrl.t2_up<-subset(res.sign_ctrl.t2, log2FoldChange>1)dim(res.sign_ctrl.t1_up)res.sign_ctrl.t2_down<-subset(res.sign_ctrl.t2, log2FoldChange< -1)dim(res.sign_ctrl.t1_down)res.sign_t1.t2<- res_t1.t2[(!is.na(res_t1.t2$padj)) & (res_t1.t2$padj < 0.05),]res.sign_t1.t2_up<-subset(res.sign_t1.t2, log2FoldChange>1)dim(res.sign_t1.t2_up)res.sign_t1.t2_down<-subset(res.sign_t1.t2, log2FoldChange< -1)dim(res.sign_t1.t2_down)ddsLRT <- DESeq(dds, test="LRT", reduced= ~ 1)resLRT <- results(ddsLRT)res.sign_LRT<- resLRT[(!is.na(resLRT$padj)) & (resLRT$padj < 0.05),]dim(res.sign_LRT)ls()Save to disk:Save to disk:
write.table(res.sign_ctrl.t1_up, "deseq1_ctrl.t1_up.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(res.sign_ctrl.t1_down, "deseq1_ctrl.t1_down.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(res.sign_ctrl.t2_up, "deseq_ctrl.t2_up.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(res.sign_ctrl.t2_down, "deseq_ctrl.t2_down.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(res.sign_t1.t2_down, "deseq_t1.t2_down.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(res.sign_t1.t2_up, "deseq_t1.t2_up.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(res.sign_LRT, "deseq.LRT.tsv", sep="\t", col.names=NA, quote=FALSE)we get gene list from these tsv files, and run the gene ontology analysis using reactome (http://www.reactome.org/).we get gene list from these tsv files, and run the gene ontology analysis using reactome (http://www.reactome.org/).
<img width="100%" src="/user/r0602960/files/ATRAup.jpg">
<img width="100%" src="/user/r0602960/files/ATRAdown.jpg">
The differential analysis of RNA seq of ATRA shows that ATRA treatment changed the expression level of genes that are mostly involved in NOTCH1 signaling, which regulates cell differentiation and proliferation, cell fate and apoptosis. The differential analysis of RNA seq of ATRA shows that ATRA treatment changed the expression level of genes that are mostly involved in NOTCH1 signaling, which regulates cell differentiation and proliferation, cell fate and apoptosis.
<img width="100%" src="/user/r0602960/files/MC2392up.jpg">
<img width="100%" src="/user/r0602960/files/MC2392down.jpg">
The differential analysis of RNAseq of MC2392 shows that MC2392 treatment increased expression level of genes mostly involved in histone modification and cellular senescence. And MC2392 treatment decreased expression of genes involved in cellular response to heat stress.The differential analysis of RNAseq of MC2392 shows that MC2392 treatment increased expression level of genes mostly involved in histone modification and cellular senescence. And MC2392 treatment decreased expression of genes involved in cellular response to heat stress.
ATRA upregulated genes are enriched in metabolic pathway.MC2392 downregulated genes are enriched in metabolic process and pathway analysis showed the decreased expression of components in cell-cell communication and cellular response to stress.MC2392 induce 7 genes expression in apoptosis pathway: GSN,DAPK2,PSMB9,CASP9,PSMB10,H1F0,PSMB8,ATRA induce 7 gene expression in apoptosis pathway:VIM, BCL2,UNC5B,MAPT,PLEC,CTSG,CADMC2392 induce 7 genes expression in apoptosis pathway: E2F1,HIST1H1E,GSN,PLEC,HIST1H1C,H1F0,CTSG,CADATRA upregulated genes are enriched in metabolic pathway. MC2392 downregulated genes are enriched in metabolic process and pathway analysis showed the decreased expression of components in cell-cell communication and cellular response to stress. MC2392 induce 7 genes expression in apoptosis pathway: GSN,DAPK2,PSMB9,CASP9,PSMB10,H1F0,PSMB8, ATRA induce 7 gene expression in apoptosis pathway:VIM, BCL2,UNC5B,MAPT,PLEC,CTSG,CAD MC2392 induce 7 genes expression in apoptosis pathway: E2F1,HIST1H1E,GSN,PLEC,HIST1H1C,H1F0,CTSG,CAD