#we load the library for the DESeq analysislibrary("DESeq2")library(scales)options(repr.plot.width=4, repr.plot.height=3)setwd(path.expand("/mnt/storage/r0611267/work"))#we organize the data in a matrix (countDataSmoker and countDataCancer)matrixFileSmoker = path.expand("/mnt/storage/r0611267/work/all.smoker.counts")matrixFileCancer = path.expand("/mnt/storage/r0611267/work/all.cancer.counts")countDataSmoker <- as.matrix(read.csv(matrixFileSmoker, header=TRUE, sep="\t", row.names="Geneid"))head(countDataSmoker)countDataCancer <- as.matrix(read.csv(matrixFileCancer, header=TRUE, sep="\t", row.names="Geneid"))head(countDataCancer)#change name of columncolnames(countDataSmoker) <- c("NS1", "NS2", "S1", "S2") head(countDataSmoker)colnames(countDataCancer) <- c("NC1", "NC2", "C1", "C2") head(countDataCancer)#we define the experimental conditionconditionS <- factor(c("NS", "NS", "S", "S"))print(conditionS)conditionC <- factor(c("NC", "NC", "C", "C"))print(conditionC)colDataS <- data.frame(sampleName = colnames(countDataSmoker), conditionS = conditionS)colDataS#we create the DESeqDataSet from the countData matrixdds <- DESeqDataSetFromMatrix(countData = countDataSmoker, colData = colDataS, design = ~ conditionS)colnames(dds) <- colnames(countDataSmoker)ddscolDataC <- data.frame(sampleName = colnames(countDataCancer), conditionC = conditionC)colDataCddsC <- DESeqDataSetFromMatrix(countData = countDataCancer, colData = colDataC, design = ~ conditionC)colnames(ddsC) <- colnames(countDataCancer)ddsC#we run DESeq giving in input the DESeqDataSet dds <- DESeq(dds)ddsC <- DESeq(ddsC)#barplot to visualize the library size. We create the plot using the DESeq2 function because less #sensitive to outliers (for example sequencing errors)options(repr.plot.width=4, repr.plot.height=4)barplot(sizeFactors(dds))options(repr.plot.width=4, repr.plot.height=4)barplot(sizeFactors(ddsC))#for the sample vs sample scatter plot we performed a normalization of the library size and a #logarithmic transformation of the data to reduce the noise rld <- rlogTransformation(dds, blind=TRUE)rldC <- rlogTransformation(ddsC, blind=TRUE)options(repr.plot.width=5, repr.plot.height=5)plot(data.frame(assay(rld)), cex=0.1, col=alpha("green", 0.4))options(repr.plot.width=5, repr.plot.height=5)plot(data.frame(assay(rldC)), cex=0.1, col=alpha("purple", 0.4))#we performed a Principal Component ANalysis (PCA) to assess the inter and intra variation in the sample pairs. plotPCA(rld, intgroup=c("conditionS"))plotPCA(rldC, intgroup=c("conditionC"))#Mean expression plot of NS vs S (red dots correspond to the significantly differentially expressed genes)options(repr.plot.width=5, repr.plot.height=4)plotMA(dds,ylim=c(-3,3))#Mean expression plot of NC vs Coptions(repr.plot.width=5, repr.plot.height=4)plotMA(ddsC,ylim=c(-3,3))#finally we calculate the fold change values for each sample pairresS <- results(dds)resSmoker <- resS[order(resS$padj),]head(resSmoker)resC <- results(ddsC)resCancer <- resC[order(resC$padj),]head(resCancer)#number of differentially expressed genes between NS and SresSmoker.sign <- resSmoker[(!is.na(resSmoker$padj)) & (resSmoker$padj < 0.05),]dim(resSmoker.sign)#number of differentially expressed genes between NC and CresCancer.sign <- resCancer[(!is.na(resCancer$padj)) & (resCancer$padj < 0.05),]dim(resCancer.sign)#check the expression trend of S100A8 in non-smoker vs smokeroptions(repr.plot.width=4, repr.plot.height=4)barplot(assay(rld)["S100A8",])#check the expression trend of CYP1A1 in non-smoker vs smokeroptions(repr.plot.width=4, repr.plot.height=4)barplot(assay(rld)["CYP1A1",])#check the expression trend of CCL20 in non-cancer vs canceroptions(repr.plot.width=4, repr.plot.height=4)barplot(assay(rldC)["CCL20",])#fold change of MUC5AC in non-smoker vs smoker options(repr.plot.width=4, repr.plot.height=4)barplot(assay(rld)["MUC5AC",])#fold change of MUC5AC in non-cancer vs canceroptions(repr.plot.width=4, repr.plot.height=4)barplot(assay(rldC)["MUC5AC",])x
#fold change of NFKBIA in non-cancer vs canceroptions(repr.plot.width=4, repr.plot.height=4)barplot(assay(rldC)["NFKBIA",])#we export the data for the functional analysiswrite.table(resS, "deseq.smoker.tsv", sep="\t", col.names=NA, quote=FALSE)write.table(resC, "deseq.cancer.tsv", sep="\t", col.names=NA, quote=FALSE)**Microarray**Microarray
setwd(path.expand("/mnt/storage/r0611267/work/Microarray_cancer"))#load the libraries required for microarray data analysis:#the affy package is necessary to work with Affymetrix microarray data#the limma package will be used for differential expression analysislibrary(affy)library(limma)#the CEL files are downloaded in the directory Microarray_cancercancer_files = Sys.glob("/mnt/storage/r0611267/work/Microarray_cancer/*.gz")#the variable cancer_files contains a list of names of CEL files, however the data is not loaded yetcancer_files#ReadAffy is used to load the files cancer_raw <- ReadAffy(filenames=cancer_files)#the cancer_files object only knows the filenamessampleNames(cancer_raw)#we create a vector (NC = no cancer, C = cancer)cancer_status = c("NC", "NC", "NC", "NC", "NC", "C", "C", "C", "C", "C", "C", "C", "C")#we create a data frame with the cancer status and the sample namespd <- data.frame(cancer_status = cancer_status)rownames(pd) <- sampleNames(cancer_raw)pd#we convert the data frame to an AnnotatedDataFrame and assign it to the cancer_raw objectlibrary(Biobase) #this library contains the AnnotatedDataFrame:phenoData(cancer_raw) <- AnnotatedDataFrame(data=pd)#we load the frma library which is necessary for the robust multichip average (rma) normalizationlibrary(frma)#we use frma to normalizeeset <- frma(cancer_raw, verbose=TRUE)save(eset, file="/mnt/storage/r0611267/work/Microarray_cancer/GSE28835.eset")#the object eset contains the normalized data per probe and some experimental annotationesetsampleNames(eset)#the sample names are not informative, therefore we assign names manuallyeset.labels <- c("BT13.NC", "BT16.NC", "BT18.NC", "BT3.NC", "BT10.NC", "Squamous cell carcinoma1.C", "Adenocarcinoma1.C", "Large cell carcinoma.C", "Adenocarcinoma2.C", "Adenocarcinoma3.C", "Adenocarcinoma4.C", "Non-small cell carcinoma.C", "Squamous cell carcinoma2.C")sampleNames(eset) <- eset.labelspData(phenoData(eset))#we check the normalized expression levels (on a probe by probe basis)probe.counts <- exprs(eset)head(probe.counts)#we load two libraries morelibrary(annotate)library(hgu133a2.db) #this library contains the annotation for the microarray platform#we use the getSYMBOL function to create a mapping from probe to geneprobe.names <- rownames(probe.counts)gene.symbols <- getSYMBOL(probe.names, "hgu133a2")head(gene.symbols)#number of probes. one gene can have more than one probelength(gene.symbols)#we add the gene symbols as an extra column to the data frame probe.counts.genesymbol <- as.data.frame(cbind(as.data.frame(probe.counts), gene.symbols))#we remove all probes for which there is no gene symbol (=correspondence in the probe column) #and we ensure that the gene symbol column contains only stringsprobe.counts.genesymbol = probe.counts.genesymbol[complete.cases(probe.counts.genesymbol),]probe.counts.genesymbol$gene.symbols <- as.character(probe.counts.genesymbol$gene.symbols)#we will have multiple probes per gene and we will take the median expression in this case#we use the reshape2 package to group the probes per genelibrary(reshape2)#we convert the probe expression table into a gene count table using melt and dcastm <- melt(probe.counts.genesymbol, id.vars = c("gene.symbols"))counts <- dcast(m, gene.symbols ~ variable, fun.aggregate=median)#we convert the column 'gene.symbols' into the row namesrownames(counts) <- counts$gene.symbolscounts$gene.symbols <- NULL#we save this count tablewrite.table(counts, 'GSE19638.counts.tsv', sep="\t", quote=FALSE, col.names=NA)#we use an MDS plot to check the quality of the data#we checked other dimensions options(repr.plot.width=10, repr.plot.height=10)plotMDS(eset)#we made the same selection as reported in the papercancer_and_no_cancer <-counts[c("BT13.NC", "BT16.NC", "BT3.NC", "Adenocarcinoma4.C", "Squamous cell carcinoma2.C")]options(repr.plot.width=10, repr.plot.height=10)plotMDS(cancer_and_no_cancer)#we check the expression of CCL20 and NFKBIA that we found differentially expressed in the RNAseq #analysis, and of SCGB1A1 that is mentioned in the papergoi <- c("CCL20", "SCGB1A1", "NFKBIA")cancer_and_no_cancer[goi,]#we define the experimental conditions along which we will do differential expression analysisstatus <- factor(c('NC', 'NC', 'NC', 'C', 'C'), levels=c('NC', 'C'))status#we build a model matrix because limma uses a linear model in the backgrounddesign <- model.matrix(~status)design#we run limma#the function lmFit fits a linear model and eBayes calculates probabilitiesfit <- eBayes(lmFit(cancer_and_no_cancer, design))#In order to gain insight into the spread of differential expression, #we create an MA plot which shows the log ratio change of expression (M) vs the average expression (A)limma::plotMA(fit, 2)abline(0,0,col='purple')#we extract the top diffentially expressed genestopTable(fit, coef=2)#we correct for multiple testingselect = p.adjust(fit[,2]$p.value, method="BH") < 0.05#we obtain an overview of how many genes are differentially expressed (TRUE)summary(select)