-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from uclahs-cds/lyl-presto1-revision
LYL add PRESTO1 analysis code
- Loading branch information
Showing
19 changed files
with
302 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
Package: EXONC.DEXP | ||
Package: EXOC.DPEx | ||
Type: Package | ||
Title: A Digital, Decentralized Clinical Trial of Exercise Therapy in Cancer (EXONC.DEXP) | ||
Version: 0.1.0 | ||
Author: Who wrote it | ||
Maintainer: Stefan Eng <[email protected]> | ||
Description: Code for 'A Digital, Decentralized Clinical Trial of Exercise Therapy in Cancer (EXONC.DEXP)' | ||
Depends: | ||
R (>= 2.10) | ||
Suggests: | ||
performance, | ||
testthat (>= 3.0.0), | ||
fs | ||
Title: Decentralized Clinical Trial of Exercise Therapy in Cancer | ||
Version: 0.2.0 | ||
Author: Stefan Eng, Lydia Y Liu | ||
Maintainer: Zhuyu Qiu <[email protected]> | ||
Description: Code for 'Phase 1a, Decentralized Trial of Neoadjuvant Exercise Therapy in Prostate Cancer (PRESTO1)' and 'A Digital, Decentralized Clinical Trial of Exercise Therapy in Cancer (DPEx)' | ||
Depends: R (>= 2.10) | ||
Suggests: performance, | ||
testthat (>= 3.0.0), | ||
fs | ||
Config/testthat/edition: 3 | ||
License: GPL-2 | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Imports: | ||
latticeExtra, | ||
BoutrosLab.plotting.general, | ||
plyr, | ||
lsr, | ||
lmerTest, | ||
slider | ||
Imports: latticeExtra, | ||
BoutrosLab.plotting.general, | ||
plyr, | ||
lsr, | ||
lmerTest, | ||
slider | ||
RoxygenNote: 7.2.1 |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# EXONC.DEXP 0.1.0 | ||
# EXOC.DPEx 0.1.0 | ||
|
||
* Initial plot and code changes for EXONC.DEXP: A Digital, Decentralized Clinical Trial of Exercise Therapy in Cancer | ||
- Initial plot and code changes for DPEx: A Digital, Decentralized Clinical Trial of Exercise Therapy in Cancer | ||
|
||
# EXOC.DPEx 0.2.0 | ||
|
||
- Addition of supplementary table code for PRESTO1: Phase 1a, Decentralized Trial of Neoadjuvant Exercise Therapy in Prostate Cancer |
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,103 @@ | ||
mean.delta.analysis <- function(daily.summary, dosage, results.path) { | ||
|
||
diff.list <- lapply(split(daily.summary, daily.summary$patient), function(x) calculate.daily.summary.mean.delta(x, plot_vars)) | ||
|
||
diff.df <- plyr::rbind.fill(diff.list) | ||
diff.df <- cbind(patient = patients, diff.df) | ||
print(summary(diff.df)) | ||
|
||
# merge with dose | ||
diff.df <- merge( | ||
x = diff.df, | ||
y = dosage[, c('patient', 'dose', 'relative.dose.intensity')], | ||
by = 'patient', | ||
all.x = TRUE | ||
) | ||
|
||
# calculate delta per variable | ||
doses <- sort(unique(dosage$dose), na.last = NA) | ||
diff.df$dose.fct <- factor(diff.df$dose, levels = doses) | ||
|
||
# output in table | ||
diff.output <- lapply(plot_vars, function(x) { | ||
|
||
# table for each dose level | ||
dose.diff.model <- lm(diff.df[, x] ~ 0 + diff.df$dose.fct) | ||
dose.diff.table <- cbind.data.frame(dose = doses, summary(dose.diff.model)$coefficient) | ||
|
||
# table for all patients | ||
dose.diff.model.all <- lm(diff.df[, x] ~ 1) | ||
dose.diff.table.all <- cbind.data.frame(dose = 0, summary(dose.diff.model.all)$coefficient) | ||
dose.diff.table <- rbind(dose.diff.table.all, dose.diff.table) | ||
|
||
dose.diff.string <- paste0(round(dose.diff.table$Estimate, 1), | ||
' (', round(dose.diff.table$Estimate - dose.diff.table[, 'Std. Error'] * 1.96, 1), | ||
' - ', round(dose.diff.table$Estimate + dose.diff.table[, 'Std. Error'] * 1.96, 1), | ||
')') | ||
dose.diff.df <- as.data.frame(matrix(dose.diff.string, ncol = length(dose.diff.string))) | ||
colnames(dose.diff.df) <- dose.diff.table$dose | ||
|
||
dose.diff.df | ||
}) | ||
|
||
dose.diff.df <- plyr::rbind.fill(diff.output) | ||
colnames(dose.diff.df) <- paste0('Dose: ', colnames(dose.diff.df), ' (minutes)') | ||
dose.diff.df <- cbind(Variable = vars_nice_names, dose.diff.df) | ||
|
||
filename <- print(file.path( | ||
results.path, | ||
generate.filename( | ||
'phase1_0b-prostate', 'daily_summary_before7_after7_diff_mean_ci', 'tsv' | ||
) | ||
)) | ||
write.table(dose.diff.df, filename, quote = F, sep = '\t', row.names = F, col.names = T) | ||
|
||
} | ||
|
||
|
||
calculate.daily.summary.mean.delta <- function(daily.summary, vars, | ||
days = 7) { | ||
|
||
print(vars[!vars %in% colnames(daily.summary)]) | ||
vars <- vars[vars %in% colnames(daily.summary)] | ||
|
||
res <- sapply(vars, function(v) { | ||
|
||
x <- daily.summary$nday | ||
y <- daily.summary[, v] | ||
|
||
# TODO: adhoc dealing with duplicated x for now | ||
if (any(duplicated(x))) { | ||
which.dup <- which(duplicated(x) | duplicated(x, fromLast = T)) | ||
if (v %in% c('sleep_length')) { | ||
z <- sum(y[which.dup]) | ||
y <- c(z, y[-which.dup]) | ||
} else { | ||
# includes start.diff.midnight, take first value | ||
y <- y[-which.dup[length(which.dup)]] | ||
} | ||
|
||
x <- x[!duplicated(x)] | ||
stopifnot(length(x) == length(y)) | ||
} | ||
|
||
before <- y[1:days] | ||
before.mean <- mean(before, na.rm = T) | ||
|
||
# actually takes the last days + 1 | ||
after <- y[(length(y) - days + 1):length(y)] | ||
after.mean <- mean(after, na.rm = T) | ||
|
||
# print(y) | ||
# print(c(before.mean, after.mean)) | ||
|
||
res <- after.mean - before.mean | ||
|
||
}) | ||
|
||
res <- as.data.frame(matrix(res, nrow = 1, byrow = T)) | ||
colnames(res) <- vars | ||
|
||
return(res) | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,26 +1,25 @@ | ||
# Project/Repo Title | ||
# Decentralized Trial of Exercise Therapy in Cancer | ||
|
||
Template Repository for the Boutros Lab R package repos. Describe a simple overview of use/purpose here. | ||
This repository contains analysis code for the following projects | ||
|
||
## How to Use This Template | ||
- PRESTO1: Phase 1a, Decentralized Trial of Neoadjuvant Exercise Therapy in Prostate Cancer | ||
- DPEx: A Digital, Decentralized Trial of Exercise Therapy in Patients with Cancer | ||
|
||
- Replace all placeholder text in the sections below. | ||
|
||
- Update metadata.yaml and DESCRIPTION with your project title, contributors, etc. | ||
## Description | ||
|
||
- Replace all occurrences of `BoutrosLabTemplate` in .github/workflows/R-CMD-check.yaml with your project title (same as title in in DESCRIPTION). | ||
### PRESTO1 | ||
|
||
## Description | ||
Analysis of lifestyle states and physiological outcomes | ||
|
||
An in-depth paragraph about your project and overview of use. | ||
- summary tables generated by `inst/scripts/submax_delta.R` and `inst/scripts/daily_summary_mean_diff.R` | ||
|
||
## License | ||
|
||
Author: Name1([email protected]), Name2([email protected]) | ||
Author: Stefan Eng, Lydia Y Liu | ||
|
||
[This project] is licensed under the GNU General Public License version 2. See the file LICENSE.md for the terms of the GNU GPL license. | ||
EXOC.Analysis is licensed under the GNU General Public License version 2. See the file LICENSE.md for the terms of the GNU GPL license. | ||
|
||
<one line to give the project/program's name and a brief idea of what it does.> | ||
Data analysis and visualization code for decentrailized trial of exercise therapy in cancer | ||
|
||
Copyright (C) 2021 University of California Los Angeles ("Boutros Lab") All rights reserved. | ||
|
||
|
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,47 @@ | ||
library(EXOC.DPEx); | ||
library(BoutrosLab.plotting.general); | ||
library(lme4); | ||
library(lmerTest); | ||
|
||
script.name <- 'daily_summary_mean_diff'; | ||
data.folder <- Sys.getenv('EXONC_HOME'); | ||
if (data.folder == '') data.folder <- 'DEXP_results'; | ||
plot.path <- file.path(data.folder, 'digIT-EX', 'plots', script.name); | ||
results.path <- file.path(data.folder, 'digIT-EX', 'results', script.name); | ||
extension <- 'png'; | ||
|
||
analysis.init( | ||
data.folder = data.folder, | ||
script.name = script.name, | ||
split.stdout = TRUE, | ||
expr = { | ||
daily.summary <- read.table( | ||
# TODO: Fix paths | ||
system.file('extdata', 'daily_summary.tsv', package = 'EXOC.DPEx'), | ||
sep = '\t', | ||
header = TRUE | ||
); | ||
|
||
# load dosage file | ||
dosage <- read.table( | ||
file.path(data.folder, 'raw_data', 'Phase1', 'Dose_finding', 'PRESTO_Dose_levels.tsv'), | ||
sep = '\t', | ||
header = TRUE | ||
); | ||
dosage$patient <- sprintf('EX%03d', dosage$patient.identifier); | ||
|
||
# merge with dosage | ||
daily.summary <- merge( | ||
x = daily.summary, | ||
y = dosage[, c('patient', 'dose', 'relative.dose.intensity')], | ||
by = 'patient', | ||
all.x = TRUE | ||
) | ||
|
||
mean.delta.analysis(daily.summary, | ||
dosage, | ||
results.path = results.path | ||
) | ||
|
||
} | ||
); |
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
Oops, something went wrong.