-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path批量生存分析
104 lines (80 loc) · 3.49 KB
/
批量生存分析
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
setwd('D:\\prrc\\TCGA\\GDC\\mutation\\lnc\\survival')
library(survival)
library(caret)
library(glmnet)
library(survminer)
library(tidyverse)
library(ggplot2)
rt=read.table("expTime.txt",header=T,sep="\t",check.names=F,row.names=1) #读取输入文件
rt$futime=rt$futime/365
rt<-rt[,-c(3:10)]
rt<-na.omit(rt)
sigGenes=c("futime","fustat")
for(i in colnames(rt[,3:ncol(rt)])){
case_when(rt[,i]<=unname(quantile(rt[,i],0.25))~ 'low',
rt[,i]>unname(quantile(rt[,i],0.25))&rt[,i]<unname(quantile(rt[,i],0.75))~'median',
rt[,i]>=unname(quantile(rt[,i],0.75))~'high')->rt[,i]
rt[,i]<-as.factor(rt[,i])
}
data=rt
dd<-list()
for(i in 3:ncol(data)){
k=colnames(data[i])
dd[[k]]<-subset(data,data[,k]=='low'|data[,k]=='high',select = c("futime","fustat",k))
dd[[k]][,3]<-as.factor(as.character(dd[[k]][,3]))
}
#
fit=list()
R<-list()
for(i in 1:length(dd)){
diff=survdiff(Surv(dd[[i]]$futime,dd[[i]]$fustat) ~ dd[[i]][,3],data =dd[[i]])
pValue=1-pchisq(diff$chisq,df=1)
if(pValue<0.05){
R=c(R,dd[i])
}
}
for (i in 1:length(R)){
Q=R[[i]]
fit<- survfit(Surv(futime, fustat) ~Q[,3],data =Q)
splots <- list()
splots[[1]]<-ggsurvplot(fit,
xlab = "Time_years",
ylab="survival probability",##根据需要调整
pval = T,
conf.int= F,
risk.table = T,
legend.title = names(R)[i],
surv.median.line = "hv",# 中位生存
palette="lancet")
res<-arrange_ggsurvplots(splots, print = F,
ncol = 1, nrow = 1, risk.table.height = 0.25)
ggsave(paste(names(R)[i],"All_surv.pdf",sep = "_"), res,width=7,height = 6)
}
另一种样式
for (i in 1:length(R)){
Q=R[[i]]
fit<- survfit(Surv(futime, fustat) ~Q[,3],data =Q)
splots <- list()
splots[[1]]<-ggsurvplot(fit,font.legend= 16,font.x = 16, font.y = 16,pval.method.coord=c(2,0.4),pval.coord=c(2,0.25),
font.tickslab = 14,risk.table =TRUE, risk.table.y.text.col = T,conf.int = TRUE,
risk.table.y.text = FALSE,risk.table.height = 0.2,pval=TRUE,pval.method = TRUE,
pval.method.size = 4,log.rank.weights = "survdiff",
legend.title = names(R)[i],
surv.median.line = "hv",# 中位生存
palette="lancet")
res<-arrange_ggsurvplots(splots, print = F,
ncol = 1, nrow = 1, risk.table.height = 0.25)
ggsave(paste(names(R)[i],"All_surv.pdf",sep = "_"), res,width=7,height = 6)
}
单个基因
fit<- survfit(Surv(futime, fustat) ~LINC02041,data =BB)
P3=ggsurvplot(fit,font.legend= 16,font.x = 16, font.y = 16,pval.method.coord=c(2,0.5),pval.coord=c(2,0.25),
font.tickslab = 14,risk.table =TRUE, risk.table.y.text.col = T,conf.int = TRUE, palette = "Dark2",
risk.table.y.text = FALSE,risk.table.height = 0.2,pval=TRUE,pval.method = TRUE,
pval.method.size = 4,log.rank.weights = "survdiff",legend.title = "LINC02041",
legend.labs = c("High ", "low "),xlab ="Time(years)",break.x.by=2,xlim=c(1,10),
ylab="surival probability",censor.shape="|", censor.size = 2,ggtheme = theme_light(),
title = "TCGA prcc OS")
P3$table <- P3$table + theme(axis.line = element_blank())
ggarrange(P3$plot+theme(plot.title = element_text(hjust = 0.5)),P3$table, heights = c(2, 0.7),
ncol = 1, nrow =2) # 标题居中