genefu package多基因预后模型的比较

经过悉心的研究以及很多老师,朋友的帮助,顺利的进行了自己预想的分析,但仍有写小细节仍有缺陷。特别感谢genefu 包的作者Benjamin Haibe-Kains教授,谨以本文记录自己的探索过程,如可对后来者有帮助也算是功德一件了。

####step18-与基于芯片的模型比较(TCGA cohort,AJCC stage)
####比较AUC值,以ROC曲线形式展示
##载入已准备好的数据
## code used to compute the risk score
library(genefu)
library(survival)
library(survivalROC)
library(survminer)

##先准备注释文件
ddata<-eset##准备好col为symbol的表达矩阵
##
s<-colnames(ddata)
##id 转换
library(org.Hs.eg.db)
s2g=toTable(org.Hs.egSYMBOL)
g=s2g[match(s,s2g$symbol),1];
head(g)
##构造注释文件
#  probe Gene.symbol Gene.ID
dannot=data.frame(probe=s,
                  "Gene.Symbol" =s, 
                  "EntrezGene.ID"=g)
dannot[1:3,1:3]
##保留已注释的基因及注释文件
ddata=ddata[,!is.na(dannot$EntrezGene.ID)]
dannot=dannot[!is.na(dannot$EntrezGene.ID),] 
head(dannot)

##如已准备好数据
##my data 
ddata[1:5,1:5]
dim(ddata)
dannot[1:5,1:3]
dim(dannot)
all(colnames(ddata)==dannot$probe)
##
rownames(dannot) <- as.character(dannot[,'probe'])
data(sig.oncotypedx)
sig.oncotypedx
rs.onco <- oncotypedx(data=ddata,annot=dannot, do.mapping=TRUE)
table(rs.onco$risk)##

##计算OncotypedROC曲线
test_expr <- exprSet
new_exprSet <- test_expr[,c('sampleID','OS_time','OS_event')]
new_exprSet$multi_model <- rs.onco$score

##
cutoff3 =60##5年
##oncotypedx风险分数
Mayo.fit1= survivalROC(Stime=new_exprSet$OS_time,
                     status=new_exprSet$OS_event,
                     marker =new_exprSet$multi_model,
                     predict.time = cutoff3,method="KM")
pdf("TCGA_oncotypedx_ROC_OS.pdf")
plot(Mayo.fit1$FP,Mayo.fit1$TP,type="l",
     xlim=c(0,1),ylim=c(0,1),
     xlab="1-Specificity",ylab="Sensitivity",main="TCGA cohort ",col="#1c61b6",lwd=2)
abline(0,1,col="grey",lwd=2)

#my gene signature
##按自己的模型计算
model_predcit_values <- predict(Multi_cox3,test_expr[,multi_sign_gene],type="risk")
new_exprSet <- test_expr[,c('sampleID','OS_time','OS_event')]
new_exprSet$multi_model <- model_predcit_values
Mayo.fit3= survivalROC(Stime=new_exprSet$OS_time,
                       status=new_exprSet$OS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
lines(Mayo.fit3$FP,Mayo.fit3$TP,type="l",
      xlim=c(0,1),ylim=c(0,1),col="#840000",lwd=2)

##添加图注
legend(0.25,0.25,
       legend=c(paste("Gene21 AUC",round(Mayo.fit1$AUC,3)),
                 paste("Gene5 AUC",round(Mayo.fit3$AUC,3))),
       title.adj=1,##图例标题字体位置1为右
       bty='n',##不画出图例框
       lwd=2,col=c("#1c61b6","#840000"))
dev.off()

####################################################################3
####RFS模型比较
##计算OncotypedROC曲线
test_expr <- exprSet
new_exprSet <- test_expr[,c('sampleID','RFS_time','RFS_event')]
new_exprSet$multi_model <- rs.onco$score

##
cutoff3 =60##5年
##oncotypedx风险分数
Mayo.fit1= survivalROC(Stime=new_exprSet$RFS_time,
                       status=new_exprSet$RFS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
pdf("TCGA_oncotypedx_ROC_RFS.pdf")
plot(Mayo.fit1$FP,Mayo.fit1$TP,type="l",
     xlim=c(0,1),ylim=c(0,1),
     xlab="1-Specificity",ylab="Sensitivity",main="TCGA cohort RFS ",col="#1c61b6",lwd=2)
abline(0,1,col="grey",lwd=2)

#my gene signature
##按自己的模型计算
model_predcit_values <- predict(Multi_cox3,test_expr[,multi_sign_gene],type="risk")
new_exprSet <- test_expr[,c('sampleID','RFS_time','RFS_event')]
new_exprSet$multi_model <- model_predcit_values
Mayo.fit3= survivalROC(Stime=new_exprSet$RFS_time,
                       status=new_exprSet$RFS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
lines(Mayo.fit3$FP,Mayo.fit3$TP,type="l",
      xlim=c(0,1),ylim=c(0,1),col="#840000",lwd=2)

##添加图注
legend(0.25,0.25,
       legend=c(paste("Gene21 AUC",round(Mayo.fit1$AUC,3)),
                paste("Gene5 AUC",round(Mayo.fit3$AUC,3))),
       title.adj=1,##图例标题字体位置1为右
       bty='n',##不画出图例框
       lwd=2,col=c("#1c61b6","#840000"))
##
dev.off()
#####################################################################
##early stage(I/II) ROC comparision
##提取早期组数据
test_expr <- exprSet
dim(test_expr)
test_expr[1:5,1:5]
table(test_expr$stage)##I/II期589sample
table(test_expr$Stage)##

##提取stage为I/II期的sample
early_index<-which(test_expr$stage=='0')
test_expr<-test_expr[early_index,]
dim(test_expr)
new_exprSet <- test_expr[,c('sampleID','OS_time','OS_event')]

##oncotypedx风险分数
ddata[1:5,1:5]
data(sig.oncotypedx)
sig.oncotypedx
##注意sample矩阵的改变
ddata<-ddata[early_index,]
dim(ddata)
rs.onco <- oncotypedx(data=ddata,annot=dannot, do.mapping=TRUE)
table(rs.onco$risk)##
new_exprSet$multi_model <- rs.onco$score
##
cutoff3 =60##5年

Mayo.fit1= survivalROC(Stime=new_exprSet$OS_time,
                       status=new_exprSet$OS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
pdf("Early_stage_oncotypedx_ROC_OS.pdf",width = 5,height = 5)
plot(Mayo.fit1$FP,Mayo.fit1$TP,type="l",
     xlim=c(0,1),ylim=c(0,1),
     xlab="1-Specificity",ylab="Sensitivity",main="Early stage cohort ",col="#1c61b6",lwd=2)
abline(0,1,col="grey",lwd=2)

#my gene signature
##按自己的模型计算
model_predcit_values <- predict(Multi_cox3,test_expr[,multi_sign_gene],type="risk")
new_exprSet <- test_expr[,c('sampleID','OS_time','OS_event')]
new_exprSet$multi_model <- model_predcit_values
Mayo.fit3= survivalROC(Stime=new_exprSet$OS_time,
                       status=new_exprSet$OS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
lines(Mayo.fit3$FP,Mayo.fit3$TP,type="l",
      xlim=c(0,1),ylim=c(0,1),col="#840000",lwd=2)

##添加图注
legend(0.25,0.25,
       legend=c(paste("Gene21 AUC",round(Mayo.fit1$AUC,3)),
                paste("Gene5 AUC",round(Mayo.fit3$AUC,3))),
       title.adj=1,##图例标题字体位置1为右
       bty='n',##不画出图例框
       lwd=2,col=c("#1c61b6","#840000"))
dev.off()

###########################################################
####Earlt stage RFS比较模型
new_exprSet <- test_expr[,c('sampleID','RFS_time','RFS_event')]
new_exprSet$multi_model <- rs.onco$score

##
cutoff3 =60##5年
##oncotypedx风险分数
Mayo.fit1= survivalROC(Stime=new_exprSet$RFS_time,
                       status=new_exprSet$RFS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
pdf("Early_oncotypedx_ROC_RFS.pdf")
plot(Mayo.fit1$FP,Mayo.fit1$TP,type="l",
     xlim=c(0,1),ylim=c(0,1),
     xlab="1-Specificity",ylab="Sensitivity",main="Early stage cohort RFS ",col="#1c61b6",lwd=2)
abline(0,1,col="grey",lwd=2)

#my gene signature
##按自己的模型计算
model_predcit_values <- predict(Multi_cox3,test_expr[,multi_sign_gene],type="risk")
new_exprSet <- test_expr[,c('sampleID','RFS_time','RFS_event')]
new_exprSet$multi_model <- model_predcit_values
Mayo.fit3= survivalROC(Stime=new_exprSet$RFS_time,
                       status=new_exprSet$RFS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
lines(Mayo.fit3$FP,Mayo.fit3$TP,type="l",
      xlim=c(0,1),ylim=c(0,1),col="#840000",lwd=2)

##添加图注
legend(0.25,0.25,
       legend=c(paste("Gene21 AUC",round(Mayo.fit1$AUC,3)),
                paste("Gene5 AUC",round(Mayo.fit3$AUC,3))),
       title.adj=1,##图例标题字体位置1为右
       bty='n',##不画出图例框
       lwd=2,col=c("#1c61b6","#840000"))
##
dev.off()

###############################################################
##Advanced stage ROC comparision
test_expr <- exprSet
dim(test_expr)
test_expr[1:5,1:5]
colnames(test_expr)[1:60]
table(test_expr$stage)
table(test_expr$Stage)
##late 168

##提取III IV期sample 168例
early_index<-which(test_expr$stage=='1')
test_expr<-test_expr[early_index,]
dim(test_expr)

##提取生存数据
new_exprSet <- test_expr[,c('sampleID','OS_time','OS_event')]
##oncotypedx风险分数
ddata[1:5,1:5]
data(sig.oncotypedx)
sig.oncotypedx
##注意sample矩阵的改变
ddata<-ddata[early_index,]
dim(ddata)
rs.onco <- oncotypedx(data=ddata,annot=dannot, do.mapping=TRUE)
table(rs.onco$risk)##
new_exprSet$multi_model <- rs.onco$score
##
cutoff3 =60##5年

Mayo.fit1= survivalROC(Stime=new_exprSet$OS_time,
                       status=new_exprSet$OS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
pdf("Advanced_stage_oncotypedx_ROC_OS.pdf",width = 5,height = 5)
plot(Mayo.fit1$FP,Mayo.fit1$TP,type="l",
     xlim=c(0,1),ylim=c(0,1),
     xlab="1-Specificity",ylab="Sensitivity",main="Advanced stage cohort ",col="#1c61b6",lwd=2)
abline(0,1,col="grey",lwd=2)

#my gene signature
##按自己的模型计算
model_predcit_values <- predict(Multi_cox3,test_expr[,multi_sign_gene],type="risk")
new_exprSet <- test_expr[,c('sampleID','OS_time','OS_event')]
new_exprSet$multi_model <- model_predcit_values
Mayo.fit3= survivalROC(Stime=new_exprSet$OS_time,
                       status=new_exprSet$OS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
lines(Mayo.fit3$FP,Mayo.fit3$TP,type="l",
      xlim=c(0,1),ylim=c(0,1),col="#840000",lwd=2)

##添加图注
legend(0.25,0.25,
       legend=c(paste("Gene21 AUC",round(Mayo.fit1$AUC,3)),
                paste("Gene5 AUC",round(Mayo.fit3$AUC,3))),
       title.adj=1,##图例标题字体位置1为右
       bty='n',##不画出图例框
       lwd=2,col=c("#1c61b6","#840000"))
dev.off()

###########################################################
####Earlt stage RFS比较模型
new_exprSet <- test_expr[,c('sampleID','RFS_time','RFS_event')]
new_exprSet$multi_model <- rs.onco$score

##
cutoff3 =60##5年
##oncotypedx风险分数
Mayo.fit1= survivalROC(Stime=new_exprSet$RFS_time,
                       status=new_exprSet$RFS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
pdf("Advanced_oncotypedx_ROC_RFS.pdf",width = 5,height = 5)
plot(Mayo.fit1$FP,Mayo.fit1$TP,type="l",
     xlim=c(0,1),ylim=c(0,1),
     xlab="1-Specificity",ylab="Sensitivity",main="Advanced stage cohort RFS ",col="#1c61b6",lwd=2)
abline(0,1,col="grey",lwd=2)

#my gene signature
##按自己的模型计算
model_predcit_values <- predict(Multi_cox3,test_expr[,multi_sign_gene],type="risk")
new_exprSet <- test_expr[,c('sampleID','RFS_time','RFS_event')]
new_exprSet$multi_model <- model_predcit_values
Mayo.fit3= survivalROC(Stime=new_exprSet$RFS_time,
                       status=new_exprSet$RFS_event,
                       marker =new_exprSet$multi_model,
                       predict.time = cutoff3,method="KM")
lines(Mayo.fit3$FP,Mayo.fit3$TP,type="l",
      xlim=c(0,1),ylim=c(0,1),col="#840000",lwd=2)

##添加图注
legend(0.25,0.25,
       legend=c(paste("Gene21 AUC",round(Mayo.fit1$AUC,3)),
                paste("Gene5 AUC",round(Mayo.fit3$AUC,3))),
       title.adj=1,##图例标题字体位置1为右
       bty='n',##不画出图例框
       lwd=2,col=c("#1c61b6","#840000"))
##
dev.off()

你可能感兴趣的:(genefu package多基因预后模型的比较)