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
| setGeneric("getKMCurve", function(.Object) standardGeneric("getKMCurve")) setMethod("getKMCurve", signature(.Object = "TumorPrognosis"), function(.Object){ for (data_set_name in c("train", "valid")){ sur_data = getGroupSameples(.Object, data_set_name) for (marker in c("stage", .Object@markers)){ if(marker == "stage"){ legend_labs = c("Stage I/II", "Stage III/IV") }else{ legend_labs = paste0(marker, c(" high risk", " low rish")) } group = paste0(marker, "_b") surv = Surv(sur_data$futime, sur_data$fustat2) formula_this = as.formula(paste0("surv", "~", group)) ggl = surv_fit(formula_this, data = sur_data) surv_diff = survdiff(formula_this, data = sur_data) p = ggsurvplot(ggl, xlab = "Time (Years)", ylab = "OS (percentage)", break.x.by = 365, break.y.by = 0.25, ylim = c(0, 1), xlim = c(0, 365 * .Object@survival_year), legend.title = paste0("Log-rank p = ", format(1 - pchisq(surv_diff$chisq, length(surv_diff$n) -1), digits = 3)), legend.labs = legend_labs, size = 0.8, censor.shape=124, censor.size=2, font.main = c(16, "plain", "darkblue"), font.x = c(10, "plain", "black"), font.y = c(10, "plain", "black"), font.tickslab = c(8,"plain", "black"), font.legend = c(8,"plain","black"), risk.table =F, tables.height = 0.25, legend = c(0.3,0.28), fontsize=4.5, conf.int=T, conf.int.style='ribbon', conf.int.alpha=0.1 ) p = p$plot + scale_x_continuous(breaks = seq(0, 1825, 365), labels = seq(0, 5)) .Object@KMCurve[[data_set_name]][[marker]] = p } } .Object })
|