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
| library("survival") library("survminer") f_DEG_coxph_oneGene <- function(trainSet, geneN){ if(!(geneN %in% colnames(trainSet$data))){ return(data.frame(row.names = geneN, mean=NA, lower=NA, upper=NA, Pvalue=1, VarName=geneN)) } df <- cbind(trainSet$data[geneN],trainSet$meta[c('pfs_status', 'pfs_time')]) coxmf <- paste0("Surv(pfs_time, pfs_status==1)~", '`',geneN,'`')
res.cox <- coxph(formula(coxmf), data = df) tmp_res <- summary(res.cox) res <- as.data.frame(tmp_res$conf.int) res <- res[,c(1,3,4)] colnames(res) <- c('mean', 'lower', 'upper') res[['Pvalue']] <- tmp_res$coefficients[,'Pr(>z)'] res[['VarName']] <- rownames(res) res } f_DEG_coxph <- function(trainSet, geneList){ res <- NULL for(gene in geneList){ res <- rbind(res,f_DEG_coxph_oneGene(trainSet, gene)) } res } f_DEG_coxph_Sets <- function(trainSets, geneList){ res <- list() for(Name in names(trainSets)){ res[[Name]] <- f_DEG_coxph(trainSets[[Name]], geneList) } res } DEG <- readRDS('../DEG/TCGA/mCRPC_DEG.rds') DEG <- subset(DEG, padj < 0.05 & abs(log2FoldChange)>2 & !grepl('pseudogene', gene_type)) train_sets <- readRDS('train_sets.rds') tmp <- f_DEG_coxph_Sets(train_sets, unique(DEG$gene_name)) saveRDS(tmp, 'mCRPC.rds')
|