-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_9_var.R
74 lines (61 loc) · 2.37 KB
/
step_9_var.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
##
## step9 使用外部数据验证
##
## 工作空间
rm(list = ls())
options(stringsAsFactors = F)
suppressMessages(library(survival))
suppressMessages(library(survminer))
suppressMessages(library(ComplexHeatmap))
suppressMessages(library(circlize))
suppressMessages(library(GEOquery))
suppressMessages(library(dplyr))
suppressMessages(library(tidyr))
source('source/rocf.R')
source('source/oclr.R')
source('source/BaseTabf.R')
source('source/Staticalf.R')
source('source/Id2Symbolf.R')
source('source/factorf.R')
# 加载需要的数据
lasso <- read.csv('output/step_8_cox_lasso.csv',row.names = 1)
load('input/ICGC.Rdata')
# 准备COX数据
COX_dat <- ICGC_DAT
COX_dat <- COX_dat[rownames(COX_dat) %in% lasso$gene,]
COX_clinc <- ICGC_clinc
COX_tdat <- as.data.frame(t(COX_dat))
COX_tdat$icgc_donor_id <- rownames(COX_tdat)
COX_mdat <- inner_join(COX_clinc,COX_tdat,by = "icgc_donor_id")
rownames(COX_mdat) <- COX_mdat$icgc_donor_id
COX_mdat$OS.time <- as.numeric(COX_mdat$OS.time)
COX_mdat$OS <- as.numeric(COX_mdat$OS)
## 计算分线得分
Risk_mdat <- theriskf(indat = COX_mdat,ingene = lasso$gene,incoeff = lasso$coef)
Risk_mdat$RiskScore
median(Risk_mdat$RiskScore)
table(Risk_mdat$RiskGroup)
## ROC绘图
rocf(indat = Risk_mdat)
## 高低风险组KM
sfit <- survfit(Surv(OS.time,OS) ~ RiskGroup, data = Risk_mdat)
plot4 <- ggsurvplot(sfit,palette = c("#ea0102","#63b931"),
risk.table = F,
pval =TRUE,pval.size= 4.3,pval.coord=c(1,0.03),
pval.method = F,
xlim = c(0,150),
conf.int = T,xlab ="Time (months)",ylab = 'Survival probability',
ggtheme = theme_test(),
legend = c(0.82,0.83),
legend.title = "Risk Group",legend.labs = c("High risk", "Low risk"))
cox<-coxph(Surv(OS.time,OS) ~ RiskScore,data = Risk_mdat)
res<-summary(cox)
plot2 <- plot4$plot +
annotate("text",x=11,y=0.24,label=paste("HR = ",signif(res$conf.int[1],2))) +
annotate("text",x=20,y=0.17,label=paste("95%CI = ",round(res$conf.int[3],2),"-",
signif(res$conf.int[4],2)))+
annotate("text",x=20,y=0.1,label=paste("Cox P = ",signif(res$coefficients[5],3)))
print(plot2)
pdf(file = 'fig/step_9_var_KM.pdf',width = 4,height = 4)
print(plot2)
dev.off()