-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02727d7
commit bf25046
Showing
9 changed files
with
136 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Multivariate Cox regression | ||
|
||
#' Fit multivariate Cox regression model based on INCOMMON classes. | ||
#' | ||
#' @param x A list of objects of class \code{'INCOMMON'} containing the classification results for | ||
#' multiple samples, as produced by using function `classify`. | ||
#' @param tumor_type The selected tumor type. | ||
#' @param gene The selected gene. | ||
#' @param covariates Covariates used in the multivariate regression. | ||
#' @return An object of class \code{coxph}. | ||
#' @export | ||
#' @importFrom dplyr filter mutate rename select %>% | ||
#' @importFrom survival Surv coxph | ||
|
||
cox_fit = function(x, gene, tumor_type, covariates = c('age', 'sex', 'tmb')){ | ||
|
||
x = prepare_km_fit_input(x, tumor_type, gene) | ||
|
||
formula = 'survival::Surv(OS_MONTHS, OS_STATUS) ~ group' | ||
|
||
for(c in covariates) { | ||
what = grep(c, colnames(x), ignore.case = T, value = TRUE) | ||
for(w in what) { | ||
if(is.numeric(x[[w]])){ | ||
q = quantile(x[w], na.rm = T)['50%'] | ||
x[[w]] = ifelse(x[[w]] > q, paste0('>', round(q, 0)), paste0('<=', round(q, 0))) | ||
x[[w]] = factor(x[[w]]) | ||
x[[w]] = relevel(x[[w]], ref = grep('<=', unique(x[[w]]), value = T)) | ||
} | ||
formula = paste(formula, w, sep = ' + ') | ||
} | ||
} | ||
|
||
fit = survival::coxph( | ||
formula = formula %>% as.formula(), | ||
data = x %>% | ||
dplyr::mutate(group = factor(group)) %>% | ||
dplyr::mutate(group = relevel(group, ref = grep('WT', unique(x$group), value = T))) %>% | ||
as.data.frame() | ||
) | ||
|
||
return(fit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Fit Kaplan-Meier survival model based on INCOMMON classes. | ||
#' | ||
#' @param x A list of objects of class \code{'INCOMMON'} containing the classification results for | ||
#' multiple samples, as produced by using function `classify`. | ||
#' @param tumor_type The selected tumor type. | ||
#' @param gene The selected gene. | ||
#' @return An table containing the selected gene, tumor_type, the data table used to | ||
#' fit the model and an object of class \code{'survfit'}. | ||
#' @export | ||
#' @importFrom dplyr filter mutate rename select %>% | ||
#' @importFrom survival Surv survfit | ||
|
||
kaplan_meier_fit = function(x, tumor_type, gene) { | ||
|
||
data = prepare_km_fit_input(x, tumor_type, gene) | ||
data = data %>% | ||
dplyr::mutate(group = factor(group, | ||
levels = c( | ||
grep('WT', unique(data$group), value = T), | ||
grep('Mutant', unique(data$group), value = T) %>% grep('with', ., invert = T, value = T), | ||
grep('Mutant', unique(data$group), value = T) %>% grep('with', ., value = T) | ||
))) | ||
fit = survival::survfit(formula = survival::Surv(OS_MONTHS, OS_STATUS) ~ group, data = data) | ||
|
||
return(tibble(gene = gene, tumor_type = tumor_type, data = list(data), fit = list(fit))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters