source("genecre.R");
args<-commandArgs(trailingOnly=TRUE);
rna=read.table("genematrix.txt");
t=which(paste("chr",as.matrix(rna[,2]),sep="") == args[1]);
x=as.matrix(rna[t,9:64]);
colnames(x)=as.matrix(read.table("cellmap.txt"))[,2];
tss=rna[,3];
tss[rna[,5]<0] = rna[rna[,5]<0,4];
tss=tss[t];
m=apply(x,1,mean);
s=apply(x,1,sd);
tt=which(m>-1 & s>1.5);
rt=run(x[tt,],tss[tt],paste("../scratch/roadmap_analysis/impute/tt.",args[1],sep=""),args[1],B=100);
save(rt,file=paste("roadmap_rna.",args[1],".3.Rdat",sep=""));
tt=which(m>-1 & s<=1.5);
rt=run(x[tt,],tss[tt],paste("../scratch/roadmap_analysis/impute/tt.",args[1],sep=""),args[1],B=100);
save(rt,file=paste("roadmap_rna.",args[1],".4.Rdat",sep=""));
tt=which(m<=-1 & s>1.5);
rt=run(x[tt,],tss[tt],paste("../scratch/roadmap_analysis/impute/tt.",args[1],sep=""),args[1],B=100);
save(rt,file=paste("roadmap_rna.",args[1],".2.Rdat",sep=""));
tt=which(m<=-1 & s<=1.5);
rt=run(x[tt,],tss[tt],paste("../scratch/roadmap_analysis/impute/tt.",args[1],sep=""),args[1],B=100);
save(rt,file=paste("roadmap_rna.",args[1],".1.Rdat",sep=""));
