#Identification of differential expressed immune-related genes(DEIRGs) library(edgeR) logFCfiler= fdrFilter= conNum= treatNum= # setwd("D:\\") rt=read.table("XXX.txt",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) data=data[rowMeans(data)>1,] group=c(rep("W",conNum),rep("M",treatNum)) design <- model.matrix(~group) y <- DGEList(counts=data,group=group) y <- calcNormFactors(y) y <- estimateCommonDisp(y) y <- estimateTagwiseDisp(y) et <- exactTest(y,pair = c("W","M")) ordered_tags <- topTags(et, n=100000) allDiff=ordered_tags$table allDiff=allDiff[is.na(allDiff$FDR)==FALSE,] diff=allDiff newData=y$pseudo.counts write.table(diff,file="all.xls",sep="\t",quote=F) diffSig = diff[(diff$FDR < fdrFilter & (diff$logFC>logFCfiler | diff$logFC<(-logFCfiler))),] diffSigOut=rbind(id=colnames(diffSig),diffSig) write.table(diffSigOut, file="diff.xls",sep="\t",quote=F,col.names=F) write.table(diffSigOut, file="diff.txt",sep="\t",quote=F,col.names=F) normalizeExp=rbind(id=colnames(newData),newData) write.table(normalizeExp,file="normalExp.txt",sep="\t",quote=F,col.names=F) diffExp=rbind(id=colnames(newData),newData[rownames(diffSig),]) write.table(diffExp,file="diffExp.txt",sep="\t",quote=F,col.names=F) ## Construction of immune gene pairs tcgaPair=data.frame() rt = read.table("tcgaImmuneExp.share.txt",header=T,sep="\t",check.names=F,row.names=1) sampleNum=ncol(rt) for(i in 1:(nrow(rt)-1)){ for(j in (i+1):nrow(rt)){ pair=ifelse(rt[i,]>rt[j,],1,0) pairRatio=sum(pair)/sampleNum if((pairRatio>0.2)&(pairRatio<0.8)){ rownames(pair)=paste0(rownames(rt)[i],"|",rownames(rt)[j]) tcgaPair=rbind(tcgaPair,pair) } } } geoPair=data.frame() rt = read.table("geoImmuneExp.share.txt",header=T,sep="\t",check.names=F,row.names=1) sampleNum=ncol(rt) for(i in 1:(nrow(rt)-1)){ for(j in (i+1):nrow(rt)){ pair=ifelse(rt[i,]>rt[j,],1,0) pairRatio=sum(pair)/sampleNum if((pairRatio>0.2)&(pairRatio<0.8)){ rownames(pair)=paste0(rownames(rt)[i],"|",rownames(rt)[j]) geoPair=rbind(geoPair,pair) } } } sameGene=intersect(row.names(tcgaPair),row.names(geoPair)) tcgaOut=tcgaPair[sameGene,] geoOut=geoPair[sameGene,] tcgaOut=rbind(ID=colnames(tcgaOut),tcgaOut) write.table(tcgaOut,file="tcgaPair.txt",sep="\t",quote=F,col.names=F) geoOut=rbind(ID=colnames(geoOut),geoOut) write.table(geoOut,file="geoPair.txt",sep="\t",quote=F,col.names=F) ###Construction and validation of the immune gene pairs prognostic model pFilter= library(survival) rt=read.table("X.txt",header=T,sep="\t",check.names=F,row.names=1) sigGenes=c("futime","fustat") outTab=data.frame() for(i in colnames(rt[,3:ncol(rt)])){ cox <- coxph(Surv(futime, fustat) ~ rt[,i], data = rt) coxSummary = summary(cox) coxP=coxSummary$coefficients[,"Pr(>|z|)"] outTab=rbind(outTab, cbind(id=i, HR=coxSummary$conf.int[,"exp(coef)"], HR.95L=coxSummary$conf.int[,"lower .95"], HR.95H=coxSummary$conf.int[,"upper .95"], pvalue=coxSummary$coefficients[,"Pr(>|z|)"]) ) if(coxP|z|)"]) outTab=cbind(id=row.names(outTab),outTab) write.table(outTab,file="multiCox.xls",sep="\t",row.names=F,quote=F) riskScore=predict(multiCox,type="risk",newdata=rt) coxGene=rownames(multiCoxSum$coefficients) coxGene=gsub("`","",coxGene) outCol=c("futime","fustat",coxGene) medianTrainRisk=median(riskScore) risk=as.vector(ifelse(riskScore>medianTrainRisk,"high","low")) write.table(cbind(id=rownames(cbind(rt[,outCol],riskScore,risk)),cbind(rt[,outCol],riskScore,risk)), file="riskTrain.txt", sep="\t", quote=F, row.names=F) rtTest=read.table("test.txt",header=T,sep="\t",check.names=F,row.names=1) rtTest[,"futime"]=rtTest[,"futime"]/365 riskScoreTest=predict(multiCox,type="risk",newdata=rtTest) riskTest=as.vector(ifelse(riskScoreTest>medianTrainRisk,"high","low")) write.table(cbind(id=rownames(cbind(rtTest[,outCol],riskScoreTest,riskTest)),cbind(rtTest[,outCol],riskScore=riskScoreTest,risk=riskTest)), file="riskTest.txt", sep="\t", quote=F, row.names=F)