############ COX model  ###############
install.packages("survival")
install.packages("survminer")
install.packages("pillar")
library(survival)
library(survminer)
setwd("C:/Users/27226/Desktop/sMFE/LUAD/biomarker")
LIHC_clin<-read.csv("C:/Users/27226/Desktop/sMFE/LUAD/biomarker/LUAD surv.csv")
LIHC_clin$status[which(LIHC_clin$status!="Dead")]=0
LIHC_clin$status[which(LIHC_clin$status=="Dead")]=1
LIHC_clin$status=as.numeric(LIHC_clin$status)
LIHC_clin$time=LIHC_clin$time/365;
a<-read.csv("C:/Users/27226/Desktop/sMFE/LUAD/biomarker/LUAD identity.csv",header = F)
a=a[,1]
k=0;
for (i in 3:length(LIHC_clin[1,]))
{splots<-list()
surv_model=survfit(Surv(time,status)~LIHC_clin$KHDRBS3,data=LIHC_clin)
d.survdiff=survival::survdiff(Surv(time,status)~LIHC_clin$KHDRBS3,data=LIHC_clin)
p_val=1-pchisq(d.survdiff$chisq,length(d.survdiff$n)-1)
if(p_val<=0.05)
{k=k+1;
splots[[1]]<-ggsurvplot(surv_model,fun="pct",data=LIHC_clin,#ylim=c(50,100),
                        legend = c(0.8,0.6),
                        pval = T,                      # 改变legend的位置
                        legend.title ="KHDRBS3 ",#a[i-2],        # 改变legend的题目
                        legend.labs = c("Identified samples","Unidentified samples"), 
                        palette = c('blue','#E6AB02'),# 改变legend的标签c('blue','#E6AB02')#c("red", "purple")
                        surv.median.line = "hv",#tables.height
                        #ylim=c(0.5,1),
                        xlab="Time(years)")

res<-arrange_ggsurvplots(splots,print = F,ncol = 1,nrow = 1)
name1="KHDRBS3 ";#a[i-2];
ggsave(paste(name1,".pdf",sep =" "),res,width=5,height=5,)}
}