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

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