@sjcrh/proteinpaint-server 2.74.2 → 2.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dataset/termdb.test.js +9 -0
- package/package.json +2 -2
- package/routes/brainImaging.js +99 -0
- package/routes/samplewsimages.js +30 -13
- package/routes/termdb.cohort.summary.js +1 -1
- package/routes/termdb.config.js +4 -0
- package/src/app.js +3358 -2957
- package/utils/regression.R +1 -1
- package/utils/regression.utils.R +43 -6
- package/utils/survival.R +13 -5
package/utils/regression.R
CHANGED
|
@@ -127,7 +127,7 @@ benchmark[["buildFormulas"]] <- unbox(paste(round(as.numeric(dtime), 4), attr(dt
|
|
|
127
127
|
stime <- Sys.time()
|
|
128
128
|
cores <- detectCores()
|
|
129
129
|
if (is.na(cores)) stop("unable to detect number of cores")
|
|
130
|
-
reg_results <- mclapply(X = formulas, FUN = runRegression, regtype = input$regressionType, dat = dat, outcome = input$outcome, mc.cores = cores)
|
|
130
|
+
reg_results <- mclapply(X = formulas, FUN = runRegression, regtype = input$regressionType, dat = dat, outcome = input$outcome, neuroOnc = input$neuroOnc, mc.cores = cores)
|
|
131
131
|
etime <- Sys.time()
|
|
132
132
|
dtime <- etime - stime
|
|
133
133
|
benchmark[["runRegression"]] <- unbox(paste(round(as.numeric(dtime), 4), attr(dtime, "units")))
|
package/utils/regression.utils.R
CHANGED
|
@@ -399,7 +399,7 @@ coxRegression <- function(formula, dat) {
|
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
# run regression analysis
|
|
402
|
-
runRegression <- function(formula, regtype, dat, outcome) {
|
|
402
|
+
runRegression <- function(formula, regtype, dat, outcome, neuroOnc) {
|
|
403
403
|
id <- formula$id
|
|
404
404
|
# remove samples with NA values in any variable in the formula
|
|
405
405
|
# NOTE: even though regression functions (e.g. lm, glm, etc.)
|
|
@@ -439,7 +439,7 @@ runRegression <- function(formula, regtype, dat, outcome) {
|
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
if (length(warns) > 0) results[["warnings"]] <- warns
|
|
442
|
-
results$coefficients <- formatCoefficients(results$coefficients, results$res, input$regressionType)
|
|
442
|
+
results$coefficients <- formatCoefficients(results$coefficients, results$res, input$regressionType, fdat, neuroOnc)
|
|
443
443
|
results$type3 <- formatType3(results$type3)
|
|
444
444
|
out <- list("id" = unbox(id), "data" = results[names(results) != "res"])
|
|
445
445
|
return(out)
|
|
@@ -612,7 +612,7 @@ build_coef_table <- function(res_summ) {
|
|
|
612
612
|
}
|
|
613
613
|
|
|
614
614
|
# reformat the coefficients table
|
|
615
|
-
formatCoefficients <- function(coefficients_table, res, regtype) {
|
|
615
|
+
formatCoefficients <- function(coefficients_table, res, regtype, dat, neuroOnc) {
|
|
616
616
|
# round all columns to 4 significant digits
|
|
617
617
|
coefficients_table <- signif(coefficients_table, 4)
|
|
618
618
|
# add variable and category columns
|
|
@@ -637,8 +637,8 @@ formatCoefficients <- function(coefficients_table, res, regtype) {
|
|
|
637
637
|
if (v2 %in% names(res$xlevels)) {
|
|
638
638
|
clst2 <- res$xlevels[[v2]][-1] # extract categories (without reference category)
|
|
639
639
|
}
|
|
640
|
-
for (
|
|
641
|
-
for (
|
|
640
|
+
for (c2 in clst2) {
|
|
641
|
+
for (c1 in clst1) {
|
|
642
642
|
cCol <- c(cCol, paste(c1, c2, sep = ":"))
|
|
643
643
|
vCol <- c(vCol, v)
|
|
644
644
|
}
|
|
@@ -667,7 +667,44 @@ formatCoefficients <- function(coefficients_table, res, regtype) {
|
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
|
-
|
|
670
|
+
|
|
671
|
+
if (regtype == "cox" && !is.null(neuroOnc)) {
|
|
672
|
+
# neuro-oncology dataset using cox regression
|
|
673
|
+
# report sample size and event counts of coefficients
|
|
674
|
+
sCol <- vector(mode = "character")
|
|
675
|
+
eCol <- vector(mode = "character")
|
|
676
|
+
for (i in 1:length(vCol)) {
|
|
677
|
+
v <- vCol[i]
|
|
678
|
+
c <- cCol[i]
|
|
679
|
+
if (grepl(":", v, fixed = T)) {
|
|
680
|
+
# interacting variables
|
|
681
|
+
# not allowed in neuro-oncology dataset
|
|
682
|
+
stop("interacting variables not supported")
|
|
683
|
+
}
|
|
684
|
+
if (v %in% names(res$xlevels)) {
|
|
685
|
+
# categorical variable
|
|
686
|
+
# determine sample size and event count of both ref and non-ref categories
|
|
687
|
+
# values will be stored in separate columns in the format "ref/nonref"
|
|
688
|
+
ref <- res$xlevels[[v]][1]
|
|
689
|
+
m <- table(dat[,"outcome_event"], dat[,v])
|
|
690
|
+
samplesize_ref <- sum(m[,ref])
|
|
691
|
+
samplesize_c <- sum(m[,c])
|
|
692
|
+
sCol <- c(sCol, paste(samplesize_ref, samplesize_c, sep = "/"))
|
|
693
|
+
eventcnt_ref <- m["1",ref]
|
|
694
|
+
eventcnt_c <- m["1",c]
|
|
695
|
+
eCol <- c(eCol, paste(eventcnt_ref, eventcnt_c, sep = "/"))
|
|
696
|
+
} else {
|
|
697
|
+
# continuous variable
|
|
698
|
+
# set sample size and event count to NA
|
|
699
|
+
sCol <- c(sCol, NA)
|
|
700
|
+
eCol <- c(eCol, NA)
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
coefficients_table <- cbind("Variable" = vCol, "Category" = cCol, "Sample Size (ref/non-ref)" = sCol, "Events (ref/non-ref)" = eCol, coefficients_table)
|
|
704
|
+
} else {
|
|
705
|
+
coefficients_table <- cbind("Variable" = vCol, "Category" = cCol, coefficients_table)
|
|
706
|
+
}
|
|
707
|
+
|
|
671
708
|
coefficients_table <- list("header" = colnames(coefficients_table), "rows" = coefficients_table)
|
|
672
709
|
return(coefficients_table)
|
|
673
710
|
}
|
package/utils/survival.R
CHANGED
|
@@ -69,11 +69,19 @@ if (length(levels(dat$series)) == 1) {
|
|
|
69
69
|
estimates <- rbind(estimates, estimates_series)
|
|
70
70
|
}
|
|
71
71
|
# test for difference between survival curves using log-rank test
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
df <- dat[dat$series %in% pair, c("time", "status")]
|
|
73
|
+
if (all(apply(df, 2, function(x) length(unique(x)) == 1))) {
|
|
74
|
+
# survival curves are identical
|
|
75
|
+
# do not compare curves using survdiff() because it will error out
|
|
76
|
+
# set pvalue to 1
|
|
77
|
+
pvalue <- 1
|
|
78
|
+
} else {
|
|
79
|
+
# suppress warnings to prevent warnings when test is done between
|
|
80
|
+
# curves with no events
|
|
81
|
+
test <- suppressWarnings(survdiff(Surv(time, status) ~ series, data = dat, subset = dat$series %in% pair))
|
|
82
|
+
# compute p-value (see: https://www.emilyzabor.com/tutorials/survival_analysis_in_r_tutorial.html#Extracting_information_from_a_survdiff_object)
|
|
83
|
+
pvalue <- 1 - pchisq(test$chisq, length(test$n) - 1)
|
|
84
|
+
}
|
|
77
85
|
tests[i,] <- c(pair, signif(pvalue, 2))
|
|
78
86
|
}
|
|
79
87
|
}
|