annotate EBGeneTwoCondTest.R @ 11:696a1f7e23fd draft

Uploaded
author ning
date Fri, 15 Mar 2013 18:23:03 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
696a1f7e23fd Uploaded
ning
parents:
diff changeset
1 sink(file="/tmp/none")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
2 sink("/dev/null")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
3 options(warn=-1)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
4 options(echo=F)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
5
696a1f7e23fd Uploaded
ning
parents:
diff changeset
6 invisible("EBSeq")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
7 suppressMessages(library("EBSeq"))
696a1f7e23fd Uploaded
ning
parents:
diff changeset
8
696a1f7e23fd Uploaded
ning
parents:
diff changeset
9 args <- commandArgs(trailingOnly = T)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
10 inputfile <- args[1]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
11 WhetherSampleName <- args[2]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
12 CondIn <- args[3]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
13 FDR <- args[4]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
14 outputfile <- args[5]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
15 Sort.out<-args[6]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
16 Sort.out.FDR <-args[7]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
17 Sizesout <-args[8]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
18
696a1f7e23fd Uploaded
ning
parents:
diff changeset
19 Conditions=strsplit(CondIn,split=",")[[1]]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
20
696a1f7e23fd Uploaded
ning
parents:
diff changeset
21 if(WhetherSampleName=="y"){
696a1f7e23fd Uploaded
ning
parents:
diff changeset
22 ReadIn=read.table(inputfile,stringsAsFactors=F,header=T,sep="\t")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
23 Names=names(ReadIn)[-1]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
24 }
696a1f7e23fd Uploaded
ning
parents:
diff changeset
25 if(WhetherSampleName=="n"){
696a1f7e23fd Uploaded
ning
parents:
diff changeset
26 ReadIn=read.table(inputfile,stringsAsFactors=F,header=F,sep="\t")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
27 Names=paste0("S",1:length(Conditions))
696a1f7e23fd Uploaded
ning
parents:
diff changeset
28 }
696a1f7e23fd Uploaded
ning
parents:
diff changeset
29
696a1f7e23fd Uploaded
ning
parents:
diff changeset
30 if(class(ReadIn[[1]])=="character"){
696a1f7e23fd Uploaded
ning
parents:
diff changeset
31 GeneMat=do.call(cbind,ReadIn[-1])
696a1f7e23fd Uploaded
ning
parents:
diff changeset
32 rownames(GeneMat)=ReadIn[[1]]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
33 colnames(GeneMat)=Names
696a1f7e23fd Uploaded
ning
parents:
diff changeset
34 }
696a1f7e23fd Uploaded
ning
parents:
diff changeset
35 if(class(ReadIn[[1]])=="numeric"){
696a1f7e23fd Uploaded
ning
parents:
diff changeset
36 GeneMat=data.matrix(ReadIn)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
37 colnames(GeneMat)=Names
696a1f7e23fd Uploaded
ning
parents:
diff changeset
38 }
696a1f7e23fd Uploaded
ning
parents:
diff changeset
39
696a1f7e23fd Uploaded
ning
parents:
diff changeset
40
696a1f7e23fd Uploaded
ning
parents:
diff changeset
41 Sizes=MedianNorm(GeneMat)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
42 EBOut=EBTest(Data=GeneMat,Conditions=as.factor(Conditions),sizeFactors=Sizes, maxround=5)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
43 PP=GetPP(EBOut)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
44 PP.sort=sort(PP,decreasing=T)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
45 PP.sort.FDR=PP.sort[which(PP.sort>=1-as.numeric(FDR))]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
46
696a1f7e23fd Uploaded
ning
parents:
diff changeset
47 Data.norm=GetNormalizedMat(GeneMat, Sizes)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
48 FC=PostFC(EBOut)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
49 realFC=FC[[2]]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
50 postFC=FC[[1]]
696a1f7e23fd Uploaded
ning
parents:
diff changeset
51
696a1f7e23fd Uploaded
ning
parents:
diff changeset
52 Mat=cbind(PP, realFC[names(PP)], postFC[names(PP)],Data.norm[names(PP),])
696a1f7e23fd Uploaded
ning
parents:
diff changeset
53 Mat.sort=cbind(PP.sort, realFC[names(PP.sort)], postFC[names(PP.sort)],Data.norm[names(PP.sort),])
696a1f7e23fd Uploaded
ning
parents:
diff changeset
54
696a1f7e23fd Uploaded
ning
parents:
diff changeset
55
696a1f7e23fd 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),])
696a1f7e23fd Uploaded
ning
parents:
diff changeset
57
696a1f7e23fd Uploaded
ning
parents:
diff changeset
58 if(length(PP.sort.FDR)==1)Mat.sort.FDR=matrix(
696a1f7e23fd 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),])
696a1f7e23fd Uploaded
ning
parents:
diff changeset
60 ,nrow=1)
696a1f7e23fd Uploaded
ning
parents:
diff changeset
61
696a1f7e23fd Uploaded
ning
parents:
diff changeset
62 colnames(Mat)=colnames(Mat.sort)=
696a1f7e23fd Uploaded
ning
parents:
diff changeset
63 c("PPDE","RealFC","PosteriorFC",colnames(Data.norm))
696a1f7e23fd Uploaded
ning
parents:
diff changeset
64 if(length(PP.sort.FDR)>0)colnames(Mat.sort.FDR)=
696a1f7e23fd Uploaded
ning
parents:
diff changeset
65 c("PPDE","RealFC","PosteriorFC",colnames(Data.norm))
696a1f7e23fd Uploaded
ning
parents:
diff changeset
66
696a1f7e23fd Uploaded
ning
parents:
diff changeset
67 write.table(round(Mat,2),file=outputfile,quote=F,col.names=T,row.names=T,sep = "\t")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
68 write.table(round(Mat.sort,2),file=Sort.out ,quote=F,col.names=T,row.names=T,sep = "\t")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
69 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")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
70 write.table(Sizes,file=Sizesout,quote=F,col.names=F,row.names=F,sep = "\t")
696a1f7e23fd Uploaded
ning
parents:
diff changeset
71