annotate EBGeneTwoCondTest.R @ 45:9bebd9fd9f1b draft default tip

Uploaded
author ning
date Mon, 16 Jun 2014 16:24:58 -0400
parents 360c058ed13a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
360c058ed13a Uploaded
ning
parents:
diff changeset
1 sink(file="/tmp/none")
360c058ed13a Uploaded
ning
parents:
diff changeset
2 sink("/dev/null")
360c058ed13a Uploaded
ning
parents:
diff changeset
3 options(warn=-1)
360c058ed13a Uploaded
ning
parents:
diff changeset
4 options(echo=F)
360c058ed13a Uploaded
ning
parents:
diff changeset
5
360c058ed13a Uploaded
ning
parents:
diff changeset
6 invisible("EBSeq")
360c058ed13a Uploaded
ning
parents:
diff changeset
7 suppressMessages(library("EBSeq"))
360c058ed13a Uploaded
ning
parents:
diff changeset
8
360c058ed13a Uploaded
ning
parents:
diff changeset
9 args <- commandArgs(trailingOnly = T)
360c058ed13a Uploaded
ning
parents:
diff changeset
10 inputfile <- args[1]
360c058ed13a Uploaded
ning
parents:
diff changeset
11 WhetherSampleName <- args[2]
360c058ed13a Uploaded
ning
parents:
diff changeset
12 CondIn <- args[3]
360c058ed13a Uploaded
ning
parents:
diff changeset
13 FDR <- args[4]
360c058ed13a Uploaded
ning
parents:
diff changeset
14 outputfile <- args[5]
360c058ed13a Uploaded
ning
parents:
diff changeset
15 Sort.out<-args[6]
360c058ed13a Uploaded
ning
parents:
diff changeset
16 Sort.out.FDR <-args[7]
360c058ed13a Uploaded
ning
parents:
diff changeset
17 Sizesout <-args[8]
360c058ed13a Uploaded
ning
parents:
diff changeset
18
360c058ed13a Uploaded
ning
parents:
diff changeset
19 Conditions=strsplit(CondIn,split=",")[[1]]
360c058ed13a Uploaded
ning
parents:
diff changeset
20
360c058ed13a Uploaded
ning
parents:
diff changeset
21 if(WhetherSampleName=="y"){
360c058ed13a Uploaded
ning
parents:
diff changeset
22 ReadIn=read.table(inputfile,stringsAsFactors=F,header=T,sep="\t")
360c058ed13a Uploaded
ning
parents:
diff changeset
23 Names=names(ReadIn)[-1]
360c058ed13a Uploaded
ning
parents:
diff changeset
24 }
360c058ed13a Uploaded
ning
parents:
diff changeset
25 if(WhetherSampleName=="n"){
360c058ed13a Uploaded
ning
parents:
diff changeset
26 ReadIn=read.table(inputfile,stringsAsFactors=F,header=F,sep="\t")
360c058ed13a Uploaded
ning
parents:
diff changeset
27 Names=paste0("S",1:length(Conditions))
360c058ed13a Uploaded
ning
parents:
diff changeset
28 }
360c058ed13a Uploaded
ning
parents:
diff changeset
29
360c058ed13a Uploaded
ning
parents:
diff changeset
30 if(class(ReadIn[[1]])=="character"){
360c058ed13a Uploaded
ning
parents:
diff changeset
31 GeneMat=do.call(cbind,ReadIn[-1])
360c058ed13a Uploaded
ning
parents:
diff changeset
32 rownames(GeneMat)=ReadIn[[1]]
360c058ed13a Uploaded
ning
parents:
diff changeset
33 colnames(GeneMat)=Names
360c058ed13a Uploaded
ning
parents:
diff changeset
34 }
360c058ed13a Uploaded
ning
parents:
diff changeset
35 if(class(ReadIn[[1]])=="numeric"){
360c058ed13a Uploaded
ning
parents:
diff changeset
36 GeneMat=data.matrix(ReadIn)
360c058ed13a Uploaded
ning
parents:
diff changeset
37 colnames(GeneMat)=Names
360c058ed13a Uploaded
ning
parents:
diff changeset
38 }
360c058ed13a Uploaded
ning
parents:
diff changeset
39
360c058ed13a Uploaded
ning
parents:
diff changeset
40
360c058ed13a Uploaded
ning
parents:
diff changeset
41 Sizes=MedianNorm(GeneMat)
360c058ed13a Uploaded
ning
parents:
diff changeset
42 EBOut=EBTest(Data=GeneMat,Conditions=as.factor(Conditions),sizeFactors=Sizes, maxround=5)
360c058ed13a Uploaded
ning
parents:
diff changeset
43 PP=GetPP(EBOut)
360c058ed13a Uploaded
ning
parents:
diff changeset
44 PP.sort=sort(PP,decreasing=T)
360c058ed13a Uploaded
ning
parents:
diff changeset
45 PP.sort.FDR=PP.sort[which(PP.sort>=1-as.numeric(FDR))]
360c058ed13a Uploaded
ning
parents:
diff changeset
46
360c058ed13a Uploaded
ning
parents:
diff changeset
47 Data.norm=GetNormalizedMat(GeneMat, Sizes)
360c058ed13a Uploaded
ning
parents:
diff changeset
48 FC=PostFC(EBOut)
360c058ed13a Uploaded
ning
parents:
diff changeset
49 realFC=FC[[2]]
360c058ed13a Uploaded
ning
parents:
diff changeset
50 postFC=FC[[1]]
360c058ed13a Uploaded
ning
parents:
diff changeset
51
360c058ed13a Uploaded
ning
parents:
diff changeset
52 Mat=cbind(PP, realFC[names(PP)], postFC[names(PP)],Data.norm[names(PP),])
360c058ed13a Uploaded
ning
parents:
diff changeset
53 Mat.sort=cbind(PP.sort, realFC[names(PP.sort)], postFC[names(PP.sort)],Data.norm[names(PP.sort),])
360c058ed13a Uploaded
ning
parents:
diff changeset
54
360c058ed13a Uploaded
ning
parents:
diff changeset
55
360c058ed13a Uploaded
ning
parents:
diff changeset
56 if(length(PP.sort.FDR)>1)Mat.sort.FDR=cbind(PP.sort.FDR, realFC[names(PP.sort.FDR)], postFC[names(PP.sort.FDR)],Data.norm[names(PP.sort.FDR),])
360c058ed13a Uploaded
ning
parents:
diff changeset
57
360c058ed13a Uploaded
ning
parents:
diff changeset
58 if(length(PP.sort.FDR)==1)Mat.sort.FDR=matrix(
360c058ed13a Uploaded
ning
parents:
diff changeset
59 c(PP.sort.FDR, realFC[names(PP.sort.FDR)], postFC[names(PP.sort.FDR)],Data.norm[names(PP.sort.FDR),])
360c058ed13a Uploaded
ning
parents:
diff changeset
60 ,nrow=1)
360c058ed13a Uploaded
ning
parents:
diff changeset
61
360c058ed13a Uploaded
ning
parents:
diff changeset
62 colnames(Mat)=colnames(Mat.sort)=
360c058ed13a Uploaded
ning
parents:
diff changeset
63 c("PPDE","RealFC","PosteriorFC",colnames(Data.norm))
360c058ed13a Uploaded
ning
parents:
diff changeset
64 if(length(PP.sort.FDR)>0)colnames(Mat.sort.FDR)=
360c058ed13a Uploaded
ning
parents:
diff changeset
65 c("PPDE","RealFC","PosteriorFC",colnames(Data.norm))
360c058ed13a Uploaded
ning
parents:
diff changeset
66
360c058ed13a Uploaded
ning
parents:
diff changeset
67 ##cms - col.names changed below to have a header for the row names. This way the output of RSEM can be joined with EBSeq output
360c058ed13a Uploaded
ning
parents:
diff changeset
68 #write.table(round(Mat,2),file=outputfile,quote=F,col.names=T,row.names=T,sep = "\t")
360c058ed13a Uploaded
ning
parents:
diff changeset
69 #write.table(round(Mat,2),file=outputfile,quote=F,col.names=NA,row.names=T,sep = "\t") ##cms - made correction on 11/11/13
360c058ed13a Uploaded
ning
parents:
diff changeset
70 write.table(round(Mat,2),file=outputfile,quote=F,col.names=c("gene_id\tPPDE","RealFC","PosteriorFC",colnames(Data.norm)),row.names=T,sep = "\t") ##cms - made correction on 11/11/13
360c058ed13a Uploaded
ning
parents:
diff changeset
71 #write.table(round(Mat.sort,2),file=Sort.out ,quote=F,col.names=T,row.names=T,sep = "\t")
360c058ed13a Uploaded
ning
parents:
diff changeset
72 #write.table(round(Mat.sort,2),file=Sort.out ,quote=F,col.names=NA,row.names=T,sep = "\t") ##cms - made correction on 11/11/13
360c058ed13a Uploaded
ning
parents:
diff changeset
73 write.table(round(Mat.sort,2),file=Sort.out ,quote=F,col.names=c("gene_id\tPPDE","RealFC","PosteriorFC",colnames(Data.norm)),row.names=T,sep = "\t") ##cms - made correction on 11/11/13
360c058ed13a Uploaded
ning
parents:
diff changeset
74 #if(length(PP.sort.FDR)>0)write.table(round(Mat.sort.FDR,2),file=Sort.out.FDR,quote=F,col.names=T,row.names=T,sep = "\t")
360c058ed13a Uploaded
ning
parents:
diff changeset
75 #if(length(PP.sort.FDR)>0)write.table(round(Mat.sort.FDR,2),file=Sort.out.FDR,quote=F,col.names=NA,row.names=T,sep = "\t") ##cms - made correction on 11/11/13
360c058ed13a Uploaded
ning
parents:
diff changeset
76 if(length(PP.sort.FDR)>0)write.table(round(Mat.sort.FDR,2),file=Sort.out.FDR,quote=F,col.names=c("gene_id\tPPDE","RealFC","PosteriorFC",colnames(Data.norm)),row.names=T,sep = "\t") ##cms - made correction on 12/17/13; this preserves the header if merged with RSEM output.
360c058ed13a Uploaded
ning
parents:
diff changeset
77 write.table(Sizes,file=Sizesout,quote=F,col.names=F,row.names=F,sep = "\t")
360c058ed13a Uploaded
ning
parents:
diff changeset
78