#source("http://bioconductor.org/biocLite.R") #source("https://bioconductor.org/biocLite.R") #biocLite("edgeR") #install.packages("gplots") foldChange=1 padj=0.05 setwd("C:\\Users\\") library("edgeR") rt=read.table("mRNA.symbol.txt",sep="\t",header=T,check.names=F) rt=as.matrix(rt) rownames(rt)=rt[,1] exp=rt[,2:ncol(rt)] dimnames=list(rownames(exp),colnames(exp)) data=matrix(as.numeric(as.matrix(exp)),nrow=nrow(exp),dimnames=dimnames) data=avereps(data) data=data[rowMeans(data)>1,] #group=c("normal","tumor","tumor","normal","tumor") group=c(rep("normal",44),rep("tumor",502)) design <- model.matrix(~group) y <- DGEList(counts=data,group=group) y <- calcNormFactors(y) y <- estimateCommonDisp(y) y <- estimateTagwiseDisp(y) et <- exactTest(y,pair = c("normal","tumor")) topTags(et) ordered_tags <- topTags(et, n=100000) allDiff=ordered_tags$table allDiff=allDiff[is.na(allDiff$FDR)==FALSE,] diff=allDiff newData=y$pseudo.counts write.table(diff,file="edgerOut.xls",sep="\t",quote=F) diffSig = diff[(diff$FDR < padj & (diff$logFC>foldChange | diff$logFC<(-foldChange))),] write.table(diffSig, file="diffSig.xls",sep="\t",quote=F) diffUp = diff[(diff$FDR < padj & (diff$logFC>foldChange)),] write.table(diffUp, file="up.xls",sep="\t",quote=F) diffDown = diff[(diff$FDR < padj & (diff$logFC<(-foldChange))),] write.table(diffDown, file="down.xls",sep="\t",quote=F) normalizeExp=rbind(id=colnames(newData),newData) write.table(normalizeExp,file="normalizeExp.txt",sep="\t",quote=F,col.names=F) diffExp=rbind(id=colnames(newData),newData[rownames(diffSig),]) write.table(diffExp,file="diffmRNAExp.txt",sep="\t",quote=F,col.names=F) heatmapData <- newData[rownames(diffSig),] #volcano pdf(file="vol.pdf") xMax=max(-log10(allDiff$FDR))+1 yMax=12 plot(-log10(allDiff$FDR), allDiff$logFC, xlab="-log10(FDR)",ylab="logFC", main="Volcano", xlim=c(0,xMax),ylim=c(-yMax,yMax),yaxs="i",pch=20, cex=0.4) diffSub=allDiff[allDiff$FDRfoldChange,] points(-log10(diffSub$FDR), diffSub$logFC, pch=20, col="red",cex=0.4) diffSub=allDiff[allDiff$FDR