
rm(list=ls())
library(tidyverse)
library(ggsci)
library(survminer)
library(survival)

## hypoxia-related genes uniCox analysis
setwd("E:\\Nutsore\\001-待处理\\001 文章项目处理\\胶质瘤原始数据\\1. hallmarks ssGSEA")

hallmark = read.csv("01 hallmarks.ssGSEA.csv")
cli = read.csv("02 all.cli.csv")
cli = cli[,c("ID", "Cohort", "OS", "OS.time")]

## 
meta = dplyr::inner_join(cli, hallmark)
meta$Cohort = factor(meta$Cohort)
var = as.character(fct_unique(meta$Cohort))

result = data.frame()
for (g in var) {
  dat = meta[meta$Cohort %in% g,]
  dat = dat %>% dplyr::select_if(~!any(is.na(.)))
  for(i in colnames(dat[,5:ncol(dat)])){
    cox <- coxph(Surv(OS.time, OS) ~ dat[,i], data = dat)
    coxSummary = summary(cox)
    coxP=coxSummary$coefficients[,"Pr(>|z|)"]
    result=rbind(result,
                 cbind(id=i,
                       GSE=g,
                       coef=coxSummary[["coefficients"]],
                       HR=coxSummary$conf.int[,"exp(coef)"],
                       HR.95L=coxSummary$conf.int[,"lower .95"],
                       HR.95H=coxSummary$conf.int[,"upper .95"],
                       pvalue=coxSummary$coefficients[,"Pr(>|z|)"])
    )
  }
}


write.csv(result, file="03 hallmarks.uniCox.csv", row.names=F) 



