-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.survival_analysis.R
More file actions
167 lines (106 loc) · 6.98 KB
/
Copy path2.survival_analysis.R
File metadata and controls
167 lines (106 loc) · 6.98 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
library(tidyverse)
library(survival)
library(survminer)
library(readxl)
library(forestploter)
clinical_data_clean <- read.csv("FILES/clinical_data_clean.csv", row.names=1)
colnames(clinical_data_clean)[colnames(clinical_data_clean) == "Sarcoma.Histopathological.Subtype"] <- "Sarcoma Histopathological Subtype"
colnames(clinical_data_clean)[colnames(clinical_data_clean) == "Neo.Adjuvant...Adjuvant.Treatment"] <- "Neo Adjuvant / Adjuvant Treatment"
colnames(clinical_data_clean)[colnames(clinical_data_clean) == "Local.Recurrence"] <- "Local Recurrence"
colnames(clinical_data_clean)[colnames(clinical_data_clean) == "Distant.Recurrence"] <- "Distant Recurrence"
sarculator <- read_excel("RESULTS/Sarculator_Results.xlsx")
consensus_clusters <- read.csv("RESULTS/Consensus_Clusters.csv")
row.names(consensus_clusters) <- consensus_clusters$X
names <- consensus_clusters$X
consensus_clusters <- consensus_clusters[names,]
clinical_data_clean <- clinical_data_clean[row.names(clinical_data_clean) %in% names,]
clinical_data_clean <- clinical_data_clean[names,]
row.names(sarculator) <- sarculator$...1
consensus_clusters <- consensus_clusters[row.names(clinical_data_clean),]
clinical_data_clean$Transcriptomic <- consensus_clusters$final
clinical_data_clean$Transcriptomic <- ifelse(clinical_data_clean$Transcriptomic == 1, "C1" ,clinical_data_clean$Transcriptomic)
clinical_data_clean$Transcriptomic <- ifelse(clinical_data_clean$Transcriptomic == 2, "C2" ,clinical_data_clean$Transcriptomic)
clinical_data_clean$Transcriptomic <- ifelse(clinical_data_clean$Transcriptomic == 3, "C3" ,clinical_data_clean$Transcriptomic)
clinical_data_clean$Transcriptomic <- ifelse(clinical_data_clean$Transcriptomic == 4, "C4" ,clinical_data_clean$Transcriptomic)
clinical_data_clean <- clinical_data_clean[!is.na(clinical_data_clean$Nº.Histologia),]
table <- data.frame(row.names = names, pvalue = numeric(length(names)))
clinical_data_clean$`Neo Adjuvant / Adjuvant Treatment` <- as.character(clinical_data_clean$`Neo Adjuvant / Adjuvant Treatment`)
clinical_data_clean$`Local Recurrence` <- as.character(clinical_data_clean$`Local Recurrence`)
sarculator <- sarculator[row.names(clinical_data_clean),]
clinical_data_clean$Sarculator_5_Year_OS <- as.numeric(sarculator$Sarculator)
colnames(clinical_data_clean)[colnames(clinical_data_clean) == "Transcriptomic"] <- "Transcriptomic Clusters"
clinical_data_clean$Sarculator_5_Year_OS <- ifelse(clinical_data_clean$Sarculator_5_Year_OS <= 0.60, "Low", "High")
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Gender + `Sarcoma Histopathological Subtype` + `Transcriptomic Clusters` + `Neo Adjuvant / Adjuvant Treatment` + `Local Recurrence` , data = clinical_data_clean)
ggforest(cox,data = clinical_data_clean, fontsize = 1.5)
temp <- cox.zph(cox)
print(temp) # display the results
plot(temp)
ggcoxzph(temp)
anova(cox)
clinical_data_clean <- clinical_data_clean[!is.na(clinical_data_clean$Sarculator_5_Year_OS),]
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ `Transcriptomic Clusters` , data = clinical_data_clean)
ggforest(cox, data = clinical_data_clean, fontsize = 1)
tc <- cox$concordance["concordance"]
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Sarculator_5_Year_OS, data = clinical_data_clean)
sarculator <- cox$concordance["concordance"]
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Age, data = clinical_data_clean)
Age <- cox$concordance["concordance"]
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Sarculator_5_Year_OS + `Transcriptomic Clusters` , data = clinical_data_clean)
tc_sarculator <- cox$concordance["concordance"]
# New models including age
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Sarculator_5_Year_OS + Age, data = clinical_data_clean)
sarculator_age <- cox$concordance["concordance"]
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ `Transcriptomic Clusters` + Age, data = clinical_data_clean)
tc_age <- cox$concordance["concordance"]
cox <- coxph(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Sarculator_5_Year_OS + `Transcriptomic Clusters` + Age, data = clinical_data_clean)
tc_sarculator_age <- cox$concordance["concordance"]
# Compile all concordance values into a data frame
concordance_values <- data.frame(
Model = c("SARCULATOR", "TC + SARCULATOR",
"TC",
"TC + Age"),
Concordance = c(sarculator, tc_sarculator,
tc,
tc_age)
)
concordance_values <- concordance_values[order(concordance_values$Concordance, decreasing = TRUE), ]
concordance_values$Color <- ifelse(grepl("TC", concordance_values$Model), "orange", "skyblue")
concordance_values$Label <- ifelse(grepl("TC", concordance_values$Model), "Includes TC", "Does Not Include TC")
concordance_values$Label
# Plot the ordered barplot with conditional coloring and a legend
ggplot(concordance_values, aes(x = reorder(Model, Concordance), y = Concordance, fill = Label)) +
geom_bar(stat = "identity", width = 0.6) + # Narrower bars for a clean look
geom_text(aes(label = round(Concordance, 2)), hjust = -0.1, size = 3.5, family = "Helvetica") + # Consistent font style
coord_flip() +
xlab("Model") +
ylab("Concordance Index") +
ggtitle("Concordance Indexes of Different Models") +
theme_classic(base_size = 12, base_family = "Helvetica") + # Clean, professional theme
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"), # Center-aligned title
axis.title.x = element_text(size = 12),
axis.title.y = element_text(size = 12),
axis.text = element_text(size = 10),
legend.title = element_blank(), # Nature-style plots often omit legend titles
legend.position = "top", # Position legend at the top for better visibility
legend.text = element_text(size = 10)
) +
scale_fill_manual(
values = c("Includes TC" = "#E69F00", "Does Not Include TC" = "#56B4E9"), # Subtle color palette
labels = c("Includes TC", "Does Not Include TC") # Corrected legend labels
) +
expand_limits(y = c(0, max(concordance_values$Concordance) * 1.1))
tmp <- clinical_data_clean[clinical_data_clean$Sarculator_5_Year_OS == "Low", ]
tmp2 <- clinical_data_clean[clinical_data_clean$Sarculator_5_Year_OS == "High", ]
colnames(tmp)[colnames(tmp) == "Transcriptomic Clusters"] <- "Transcriptomic_Clusters"
tmp$Transcriptomic_Clusters <- ifelse(tmp$Transcriptomic_Clusters == "C1","C1", "Not C1")
colnames(tmp2)[colnames(tmp2) == "Transcriptomic Clusters"] <- "Transcriptomic_Clusters"
tmp2$Transcriptomic_Clusters <- ifelse(tmp2$Transcriptomic_Clusters == "C1","C1", "Not C1")
km_fit <- survfit(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Transcriptomic_Clusters, data=tmp)
x <- ggsurvplot(km_fit,pval=TRUE,risk.table=TRUE, conf.int = TRUE,
title = "Overall Survival Sarculator Score <= 0.60")
x
km_fit <- survfit(Surv(TIME_DEATH_FROM_SURGERY, Morte.S.N) ~ Transcriptomic_Clusters, data=tmp2)
x <- ggsurvplot(km_fit,pval=TRUE,risk.table=TRUE, conf.int = TRUE,
title = "Overall Survival Sarculator Score > 0.60")
x