annotate EBIsoformTwoCondTest.R @ 7:c85f281dc059 draft

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