######Video source: https://ke.biowolf.cn
######??????ѧ??: https://www.biowolf.cn/
######΢?Ź??ںţ?biowolf_cn
######???????䣺biowolf@foxmail.com
######????΢??: 18520221056

install.packages("ReactomePA")
#install.packages("survminer")


#???ð?
library(survival)
library(survminer)
setwd("C:\\Users\\LZD\\Desktop\\THCA\\PANoptosis\\17.survival")     #???ù???Ŀ¼

#?????????????ĺ???
bioSurvival=function(inputFile=null, outFile=null){
	#??ȡ?????ļ?
	rt=read.table(inputFile, header=T, sep="\t")
	#?Ƚϸߵͷ????????????죬?õ???????pֵ
	diff=survdiff(Surv(futime, fustat) ~risk,data = rt)
	pValue=1-pchisq(diff$chisq,df=1)
	if(pValue<0.001){
		pValue="p<0.001"
	}else{
		pValue=paste0("p=",sprintf("%.03f",pValue))
	}
	fit <- survfit(Surv(futime, fustat) ~ risk, data = rt)
		
	#????????????
	surPlot=ggsurvplot(fit, 
		           data=rt,
		           conf.int=F,
		           pval=pValue,
		           pval.size=6,
		           legend.title="Risk",
		           legend.labs=c("High risk", "Low risk"),
		           xlab="Time(years)",
		           ylab="Overall survival",
		           break.time.by = 1,
		           palette=c("#CC0033", "#0099CC"),
		           risk.table=TRUE,
		       	   risk.table.title="",
		           risk.table.col = "strata",
		           risk.table.height=.25)
	
	#????ͼ??
	pdf(file=outFile, width = 6.5, height =5.5, onefile = FALSE)
	print(surPlot)
	dev.off()
}

#???ú?????????????????
bioSurvival(inputFile="risk.train.txt", outFile="surv.train.pdf")
bioSurvival(inputFile="risk.test.txt", outFile="surv.test.pdf")
bioSurvival(inputFile="risk.all.txt", outFile="surv.all.pdf")


######Video source: https://ke.biowolf.cn
######??????ѧ??: https://www.biowolf.cn/
######΢?Ź??ںţ?biowolf_cn
######???????䣺biowolf@foxmail.com
######????΢??: 18520221056

