
library(limma)
library(estimate)
setwd(" ")                
inputFile="symbol.txt"                                                

rt=read.table(inputFile,sep="\t",header=T,check.names=F)


rt=as.matrix(rt)
rownames(rt)=rt[,1]
exp=rt[,2:ncol(rt)]
dimnames=list(rownames(exp),colnames(exp))
data=matrix(as.numeric(as.matrix(exp)),nrow=nrow(exp),dimnames=dimnames)
data=avereps(data)


group=sapply(strsplit(colnames(data),"\\-"),"[",4)
group=sapply(strsplit(group,""),"[",1)
group=gsub("2","1",group)
data=data[,group==0]
out=data[rowMeans(data)>0,]
out=rbind(ID=colnames(out),out)

write.table(out,file="uniq.symbol.txt",sep="\t",quote=F,col.names=F)


filterCommonGenes(input.f="uniq.symbol.txt", 
                  output.f="XX.gct", 
                  id="GeneSymbol")

estimateScore(input.ds = "XX.gct",
              output.ds="estimateScore.gct")


scores=read.table("estimateScore.gct",skip = 2,header = T)
rownames(scores)=scores[,1]
scores=t(scores[,3:ncol(scores)])
rownames(scores)=gsub("\\.","\\-",rownames(scores))
out=rbind(ID=colnames(scores),scores)
write.table(out,file="scores.txt",sep="\t",quote=F,col.names=F)