From 1a504d23652f6da2fae1fe792f8d4d9d0e4f07e8 Mon Sep 17 00:00:00 2001 From: Jeremy Wildfire Date: Thu, 10 Nov 2022 09:53:30 -0500 Subject: [PATCH 01/20] remove strType. fix #849 --- R/Disp_Assess.R | 8 ++------ R/PD_Assess.R | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/R/Disp_Assess.R b/R/Disp_Assess.R index c8da478d9..392e89aa0 100644 --- a/R/Disp_Assess.R +++ b/R/Disp_Assess.R @@ -16,9 +16,6 @@ #' - `"NormalApprox"` (default) #' - `"fisher"` #' - `"identity"` -#' @param strType `character` Statistical outcome type. Valid values: -#' - `"binary"` (default) -#' - `"rate"` #' @param lMapping Column metadata with structure `domain$key`, where `key` contains the name #' of the column. #' @param strGroup `character` Grouping variable. `"Site"` (the default) uses the column named in `mapping$strSiteCol`. Other valid options using the default mapping are `"Study"` and `"CustomGroup"`. @@ -62,7 +59,6 @@ Disp_Assess <- function( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "binary", lMapping = yaml::read_yaml(system.file("mappings", "Disp_Assess.yaml", package = "gsm")), strGroup = "Site", nConfLevel = NULL, @@ -132,14 +128,14 @@ Disp_Assess <- function( lData$dfAnalyzed <- gsm::Analyze_NormalApprox( dfTransformed = lData$dfTransformed, - strType = strType, + strType = "binary", bQuiet = bQuiet ) lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds( dfTransformed = lData$dfTransformed, vThreshold = vThreshold, - strType = strType, + strType = "binary", bQuiet = bQuiet ) diff --git a/R/PD_Assess.R b/R/PD_Assess.R index 2ffb0e1a4..7338881e2 100644 --- a/R/PD_Assess.R +++ b/R/PD_Assess.R @@ -16,9 +16,6 @@ #' - `"NormalApprox"` (default) #' - `"poisson"` #' - `"identity"` -#' @param strType `character` Statistical outcome type. Valid values: -#' - `"binary"` (default) -#' - `"rate"` #' @param lMapping Column metadata with structure `domain$key`, where `key` contains the name #' of the column. #' @param strGroup `character` Grouping variable. `"Site"` (the default) uses the column named in `mapping$strSiteCol`. Other valid options using the default mapping are `"Study"` and `"CustomGroup"`. @@ -60,7 +57,6 @@ PD_Assess <- function( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "rate", lMapping = yaml::read_yaml(system.file("mappings", "PD_Assess.yaml", package = "gsm")), strGroup = "Site", nConfLevel = NULL, @@ -128,14 +124,14 @@ PD_Assess <- function( lData$dfAnalyzed <- gsm::Analyze_NormalApprox( dfTransformed = lData$dfTransformed, - strType = strType, + strType = "rate", bQuiet = bQuiet ) lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds( dfTransformed = lData$dfTransformed, vThreshold = vThreshold, - strType = strType, + strType = "rate", bQuiet = bQuiet ) From 91d3636349e283b995911e5229da2c1bb546e24f Mon Sep 17 00:00:00 2001 From: Jeremy Wildfire Date: Thu, 10 Nov 2022 10:30:36 -0500 Subject: [PATCH 02/20] prototype for QTL flag method. #864 --- R/Disp_Assess.R | 6 ++--- R/Flag_QTL.R | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ R/PD_Assess.R | 6 ++--- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 R/Flag_QTL.R diff --git a/R/Disp_Assess.R b/R/Disp_Assess.R index 392e89aa0..0012b9396 100644 --- a/R/Disp_Assess.R +++ b/R/Disp_Assess.R @@ -90,7 +90,7 @@ Disp_Assess <- function( NormalApprox = c(-3, -2, 2, 3), fisher = c(0.01, 0.05), identity = c(3.491, 5.172), - qtl = c(0, 0.2) + qtl = c(0.2) ) } @@ -158,14 +158,14 @@ Disp_Assess <- function( } else if (strMethod == "identity") { lData$dfFlagged <- gsm::Flag(lData$dfAnalyzed, vThreshold = vThreshold, strValueColumn = strValueColumnVal) } else if (strMethod == "qtl") { - lData$dfFlagged <- gsm::Flag(lData$dfAnalyzed, vThreshold = vThreshold) + lData$dfFlagged <- gsm::Flag_QTL(lData$dfAnalyzed, vThreshold = vThreshold) } flag_function_name <- switch(strMethod, NormalApprox = "Flag_NormalApprox", identity = "Flag", fisher = "Flag_Fisher", - qtl = "Flag" + qtl = "Flag_QTL" ) if (!bQuiet) cli::cli_alert_success("{.fn {flag_function_name}} returned output with {nrow(lData$dfFlagged)} rows.") diff --git a/R/Flag_QTL.R b/R/Flag_QTL.R new file mode 100644 index 000000000..56c839c45 --- /dev/null +++ b/R/Flag_QTL.R @@ -0,0 +1,58 @@ +#' Flag QTL +#' +#' @details +#' This function flags a study-level QTL metric by comparing the mean and lower confidence bound for the metric to a single threhsold. +#' +#' @section Data Specification: +#' \code{Flag_NormalApprox} is designed to support the input data (`dfAnalyzed`) from \code{Analyze_QTL} function. +#' At a minimum, the input data must have numeric `Score` and `LowCI` columns that will be compared to the specified threshold (`vThreshold`) to +#' calculate a new `Flag` column. +#' +#' @param dfAnalyzed data.frame where flags should be added. +#' @param vThreshold Numeric value representing the threshold. NA and NaN values in strColumn are given NA flag values. +#' +#' @return `data.frame` with "Flag" column added +#' +#' @examples +#' dfInput <- Disp_Map_Raw() +#' dfTransformed <- Transform_Rate( +#' dfInput, +#' strGroupCol = "StudyID", +#' strNumeratorCol = "Count", +#' strDenominatorCol = "Total" +#' ) +#' dfAnalyzed <- Analyze_QTL(dfTransformed) +#' dfFlagged <- Flag_QTL(dfAnalyzed) +#' +#' @import dplyr +#' +#' @export + +Flag_QTL <- function( + dfAnalyzed, + vThreshold = NULL +) { + stopifnot( + "dfAnalyzed is not a data frame" = is.data.frame(dfAnalyzed), + "Required columns not found"= all(c("Score","LowCI") %in% names(dfAnalyzed)), + "vThreshold is not numeric" = is.numeric(vThreshold), + "vThreshold must be length of 1" = length(vThreshold) == 1, + "vThreshold cannot be NULL" = !is.null(vThreshold), + + ) + + # Flag values outside the specified threshold. + dfFlagged <- dfAnalyzed %>% + mutate( + Flag = case_when( + (.data$LowCI > vThreshold) ~ 2, + (.data$Score > vThreshold) ~ 1, + TRUE ~ 0 + ) + ) + + dfFlagged <- dfFlagged %>% + arrange(match(.data$Flag, c( 2, 1, 0))) + + return(dfFlagged) +} diff --git a/R/PD_Assess.R b/R/PD_Assess.R index 7338881e2..cb9a15cbe 100644 --- a/R/PD_Assess.R +++ b/R/PD_Assess.R @@ -86,7 +86,7 @@ PD_Assess <- function( NormalApprox = c(-3, -2, 2, 3), poisson = c(-7, -5, 5, 7), identity = c(0.000895, 0.003059), - qtl = c(0, 5) + qtl = c(5) ) } @@ -156,14 +156,14 @@ PD_Assess <- function( } else if (strMethod == "identity") { lData$dfFlagged <- gsm::Flag(lData$dfAnalyzed, vThreshold = vThreshold, strValueColumn = strValueColumnVal) } else if (strMethod == "qtl") { - lData$dfFlagged <- gsm::Flag(lData$dfAnalyzed, vThreshold = vThreshold) + lData$dfFlagged <- gsm::Flag_QTL(lData$dfAnalyzed, vThreshold = vThreshold) } flag_function_name <- switch(strMethod, NormalApprox = "Flag_NormalApprox", identity = "Flag", poisson = "Flag_Poisson", - qtl = "Flag" + qtl = "Flag_QTL" ) if (!bQuiet) cli::cli_alert_success("{.fn {flag_function_name}} returned output with {nrow(lData$dfFlagged)} rows.") From 1385958975587c0d42890501b897584f76fbd065 Mon Sep 17 00:00:00 2001 From: Jeremy Wildfire Date: Thu, 10 Nov 2022 10:59:55 -0500 Subject: [PATCH 03/20] spec for results_analysis. #863 --- R/Make_Snapshot.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index ea5c80857..3d9e46346 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -180,6 +180,11 @@ bQuiet = TRUE score = "Score", flag = "Flag" ) + + # results_analysis --------------------------------------------------------- + + # Leaving this data munging for Matt/Spencer/Kai. Columns = workflowid, groupid, param, value. + # for now, we just want to add Param = "LowCI", "UpperCI", "Mean" for the 2 QTLs. So 6 rows for now. # lSnapshot$results_summary$StudyID <- meta$status_study[1,'StudyID'] From 4f21bb27aad6429e04c6d0a8505ba8646c774908 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Thu, 10 Nov 2022 22:33:49 +0000 Subject: [PATCH 04/20] add results_analysis + cleanup --- NAMESPACE | 1 + R/AE_Assess.R | 8 ++--- R/AE_Map_Raw.R | 1 + R/Flag_QTL.R | 13 ++++---- R/LB_Assess.R | 8 ++--- R/Make_Snapshot.R | 24 +++++++++++---- _pkgdown.yml | 1 + man/AE_Assess.Rd | 7 ----- man/Disp_Assess.Rd | 7 ----- man/Flag_QTL.Rd | 41 ++++++++++++++++++++++++++ man/LB_Assess.Rd | 7 ----- man/PD_Assess.Rd | 7 ----- tests/testthat/_snaps/Make_Snapshot.md | 10 +++---- 13 files changed, 79 insertions(+), 56 deletions(-) create mode 100644 man/Flag_QTL.Rd diff --git a/NAMESPACE b/NAMESPACE index 6abbde690..9964395d5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(Flag) export(Flag_Fisher) export(Flag_NormalApprox) export(Flag_Poisson) +export(Flag_QTL) export(Get_Enrolled) export(IE_Assess) export(IE_Map_Raw) diff --git a/R/AE_Assess.R b/R/AE_Assess.R index 69cbf7ebb..dc7c9e47d 100644 --- a/R/AE_Assess.R +++ b/R/AE_Assess.R @@ -17,9 +17,6 @@ #' - `"NormalApprox"` (default) #' - `"poisson"` #' - `"identity"` -#' @param strType `character` Statistical outcome type. Valid values: -#' - `"binary"` -#' - `"rate"` (default) #' @param lMapping Column metadata with structure `domain$key`, where `key` contains the name #' of the column. #' @param strGroup `character` Grouping variable. `"Site"` (the default) uses the column named in `mapping$strSiteCol`. @@ -62,7 +59,6 @@ AE_Assess <- function( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "rate", lMapping = yaml::read_yaml(system.file("mappings", "AE_Assess.yaml", package = "gsm")), strGroup = "Site", bQuiet = TRUE @@ -128,14 +124,14 @@ AE_Assess <- function( lData$dfAnalyzed <- gsm::Analyze_NormalApprox( dfTransformed = lData$dfTransformed, - strType = strType, + strType = "rate", bQuiet = bQuiet ) lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds( dfTransformed = lData$dfTransformed, vThreshold = vThreshold, - strType = strType, + strType = "rate", bQuiet = bQuiet ) diff --git a/R/AE_Map_Raw.R b/R/AE_Map_Raw.R index bcc547670..00bac735e 100644 --- a/R/AE_Map_Raw.R +++ b/R/AE_Map_Raw.R @@ -47,6 +47,7 @@ AE_Map_Raw <- function( bReturnChecks = FALSE, bQuiet = TRUE ) { + stopifnot( "bReturnChecks must be logical" = is.logical(bReturnChecks), "bQuiet must be logical" = is.logical(bQuiet) diff --git a/R/Flag_QTL.R b/R/Flag_QTL.R index 56c839c45..da28d7c07 100644 --- a/R/Flag_QTL.R +++ b/R/Flag_QTL.R @@ -1,13 +1,13 @@ #' Flag QTL #' #' @details -#' This function flags a study-level QTL metric by comparing the mean and lower confidence bound for the metric to a single threhsold. +#' This function flags a study-level QTL metric by comparing the mean and lower confidence bound for the metric to a single threhsold. #' #' @section Data Specification: #' \code{Flag_NormalApprox} is designed to support the input data (`dfAnalyzed`) from \code{Analyze_QTL} function. #' At a minimum, the input data must have numeric `Score` and `LowCI` columns that will be compared to the specified threshold (`vThreshold`) to #' calculate a new `Flag` column. -#' +#' #' @param dfAnalyzed data.frame where flags should be added. #' @param vThreshold Numeric value representing the threshold. NA and NaN values in strColumn are given NA flag values. #' @@ -22,7 +22,7 @@ #' strDenominatorCol = "Total" #' ) #' dfAnalyzed <- Analyze_QTL(dfTransformed) -#' dfFlagged <- Flag_QTL(dfAnalyzed) +#' dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.02) #' #' @import dplyr #' @@ -32,13 +32,14 @@ Flag_QTL <- function( dfAnalyzed, vThreshold = NULL ) { + stopifnot( "dfAnalyzed is not a data frame" = is.data.frame(dfAnalyzed), - "Required columns not found"= all(c("Score","LowCI") %in% names(dfAnalyzed)), + "Required columns not found" = all(c("Score", "LowCI") %in% names(dfAnalyzed)), "vThreshold is not numeric" = is.numeric(vThreshold), "vThreshold must be length of 1" = length(vThreshold) == 1, - "vThreshold cannot be NULL" = !is.null(vThreshold), - + "vThreshold cannot be NULL" = !is.null(vThreshold) + ) # Flag values outside the specified threshold. diff --git a/R/LB_Assess.R b/R/LB_Assess.R index d98598a89..4c12af42e 100644 --- a/R/LB_Assess.R +++ b/R/LB_Assess.R @@ -16,9 +16,6 @@ #' - `"NormalApprox"` (default) #' - `"fisher"` #' - `"identity"` -#' @param strType `character` Statistical outcome type. Valid values: -#' - `"binary"` (default) -#' - `"rate"` #' @param lMapping Column metadata with structure `domain$key`, where `key` contains the name #' of the column. #' @param strGroup `character` Grouping variable. `"Site"` (the default) uses the column named in `mapping$strSiteCol`. Other valid options using the default mapping are `"Study"` and `"CustomGroup"`. @@ -61,7 +58,6 @@ LB_Assess <- function( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "binary", lMapping = yaml::read_yaml(system.file("mappings", "LB_Assess.yaml", package = "gsm")), strGroup = "Site", bQuiet = TRUE @@ -128,14 +124,14 @@ LB_Assess <- function( lData$dfAnalyzed <- gsm::Analyze_NormalApprox( dfTransformed = lData$dfTransformed, - strType = strType, + strType = "binary", bQuiet = bQuiet ) lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds( dfTransformed = lData$dfTransformed, vThreshold = vThreshold, - strType = strType, + strType = "binary", bQuiet = bQuiet ) diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index 3d9e46346..b76a95876 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -180,15 +180,28 @@ bQuiet = TRUE score = "Score", flag = "Flag" ) - + # results_analysis --------------------------------------------------------- + # Leaving this data munging for Matt/Spencer/Kai. Columns = workflowid, groupid, param, value. + # for now, we just want to add Param = "LowCI", "UpperCI", "Mean" for the 2 QTLs. So 6 rows for now. + # lSnapshot$results_summary$StudyID <- meta$status_study[1,'StudyID'] + # Also need to make sure we're capturing WorkflowID here ... + + results_analysis <- lResults[grep("qtl", names(lResults))] %>% + purrr::imap_dfr( + ~ .x$lResults$lData$dfAnalyzed %>% + select(GroupID, + LowCI, + UpCI, + Score) %>% + mutate(workflowid = .y) + ) %>% + pivot_longer(-c("GroupID", "workflowid")) %>% + rename(param = "name", + studyid = "GroupID") - # Leaving this data munging for Matt/Spencer/Kai. Columns = workflowid, groupid, param, value. - # for now, we just want to add Param = "LowCI", "UpperCI", "Mean" for the 2 QTLs. So 6 rows for now. - # lSnapshot$results_summary$StudyID <- meta$status_study[1,'StudyID'] - # Also need to make sure we're capturing WorkflowID here ... # results_bounds ---------------------------------------------------------- results_bounds <- lResults %>% @@ -216,6 +229,7 @@ bQuiet = TRUE status_param = status_param, status_schedule = status_schedule, results_summary = results_summary, + results_analysis = results_analysis, results_bounds = results_bounds, meta_workflow = meta_workflow, meta_param = meta_param diff --git a/_pkgdown.yml b/_pkgdown.yml index 78613ed5a..963529a21 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -37,6 +37,7 @@ reference: - Flag_Fisher - Flag_NormalApprox - Flag_Poisson + - Flag_QTL - Summarize - title: Reporting diff --git a/man/AE_Assess.Rd b/man/AE_Assess.Rd index 6fd72ab92..f7a2c0e67 100644 --- a/man/AE_Assess.Rd +++ b/man/AE_Assess.Rd @@ -8,7 +8,6 @@ AE_Assess( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "rate", lMapping = yaml::read_yaml(system.file("mappings", "AE_Assess.yaml", package = "gsm")), strGroup = "Site", bQuiet = TRUE @@ -28,12 +27,6 @@ for a nominal assessment (\code{strMethod = "identity"}).} \item \code{"identity"} }} -\item{strType}{\code{character} Statistical outcome type. Valid values: -\itemize{ -\item \code{"binary"} -\item \code{"rate"} (default) -}} - \item{lMapping}{Column metadata with structure \code{domain$key}, where \code{key} contains the name of the column.} diff --git a/man/Disp_Assess.Rd b/man/Disp_Assess.Rd index bddc9a080..8aa02d52e 100644 --- a/man/Disp_Assess.Rd +++ b/man/Disp_Assess.Rd @@ -8,7 +8,6 @@ Disp_Assess( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "binary", lMapping = yaml::read_yaml(system.file("mappings", "Disp_Assess.yaml", package = "gsm")), strGroup = "Site", @@ -29,12 +28,6 @@ Disp_Assess( \item \code{"identity"} }} -\item{strType}{\code{character} Statistical outcome type. Valid values: -\itemize{ -\item \code{"binary"} (default) -\item \code{"rate"} -}} - \item{lMapping}{Column metadata with structure \code{domain$key}, where \code{key} contains the name of the column.} diff --git a/man/Flag_QTL.Rd b/man/Flag_QTL.Rd new file mode 100644 index 000000000..9837a44e4 --- /dev/null +++ b/man/Flag_QTL.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Flag_QTL.R +\name{Flag_QTL} +\alias{Flag_QTL} +\title{Flag QTL} +\usage{ +Flag_QTL(dfAnalyzed, vThreshold = NULL) +} +\arguments{ +\item{dfAnalyzed}{data.frame where flags should be added.} + +\item{vThreshold}{Numeric value representing the threshold. NA and NaN values in strColumn are given NA flag values.} +} +\value{ +\code{data.frame} with "Flag" column added +} +\description{ +Flag QTL +} +\details{ +This function flags a study-level QTL metric by comparing the mean and lower confidence bound for the metric to a single threhsold. +} +\section{Data Specification}{ + +\code{Flag_NormalApprox} is designed to support the input data (\code{dfAnalyzed}) from \code{Analyze_QTL} function. +At a minimum, the input data must have numeric \code{Score} and \code{LowCI} columns that will be compared to the specified threshold (\code{vThreshold}) to +calculate a new \code{Flag} column. +} + +\examples{ +dfInput <- Disp_Map_Raw() +dfTransformed <- Transform_Rate( + dfInput, + strGroupCol = "StudyID", + strNumeratorCol = "Count", + strDenominatorCol = "Total" +) +dfAnalyzed <- Analyze_QTL(dfTransformed) +dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.02) + +} diff --git a/man/LB_Assess.Rd b/man/LB_Assess.Rd index bbb8f3408..ba3ebbf2c 100644 --- a/man/LB_Assess.Rd +++ b/man/LB_Assess.Rd @@ -8,7 +8,6 @@ LB_Assess( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "binary", lMapping = yaml::read_yaml(system.file("mappings", "LB_Assess.yaml", package = "gsm")), strGroup = "Site", bQuiet = TRUE @@ -27,12 +26,6 @@ LB_Assess( \item \code{"identity"} }} -\item{strType}{\code{character} Statistical outcome type. Valid values: -\itemize{ -\item \code{"binary"} (default) -\item \code{"rate"} -}} - \item{lMapping}{Column metadata with structure \code{domain$key}, where \code{key} contains the name of the column.} diff --git a/man/PD_Assess.Rd b/man/PD_Assess.Rd index c0f764b7b..c516b50e3 100644 --- a/man/PD_Assess.Rd +++ b/man/PD_Assess.Rd @@ -8,7 +8,6 @@ PD_Assess( dfInput, vThreshold = NULL, strMethod = "NormalApprox", - strType = "rate", lMapping = yaml::read_yaml(system.file("mappings", "PD_Assess.yaml", package = "gsm")), strGroup = "Site", nConfLevel = NULL, @@ -28,12 +27,6 @@ PD_Assess( \item \code{"identity"} }} -\item{strType}{\code{character} Statistical outcome type. Valid values: -\itemize{ -\item \code{"binary"} (default) -\item \code{"rate"} -}} - \item{lMapping}{Column metadata with structure \code{domain$key}, where \code{key} contains the name of the column.} diff --git a/tests/testthat/_snaps/Make_Snapshot.md b/tests/testthat/_snaps/Make_Snapshot.md index 70a9defdf..784910fdd 100644 --- a/tests/testthat/_snaps/Make_Snapshot.md +++ b/tests/testthat/_snaps/Make_Snapshot.md @@ -3,9 +3,9 @@ Code names(snapshot) Output - [1] "status_study" "status_site" "status_workflow" "status_param" - [5] "status_schedule" "results_summary" "results_bounds" "meta_workflow" - [9] "meta_param" + [1] "status_study" "status_site" "status_workflow" "status_param" + [5] "status_schedule" "results_summary" "results_analysis" "results_bounds" + [9] "meta_workflow" "meta_param" # input data is structured as expected @@ -491,7 +491,7 @@ Input data has 50 rows. v `Transform_Rate()` returned output with 1 rows. v `Analyze_Qtl()` returned output with 1 rows. - v `Flag()` returned output with 1 rows. + v `Flag_QTL()` returned output with 1 rows. v `Summarize()` returned output with 1 rows. v `PD_Assess()` Successful Saving lResults to `lWorkflow` @@ -532,7 +532,7 @@ Input data has 50 rows. v `Transform_Rate()` returned output with 1 rows. v `Analyze_Qtl()` returned output with 1 rows. - v `Flag()` returned output with 1 rows. + v `Flag_QTL()` returned output with 1 rows. v `Summarize()` returned output with 1 rows. v `Disp_Assess()` Successful Saving lResults to `lWorkflow` From 9035715e4a876c9054132a41f6f54b4c7868bf5a Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Fri, 11 Nov 2022 16:08:33 +0000 Subject: [PATCH 05/20] add unit tests --- tests/testthat/_snaps/Flag_QTL.md | 9 +++++++++ tests/testthat/test_Flag_QTL.R | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/testthat/_snaps/Flag_QTL.md create mode 100644 tests/testthat/test_Flag_QTL.R diff --git a/tests/testthat/_snaps/Flag_QTL.md b/tests/testthat/_snaps/Flag_QTL.md new file mode 100644 index 000000000..379e91096 --- /dev/null +++ b/tests/testthat/_snaps/Flag_QTL.md @@ -0,0 +1,9 @@ +# output is created as expected + + Code + names(dfFlagged) + Output + [1] "GroupID" "Numerator" "Denominator" "Metric" "Method" + [6] "ConfLevel" "Estimate" "LowCI" "UpCI" "Score" + [11] "Flag" + diff --git a/tests/testthat/test_Flag_QTL.R b/tests/testthat/test_Flag_QTL.R new file mode 100644 index 000000000..9d0384435 --- /dev/null +++ b/tests/testthat/test_Flag_QTL.R @@ -0,0 +1,25 @@ +dfAnalyzed <- tibble::tribble( + ~GroupID, ~Numerator, ~Denominator, ~Metric, ~Method, ~ConfLevel, ~Estimate, ~LowCI, ~UpCI, ~Score, + "AA-AA-000-0000", 122, 1301, 0.0937, "Exact binomial test", 0.95, 0.0937, 0.0784, 0.1109, 0.0784 +) + +dfAnalyzed %>% + mutate(Score = NA) %>% + Flag_QTL(vThreshold = 1) + + +test_that("output is created as expected", { + dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.2) + expect_true(is.data.frame(dfFlagged)) + expect_true(all(names(dfAnalyzed) %in% names(dfFlagged))) + expect_snapshot(names(dfFlagged)) +}) + +test_that("incorrect inputs throw errors", { + expect_error(Flag_QTL(list(), vThreshold = 1)) + expect_error(Flag_QTL(dfAnalyzed %>% select(-Score), vThreshold = 1)) + expect_error(Flag_QTL(dfAnalyzed %>% select(-LowCI), vThreshold = 1)) + expect_error(Flag_QTL(dfAnalyzed, vThreshold = "1")) + expect_error(Flag_QTL(dfAnalyzed, vThreshold = c(1, 2))) + expect_error(Flag_QTL(dfAnalyzed)) +}) From b7e52b28db1f02f4e44ca64651aa4ba849c6d005 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Fri, 11 Nov 2022 16:16:00 +0000 Subject: [PATCH 06/20] add logic to check if qtl exists in lResults --- R/Make_Snapshot.R | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index b76a95876..47974abba 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -187,18 +187,30 @@ bQuiet = TRUE # lSnapshot$results_summary$StudyID <- meta$status_study[1,'StudyID'] # Also need to make sure we're capturing WorkflowID here ... - results_analysis <- lResults[grep("qtl", names(lResults))] %>% - purrr::imap_dfr( - ~ .x$lResults$lData$dfAnalyzed %>% - select(GroupID, - LowCI, - UpCI, - Score) %>% - mutate(workflowid = .y) - ) %>% - pivot_longer(-c("GroupID", "workflowid")) %>% - rename(param = "name", - studyid = "GroupID") + hasQTL <- grep("qtl", names(lResults)) + + if (length(hasQTL) > 0) { + results_analysis <- lResults[hasQTL] %>% + purrr::imap_dfr( + ~ .x$lResults$lData$dfAnalyzed %>% + select(GroupID, + LowCI, + UpCI, + Score) %>% + mutate(workflowid = .y) + ) %>% + pivot_longer(-c("GroupID", "workflowid")) %>% + rename(param = "name", + studyid = "GroupID") + } else { + results_analysis <- tibble( + studyid = NA, + workflowid = NA, + param = NA, + value = NA + ) + } + From f11f9ecfe4b4f7b1b751d8846341ae2e15a00917 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Fri, 11 Nov 2022 16:31:14 +0000 Subject: [PATCH 07/20] fix #866; fix #867 --- inst/report/studySummary.rmd | 28 ++++++++++++++-------------- vignettes/Cookbook.Rmd | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/inst/report/studySummary.rmd b/inst/report/studySummary.rmd index da684d606..83c8d0f7b 100644 --- a/inst/report/studySummary.rmd +++ b/inst/report/studySummary.rmd @@ -52,7 +52,7 @@ allFindings <- results %>% table <- gsm::Study_Table(allFindings) overview_tbl <- table$df_summary %>% - mutate(across(everything(), ~ map(., ~ gt::html(.)))) %>% + dplyr::mutate(dplyr::across(dplyr::everything(), ~ purrr::map(., ~ gt::html(.)))) %>% gt::gt() %>% gt::tab_style( style = list( @@ -109,8 +109,8 @@ function showDetails(elem){ for (i in seq_along(results)) { result <- results[[i]] title <- gsm::meta_workflow %>% - filter(workflowid == names(params$assessments)[i]) %>% - pull(metric) + dplyr::filter(workflowid == names(params$assessments)[i]) %>% + dplyr::pull(metric) # title @@ -140,12 +140,12 @@ for (i in seq_along(results)) { flagged <- result$lData$dfSummary %>% - filter(Flag != 0) + dplyr::filter(Flag != 0) if (nrow(flagged) > 0) { flagged %>% - kbl(escape = FALSE) %>% - kable_styling() %>% + kableExtra::kbl(escape = FALSE) %>% + kableExtra::kable_styling() %>% cat() } @@ -161,8 +161,8 @@ for (i in seq_along(results)) { ) details <- result$lData$dfFlagged %>% - filter(Flag != 0) %>% - arrange(., match(GroupID, flagged$GroupID)) + dplyr::filter(Flag != 0) %>% + dplyr::arrange(., match(GroupID, flagged$GroupID)) if (length(unique(flagged$GroupID)) > 0) { cat("
") @@ -172,8 +172,8 @@ for (i in seq_along(results)) { if (nrow(details) > 0) { details %>% - kbl(escape = FALSE) %>% - kable_styling() %>% + kableExtra::kbl(escape = FALSE) %>% + kableExtra::kable_styling() %>% cat() } @@ -213,10 +213,10 @@ AssessmentReport$dfSummary %>% ## Issue List ```{r, results='asis', echo = FALSE, message=FALSE, warning = FALSE} assessment_report <- AssessmentReport$dfAllChecks %>% - filter(check > 1) %>% - mutate( - check = map(check, rank_chg), - across(where(is.character), ~ replace_na(., "")) + dplyr::filter(check > 1) %>% + dplyr::mutate( + check = purrr::map(check, rank_chg), + dplyr::across(where(is.character), ~ tidyr::replace_na(., "")) ) if (nrow(assessment_report) > 0) { diff --git a/vignettes/Cookbook.Rmd b/vignettes/Cookbook.Rmd index 4e061839d..3d3b00901 100644 --- a/vignettes/Cookbook.Rmd +++ b/vignettes/Cookbook.Rmd @@ -253,7 +253,7 @@ library(clindata) multiple_assessments <- Study_Assess() -Study_Report(lAssessments = multiple_assessments, lMeta = list(label = "My Study")) +Study_Report(lAssessments = multiple_assessments) ``` The report will render and be saved to your current working directory. If you would like the report saved in a different location, you can set an output directory using the `strOutpath` argument in the `Study_Report()` function. From da60476064fe1fd524b0d96324b0858e7e6abf81 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Fri, 11 Nov 2022 16:52:12 +0000 Subject: [PATCH 08/20] change score to estimate --- R/Flag_QTL.R | 4 ++-- tests/testthat/test_Flag_QTL.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/Flag_QTL.R b/R/Flag_QTL.R index da28d7c07..3f28b4014 100644 --- a/R/Flag_QTL.R +++ b/R/Flag_QTL.R @@ -35,7 +35,7 @@ Flag_QTL <- function( stopifnot( "dfAnalyzed is not a data frame" = is.data.frame(dfAnalyzed), - "Required columns not found" = all(c("Score", "LowCI") %in% names(dfAnalyzed)), + "Required columns not found" = all(c("Estimate", "LowCI") %in% names(dfAnalyzed)), "vThreshold is not numeric" = is.numeric(vThreshold), "vThreshold must be length of 1" = length(vThreshold) == 1, "vThreshold cannot be NULL" = !is.null(vThreshold) @@ -47,7 +47,7 @@ Flag_QTL <- function( mutate( Flag = case_when( (.data$LowCI > vThreshold) ~ 2, - (.data$Score > vThreshold) ~ 1, + (.data$Estimate > vThreshold) ~ 1, TRUE ~ 0 ) ) diff --git a/tests/testthat/test_Flag_QTL.R b/tests/testthat/test_Flag_QTL.R index 9d0384435..3fda96435 100644 --- a/tests/testthat/test_Flag_QTL.R +++ b/tests/testthat/test_Flag_QTL.R @@ -17,7 +17,7 @@ test_that("output is created as expected", { test_that("incorrect inputs throw errors", { expect_error(Flag_QTL(list(), vThreshold = 1)) - expect_error(Flag_QTL(dfAnalyzed %>% select(-Score), vThreshold = 1)) + expect_error(Flag_QTL(dfAnalyzed %>% select(-Estimate), vThreshold = 1)) expect_error(Flag_QTL(dfAnalyzed %>% select(-LowCI), vThreshold = 1)) expect_error(Flag_QTL(dfAnalyzed, vThreshold = "1")) expect_error(Flag_QTL(dfAnalyzed, vThreshold = c(1, 2))) From dc1a84875b03765dbeeacfa6971f7cfd4a79e593 Mon Sep 17 00:00:00 2001 From: Spencer Childress Date: Mon, 14 Nov 2022 14:12:39 -0500 Subject: [PATCH 09/20] fix `nStep` in *_PredictBounds functions --- R/Analyze_NormalApprox_PredictBounds.R | 2 +- R/Analyze_Poisson_PredictBounds.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/Analyze_NormalApprox_PredictBounds.R b/R/Analyze_NormalApprox_PredictBounds.R index 3f168ca4f..94357cd38 100644 --- a/R/Analyze_NormalApprox_PredictBounds.R +++ b/R/Analyze_NormalApprox_PredictBounds.R @@ -60,7 +60,7 @@ Analyze_NormalApprox_PredictBounds <- function( dfTransformed, vThreshold = c(-3, -2, 2, 3), - nStep = 1, + nStep = 100, strType = "binary", bQuiet = TRUE ) { diff --git a/R/Analyze_Poisson_PredictBounds.R b/R/Analyze_Poisson_PredictBounds.R index 5911da5c5..724de0f85 100644 --- a/R/Analyze_Poisson_PredictBounds.R +++ b/R/Analyze_Poisson_PredictBounds.R @@ -49,7 +49,7 @@ Analyze_Poisson_PredictBounds <- function( dfTransformed, vThreshold = c(-5, 5), - nStep = 1, + nStep = .05, bQuiet = TRUE ) { if (is.null(vThreshold)) { From 1c38158baec3c6cab9403d0060beb0fc725c5699 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Mon, 14 Nov 2022 22:53:50 +0000 Subject: [PATCH 10/20] add filter for denominator > 0 --- R/Analyze_NormalApprox_PredictBounds.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/Analyze_NormalApprox_PredictBounds.R b/R/Analyze_NormalApprox_PredictBounds.R index 56dd0633b..acd011fa8 100644 --- a/R/Analyze_NormalApprox_PredictBounds.R +++ b/R/Analyze_NormalApprox_PredictBounds.R @@ -81,6 +81,7 @@ Analyze_NormalApprox_PredictBounds <- function( if (strType == "binary") { dfBounds <- tidyr::expand_grid(Threshold = vThreshold, Denominator = vRange) %>% + filter(.data$Denominator > 0) %>% mutate( LogDenominator = log(.data$Denominator), # Calculate expected event percentage at sample size. @@ -102,6 +103,7 @@ Analyze_NormalApprox_PredictBounds <- function( ) } else if (strType == "rate") { dfBounds <- tidyr::expand_grid(Threshold = vThreshold, Denominator = vRange) %>% + filter(.data$Denominator > 0) %>% mutate( LogDenominator = log(.data$Denominator), # Calculate expected rate at given exposure. From e96e97686bcb14e5ee6717087bf3ed8a08d3f7f1 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Tue, 15 Nov 2022 13:56:56 +0000 Subject: [PATCH 11/20] update docs --- man/Analyze_NormalApprox_PredictBounds.Rd | 2 +- man/Analyze_Poisson_PredictBounds.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/man/Analyze_NormalApprox_PredictBounds.Rd b/man/Analyze_NormalApprox_PredictBounds.Rd index 9bd36dffc..04aa0fa60 100644 --- a/man/Analyze_NormalApprox_PredictBounds.Rd +++ b/man/Analyze_NormalApprox_PredictBounds.Rd @@ -7,7 +7,7 @@ Analyze_NormalApprox_PredictBounds( dfTransformed, vThreshold = c(-3, -2, 2, 3), - nStep = 1, + nStep = 100, strType = "binary", bQuiet = TRUE ) diff --git a/man/Analyze_Poisson_PredictBounds.Rd b/man/Analyze_Poisson_PredictBounds.Rd index e52e114a7..0cd525c3c 100644 --- a/man/Analyze_Poisson_PredictBounds.Rd +++ b/man/Analyze_Poisson_PredictBounds.Rd @@ -7,7 +7,7 @@ Analyze_Poisson_PredictBounds( dfTransformed, vThreshold = c(-5, 5), - nStep = 1, + nStep = 0.05, bQuiet = TRUE ) } From 812184a2b78efd3cf65c825f462059a6efc2f866 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Tue, 15 Nov 2022 14:09:20 +0000 Subject: [PATCH 12/20] review updates --- R/Analyze_QTL.R | 4 ++-- R/PD_Assess.R | 2 +- man/Analyze_QTL.Rd | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/Analyze_QTL.R b/R/Analyze_QTL.R index 3ca3cfd7a..9c598bfcd 100644 --- a/R/Analyze_QTL.R +++ b/R/Analyze_QTL.R @@ -36,7 +36,7 @@ #' ) #' #' dfAnalyzed <- Analyze_QTL(dfTransformed, strOutcome = "binary") -#' dfFlagged <- Flag(dfAnalyzed, strColumn = "LowCI", vThreshold = c(NA, 0.2)) +#' dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.2) #' #' #' @@ -48,7 +48,7 @@ #' ) #' #' dfAnalyzed <- Analyze_QTL(dfTransformed, strOutcome = "rate") -#' dfFlagged <- Flag(dfAnalyzed, vThreshold = c(NA, 0.01)) +#' dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.01) #' #' @import dplyr #' @importFrom stats binom.test poisson.test diff --git a/R/PD_Assess.R b/R/PD_Assess.R index 891e86856..4d2478379 100644 --- a/R/PD_Assess.R +++ b/R/PD_Assess.R @@ -88,7 +88,7 @@ PD_Assess <- function( NormalApprox = c(-3, -2, 2, 3), poisson = c(-7, -5, 5, 7), identity = c(0.000895, 0.003059), - qtl = c(5) + qtl = c(0.01) ) } diff --git a/man/Analyze_QTL.Rd b/man/Analyze_QTL.Rd index 04a01e4e0..4d6a29146 100644 --- a/man/Analyze_QTL.Rd +++ b/man/Analyze_QTL.Rd @@ -59,7 +59,7 @@ dfTransformed <- Transform_Rate(dfInput, ) dfAnalyzed <- Analyze_QTL(dfTransformed, strOutcome = "binary") -dfFlagged <- Flag(dfAnalyzed, strColumn = "LowCI", vThreshold = c(NA, 0.2)) +dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.2) @@ -71,6 +71,6 @@ dfTransformed <- Transform_Rate(dfInput, ) dfAnalyzed <- Analyze_QTL(dfTransformed, strOutcome = "rate") -dfFlagged <- Flag(dfAnalyzed, vThreshold = c(NA, 0.01)) +dfFlagged <- Flag_QTL(dfAnalyzed, vThreshold = 0.01) } From 1dfacc1e67e773ba37877e906989cbb840656897 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Tue, 15 Nov 2022 18:25:45 +0000 Subject: [PATCH 13/20] tweak logic for failed QTL --- R/Make_Snapshot.R | 48 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index 61d28e438..ce45de360 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -201,39 +201,35 @@ bQuiet = TRUE ) # results_analysis --------------------------------------------------------- - # Leaving this data munging for Matt/Spencer/Kai. Columns = workflowid, groupid, param, value. - # for now, we just want to add Param = "LowCI", "UpperCI", "Mean" for the 2 QTLs. So 6 rows for now. - # lSnapshot$results_summary$StudyID <- meta$status_study[1,'StudyID'] - # Also need to make sure we're capturing WorkflowID here ... hasQTL <- grep("qtl", names(lResults)) if (length(hasQTL) > 0) { - results_analysis <- lResults[hasQTL] %>% - purrr::imap_dfr( - ~ .x$lResults$lData$dfAnalyzed %>% - select(GroupID, - LowCI, - UpCI, - Score) %>% - mutate(workflowid = .y) - ) %>% - pivot_longer(-c("GroupID", "workflowid")) %>% - rename(param = "name", - studyid = "GroupID") - } else { - results_analysis <- tibble( - studyid = NA, - workflowid = NA, - param = NA, - value = NA - ) + results_analysis <- + purrr::imap_dfr(lResults[hasQTL], function(qtl, qtl_name) { + if (qtl$bStatus) { + qtl$lResults$lData$dfAnalyzed %>% + select(GroupID, + LowCI, + UpCI, + Score) %>% + mutate(workflowid = qtl_name) %>% + pivot_longer(-c("GroupID", "workflowid")) %>% + rename(param = "name", + studyid = "GroupID") + } else { + tibble( + studyid = unique(lMeta$config_workflow$studyid), + workflowid = qtl_name, + param = NA, + value = NA + ) + } + + }) } - - - # results_bounds ---------------------------------------------------------- results_bounds <- lResults %>% purrr::map(~ .x$lResults$lData$dfBounds) %>% From 41996832ef375db8b69a6d42a33bdbcd56078bf2 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Tue, 15 Nov 2022 18:41:31 +0000 Subject: [PATCH 14/20] update rbm_data_spec --- R/Make_Snapshot.R | 8 +- data-raw/rbm_data_spec.csv | 277 +++++++++++++++++++------------------ data/rbm_data_spec.rda | Bin 1540 -> 1562 bytes 3 files changed, 145 insertions(+), 140 deletions(-) diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index ce45de360..f9ea6d47a 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -209,10 +209,10 @@ bQuiet = TRUE purrr::imap_dfr(lResults[hasQTL], function(qtl, qtl_name) { if (qtl$bStatus) { qtl$lResults$lData$dfAnalyzed %>% - select(GroupID, - LowCI, - UpCI, - Score) %>% + select("GroupID", + "LowCI", + "UpCI", + "Score") %>% mutate(workflowid = qtl_name) %>% pivot_longer(-c("GroupID", "workflowid")) %>% rename(param = "name", diff --git a/data-raw/rbm_data_spec.csv b/data-raw/rbm_data_spec.csv index bc1ba86a4..867ba29b9 100644 --- a/data-raw/rbm_data_spec.csv +++ b/data-raw/rbm_data_spec.csv @@ -1,136 +1,141 @@ -System,Table,Column,Description -Gismo,status_study,studyid,Unique Study ID -Gismo,status_study,enrolled_sites,# of enrolled sites -Gismo,status_study,enrolled_participants,# of enrolled participants -Gismo,status_study,planned_sites,# of planned sites -Gismo,status_study,planned_participants,# of planned participants -Gismo,status_study,title,Protocol title -Gismo,status_study,nickname,Protocol nickname -Gismo,status_study,indication,Indication -Gismo,status_study,ta,Therapeutic Area -Gismo,status_study,phase,Phase -Gismo,status_study,status,Study Status -Gismo,status_study,fpfv,First-patient first visit date -Gismo,status_study,lplv,Last-patient last visit date -Gismo,status_study,lpfv,Last-patient first visit date -Gismo,status_study,rbm_flag,Risk-based monitoring flag -Gismo,status_study,gsm_analysis_date,Date that snapshot was created -Gismo,status_site,studyid,Unique Study ID -Gismo,status_site,siteid,Unique Site ID -Gismo,status_site,institution,Institution Name -Gismo,status_site,status,Site Status -Gismo,status_site,enrolled_participants,# of enrolled participants -Gismo,status_site,start_date,Site Activation Date -Gismo,status_site,city,City -Gismo,status_site,state,State -Gismo,status_site,country,Country -Gismo,status_site,invname,Investigator name -Gismo,status_site,gsm_analysis_date,Date that snapshot was created -Gismo,status_workflow,studyid,Unique Study ID -Gismo,status_workflow,workflowid,Unique Workflow ID -Gismo,status_workflow,gsm_version,GSM version of workflow -Gismo,status_workflow,active,Is workflow active? -Gismo,status_workflow,status,Did workflow run? -Gismo,status_workflow,notes,Status notes -Gismo,status_workflow,gsm_analysis_date,Date that snapshot was created -Gismo,status_param,studyid,Unique Study ID -Gismo,status_param,workflowid,Unique Workflow ID -Gismo,status_param,gsm_version,GSM version of workflow -Gismo,status_param,param,Parameter name -Gismo,status_param,index,Index value for parameter -Gismo,status_param,value,Value for parameter at index -Gismo,status_param,gsm_analysis_date,Date that snapshot was created -Gismo,status_schedule,studyid,Unique Study ID -Gismo,status_schedule,snapshot_date,Snapshot Date -Gismo,status_schedule,gsm_analysis_date,Date that snapshot was created -Gismo,results_summary,studyid,Unique Study ID -Gismo,results_summary,workflowid,Unique Workflow ID -Gismo,results_summary,groupid,Unique Group ID (e.g. SiteID for KRI workflows) -Gismo,results_summary,numerator,Metric numerator -Gismo,results_summary,denominator,Metric denominator -Gismo,results_summary,metric,Metric value -Gismo,results_summary,score,Statistical Score -Gismo,results_summary,flag,Flag -Gismo,results_summary,gsm_analysis_date,Date that snapshot was created -Gismo,results_bounds,studyid,Unique Study ID -Gismo,results_bounds,workflowid,Unique Workflow ID -Gismo,results_bounds,threshold,Threshold -Gismo,results_bounds,numerator,y value -Gismo,results_bounds,denominator,x value -Gismo,results_bounds,log_denominator,Log X value -Gismo,results_bounds,gsm_analysis_date,Date that snapshot was created -Gismo,meta_workflow,workflowid,Unique Workflow ID -Gismo,meta_workflow,gsm_version,GSM Version of workflow -Gismo,meta_workflow,group,"Group for workflow - Site, Country, Region or Study" -Gismo,meta_workflow,abbreviation,Workflow Abbreviation (max 3-letters) -Gismo,meta_workflow,metric,Metric Label -Gismo,meta_workflow,numerator,Numerator Label -Gismo,meta_workflow,denominator,Denominator Label -Gismo,meta_workflow,outcome,Metric Outcome Type (e.g. rate) -Gismo,meta_workflow,model,Statistical Model used to create score -Gismo,meta_workflow,score,Score Label -Gismo,meta_workflow,data_inputs,Data inputs for workflow -Gismo,meta_workflow,data_filters,Filters applied in workflow -Gismo,meta_workflow,gsm_analysis_date,Date that snapshot was created -Gismo,meta_param,workflowid,Unique Workflow ID -Gismo,meta_param,gsm_version,GSM version of workflow -Gismo,meta_param,param,Parameter name -Gismo,meta_param,index,Parameter index -Gismo,meta_param,default,Default value for parameter at index -Gismo,meta_param,configurable,Is parameter configurable? -Gismo,meta_param,gsm_analysis_date,Date that snapshot was created -GSM,meta_study,studyid,Unique Study ID -GSM,meta_study,enrolled_sites,# of enrolled sites -GSM,meta_study,enrolled_participants,# of enrolled participants -GSM,meta_study,planned_sites,# of planned sites -GSM,meta_study,planned_participants,# of planned participants -GSM,meta_study,title,Protocol title -GSM,meta_study,nickname,Protocol nickname -GSM,meta_study,indication,Indication -GSM,meta_study,ta,Therapeutic Area -GSM,meta_study,phase,Phase -GSM,meta_study,status,Study Status -GSM,meta_study,fpfv,First-patient first visit date -GSM,meta_study,lplv,Last-patient last visit date -GSM,meta_study,lpfv,Last-patient first visit date -GSM,meta_study,rbm_flag,Risk-based monitoring flag -GSM,meta_site,studyid,Unique Study ID -GSM,meta_site,siteid,Unique Site ID -GSM,meta_site,institution,Institution Name -GSM,meta_site,status,Site Status -GSM,meta_site,enrolled_participants,# of enrolled participants -GSM,meta_site,start_date,Site Activation Date -GSM,meta_site,city,City -GSM,meta_site,state,State -GSM,meta_site,country,Country -GSM,meta_site,invname,Investigator name -GSM,config_workflow,studyid,Unique Study ID -GSM,config_workflow,workflowid,Unique Workflow ID -GSM,config_workflow,gsm_version,GSM version of workflow -GSM,config_workflow,active,Is workflow active? -GSM,config_param,studyid,Unique Study ID -GSM,config_param,workflowid,Unique Workflow ID -GSM,config_param,gsm_version,GSM version of workflow -GSM,config_param,param,Parameter name -GSM,config_param,index,Index value for parameter -GSM,config_param,value,Value for parameter at index -GSM,config_schedule,studyid,Unique Study ID -GSM,config_schedule,snapshot_date,Snapshot Date -GSM,meta_workflow,workflowid,Unique Workflow ID -GSM,meta_workflow,abbreviation,Workflow Abbreviation (max 3-letters) -GSM,meta_workflow,gsm_version,GSM Version of workflow -GSM,meta_workflow,group,"Group for workflow - Site, Country, Region or Study" -GSM,meta_workflow,metric,Metric Label -GSM,meta_workflow,numerator,Numerator Label -GSM,meta_workflow,denominator,Denominator Label -GSM,meta_workflow,outcome,Metric Outcome Type (e.g. rate) -GSM,meta_workflow,model,Statistical Model used to create score -GSM,meta_workflow,score,Score Label -GSM,meta_workflow,data_inputs,Data inputs for workflow -GSM,meta_workflow,data_filters,Filters applied in workflow -GSM,meta_param,workflowid,Unique Workflow ID -GSM,meta_param,gsm_version,GSM version of workflow -GSM,meta_param,param,Parameter name -GSM,meta_param,index,Parameter index -GSM,meta_param,default,Default value for parameter at index -GSM,meta_param,configurable,Is parameter configurable? +System,Table,Column,Description +Gismo,status_study,studyid,Unique Study ID +Gismo,status_study,enrolled_sites,# of enrolled sites +Gismo,status_study,enrolled_participants,# of enrolled participants +Gismo,status_study,planned_sites,# of planned sites +Gismo,status_study,planned_participants,# of planned participants +Gismo,status_study,title,Protocol title +Gismo,status_study,nickname,Protocol nickname +Gismo,status_study,indication,Indication +Gismo,status_study,ta,Therapeutic Area +Gismo,status_study,phase,Phase +Gismo,status_study,status,Study Status +Gismo,status_study,fpfv,First-patient first visit date +Gismo,status_study,lplv,Last-patient last visit date +Gismo,status_study,lpfv,Last-patient first visit date +Gismo,status_study,rbm_flag,Risk-based monitoring flag +Gismo,status_study,gsm_analysis_date,Date that snapshot was created +Gismo,status_site,studyid,Unique Study ID +Gismo,status_site,siteid,Unique Site ID +Gismo,status_site,institution,Institution Name +Gismo,status_site,status,Site Status +Gismo,status_site,enrolled_participants,# of enrolled participants +Gismo,status_site,start_date,Site Activation Date +Gismo,status_site,city,City +Gismo,status_site,state,State +Gismo,status_site,country,Country +Gismo,status_site,invname,Investigator name +Gismo,status_site,gsm_analysis_date,Date that snapshot was created +Gismo,status_workflow,studyid,Unique Study ID +Gismo,status_workflow,workflowid,Unique Workflow ID +Gismo,status_workflow,gsm_version,GSM version of workflow +Gismo,status_workflow,active,Is workflow active? +Gismo,status_workflow,status,Did workflow run? +Gismo,status_workflow,notes,Status notes +Gismo,status_workflow,gsm_analysis_date,Date that snapshot was created +Gismo,status_param,studyid,Unique Study ID +Gismo,status_param,workflowid,Unique Workflow ID +Gismo,status_param,gsm_version,GSM version of workflow +Gismo,status_param,param,Parameter name +Gismo,status_param,index,Index value for parameter +Gismo,status_param,value,Value for parameter at index +Gismo,status_param,gsm_analysis_date,Date that snapshot was created +Gismo,status_schedule,studyid,Unique Study ID +Gismo,status_schedule,snapshot_date,Snapshot Date +Gismo,status_schedule,gsm_analysis_date,Date that snapshot was created +Gismo,results_summary,studyid,Unique Study ID +Gismo,results_summary,workflowid,Unique Workflow ID +Gismo,results_summary,groupid,Unique Group ID (e.g. SiteID for KRI workflows) +Gismo,results_summary,numerator,Metric numerator +Gismo,results_summary,denominator,Metric denominator +Gismo,results_summary,metric,Metric value +Gismo,results_summary,score,Statistical Score +Gismo,results_summary,flag,Flag +Gismo,results_summary,gsm_analysis_date,Date that snapshot was created +Gismo,results_analysis,studyid,Unique Study ID +Gismo,results_analysis,workflowid,Unique Workflow ID +Gismo,results_analysis,param,Parameter name +Gismo,results_analysis,value,Value for parameter +Gismo,results_analysis,gsm_analysis_date,Date that snapshot was created +Gismo,results_bounds,studyid,Unique Study ID +Gismo,results_bounds,workflowid,Unique Workflow ID +Gismo,results_bounds,threshold,Threshold +Gismo,results_bounds,numerator,y value +Gismo,results_bounds,denominator,x value +Gismo,results_bounds,log_denominator,Log X value +Gismo,results_bounds,gsm_analysis_date,Date that snapshot was created +Gismo,meta_workflow,workflowid,Unique Workflow ID +Gismo,meta_workflow,gsm_version,GSM Version of workflow +Gismo,meta_workflow,group,"Group for workflow - Site, Country, Region or Study" +Gismo,meta_workflow,abbreviation,Workflow Abbreviation (max 3-letters) +Gismo,meta_workflow,metric,Metric Label +Gismo,meta_workflow,numerator,Numerator Label +Gismo,meta_workflow,denominator,Denominator Label +Gismo,meta_workflow,outcome,Metric Outcome Type (e.g. rate) +Gismo,meta_workflow,model,Statistical Model used to create score +Gismo,meta_workflow,score,Score Label +Gismo,meta_workflow,data_inputs,Data inputs for workflow +Gismo,meta_workflow,data_filters,Filters applied in workflow +Gismo,meta_workflow,gsm_analysis_date,Date that snapshot was created +Gismo,meta_param,workflowid,Unique Workflow ID +Gismo,meta_param,gsm_version,GSM version of workflow +Gismo,meta_param,param,Parameter name +Gismo,meta_param,index,Parameter index +Gismo,meta_param,default,Default value for parameter at index +Gismo,meta_param,configurable,Is parameter configurable? +Gismo,meta_param,gsm_analysis_date,Date that snapshot was created +GSM,meta_study,studyid,Unique Study ID +GSM,meta_study,enrolled_sites,# of enrolled sites +GSM,meta_study,enrolled_participants,# of enrolled participants +GSM,meta_study,planned_sites,# of planned sites +GSM,meta_study,planned_participants,# of planned participants +GSM,meta_study,title,Protocol title +GSM,meta_study,nickname,Protocol nickname +GSM,meta_study,indication,Indication +GSM,meta_study,ta,Therapeutic Area +GSM,meta_study,phase,Phase +GSM,meta_study,status,Study Status +GSM,meta_study,fpfv,First-patient first visit date +GSM,meta_study,lplv,Last-patient last visit date +GSM,meta_study,lpfv,Last-patient first visit date +GSM,meta_study,rbm_flag,Risk-based monitoring flag +GSM,meta_site,studyid,Unique Study ID +GSM,meta_site,siteid,Unique Site ID +GSM,meta_site,institution,Institution Name +GSM,meta_site,status,Site Status +GSM,meta_site,enrolled_participants,# of enrolled participants +GSM,meta_site,start_date,Site Activation Date +GSM,meta_site,city,City +GSM,meta_site,state,State +GSM,meta_site,country,Country +GSM,meta_site,invname,Investigator name +GSM,config_workflow,studyid,Unique Study ID +GSM,config_workflow,workflowid,Unique Workflow ID +GSM,config_workflow,gsm_version,GSM version of workflow +GSM,config_workflow,active,Is workflow active? +GSM,config_param,studyid,Unique Study ID +GSM,config_param,workflowid,Unique Workflow ID +GSM,config_param,gsm_version,GSM version of workflow +GSM,config_param,param,Parameter name +GSM,config_param,index,Index value for parameter +GSM,config_param,value,Value for parameter at index +GSM,config_schedule,studyid,Unique Study ID +GSM,config_schedule,snapshot_date,Snapshot Date +GSM,meta_workflow,workflowid,Unique Workflow ID +GSM,meta_workflow,abbreviation,Workflow Abbreviation (max 3-letters) +GSM,meta_workflow,gsm_version,GSM Version of workflow +GSM,meta_workflow,group,"Group for workflow - Site, Country, Region or Study" +GSM,meta_workflow,metric,Metric Label +GSM,meta_workflow,numerator,Numerator Label +GSM,meta_workflow,denominator,Denominator Label +GSM,meta_workflow,outcome,Metric Outcome Type (e.g. rate) +GSM,meta_workflow,model,Statistical Model used to create score +GSM,meta_workflow,score,Score Label +GSM,meta_workflow,data_inputs,Data inputs for workflow +GSM,meta_workflow,data_filters,Filters applied in workflow +GSM,meta_param,workflowid,Unique Workflow ID +GSM,meta_param,gsm_version,GSM version of workflow +GSM,meta_param,param,Parameter name +GSM,meta_param,index,Parameter index +GSM,meta_param,default,Default value for parameter at index +GSM,meta_param,configurable,Is parameter configurable? diff --git a/data/rbm_data_spec.rda b/data/rbm_data_spec.rda index b6e590af00c014058a33a2b002dbd074ac9f3336..de3229b1583a7ae8162cabf911826af6b506a992 100644 GIT binary patch literal 1562 zcmV+#2IcueT4*^jL0KkKS^7z-X#fg{f589${{PQsm;kM>-@w1`|KLCb00H0!zI-SZ zQlfwqp+yuZj%kR<$)-&J$Y{u9$N&Ht8f0h~Lm=jujEtIO&pWM~*eAm*5ijGAQ742Fz`On?9Zk)}q0gfawDQ$~iEke*5D zF#z=q8a*NEHkyM*nl_=J^#+YJ3X&liBPK;W5X7gHdMA@8(?BwMJy0~z8a9llsFQvu zpsE!eYc}jEC~1ULg6}V%;batN56AnSv928ug8lN{u%L)oC=_(eHJrg<6np=(-r>`t z#%t$+{&hC{8M1rytvWP&y|&_GETbj!WcFhtbz@EM->UG#a<|pirr7tXGD%#FrZlyz zt+gi^Yr`xNUp74$H|3_0;A~#$q?40#1dQt`w>8+)1(#Y*W=>o=YHh44X>KhUR}_H+ z(+sZ{^$LP|i_#})AhQh;V&P2@AjYNE#B9P%7ht1m%#_xp^Sxt(Wo34zrp)wKPLryV zM03JODj_1GqSO*Zf68~!0o_oOR~v&j5|?znY+Wod+^Shnv^u^GYGS7bwhY(B^gf$3 zYg$R#sU18{hAG;zHzyz5mNhtMCQa`HBS&(}uO{|eKXN&djF>V`GlP?jfw2}w#njco zPALT$-cy3_bNM+F!#ed&ojLPahc!#5k@=OaS00<2?+*Fgv2W( zn3Z3dEVR5S6;~`4guq#a?Ic=Q_6tZMfcgQKOg%D_IOll~{E$XfX8<96ibaF&l4>2~ zyEZ8M2Pla{Sp7tt;!3h46 zZg602CrTXWD0Da#RpYnRk`zlnu7_%8t%SESO&&*Q=SOJ7(dTp{;*U$XD*Z=1vZSfb zQ8%8Cty?P6RGZaf!`9TEa#EA;b-M>aWcXX1i@F_6C%`C_J~u%%^C;967L~#{%;<@A znMc5c2_UvWa~l>+8xlh2N<4G8vuthf47pi8CdZyBY1U6uTOxY4B!}WNJf%c#NtUI9 zbqeYUd4M+1-6oucV79V0(ccmk&V;ypvmuf*h>yVd7$n(J8<}g8c6rTG)OqvlY$j-Z zYEwx&M-X7m_r2044WpcKWvIC+qRFCUPGc-tH^fJYDe7W}=EBU1u)^f!rz(T8YgYiRkExgye-KCz(Aj7gL#|TTN%s^1RHN z!;h4y6S7BSsVNmwiJ^>=aZq5`sWk3tAF0kxm##ldo``r3#A|ASP}Bz~Zy6ZJd{Y4H z3#~yUAST$1Er9H&%S9%*#|#TGQc|gQq+q|8!^v0^QZa~H6(^26c$Cvb#b;tn!@5bL zXA$wJ(7SpS5f(>d4Vua+PfLxQW?rM^Qa}<~Z#9^L@~$*&B1sO8*|bhgM&gu=9chXw zH>~zClSv||MlVv8Dk>nUB!9)+ MkxmpOK9Xu$K)=1v!T-@w1`|KLD?00H0!o_qi( z0YCr+08t#%5s{NjngNi}kjan$05UYl&@hHU%`q7nG|8YD4H*oX0009cOpOBwWE|5G zk&{fC0g%y<$&dg5GBn80For?RF&P;&$)Fhx84Q^K00SdTjROc|2&Gf>l>JSVo79*Z zObB2hfB*q70BIOcKvanIH2>udi|)elS{zB<%NRX~wQqh?{K^$9Bv+x)jUbmptys|jrENK;H!GH|wKzxYq{$_6vSUkH%H2|JEqG;uE6a~g z4jE^heyta}XC&p`!6Rj5H*8$H71m8$?M`fYsk*SKrMWbg-C-73a4F2rehGhK>}%Q911m)OSbD=W1!X|pwC?wwSSj);U62@z3IY62tv)6Ynf zPTG5HZP0keHLccvQGk$-Q;w!PXf^1n|~y+ zsmEeu;Pn|9yH;Iv;LA_wj&x#}GEJu!F4hK+v@~5#J*ly+4CM3 z%=sPk^G3PMab5a9vz0sZ>pNnL`sJ}T>@pw0rKU)|5%At597u8-rqpng6#J4y`NxnW zXG@aMoW1vv^0vEOtx)s4?mv8zPc!LzI$v4mQl4{}xo4a1$;$hrl3R1?S!GY9o9k(T zwvtoV$9w9<_VTzBiaU&7Vv*HeU+WKsO86FqJ`aI{q?U{ltKv&7FA7Cf%LSn@7GZly z7M4$0lp)UlL*)D_bhf;y<)2veQocxPl1h)gP_j?T8i$;hY-1AX4?=HPobdio{Ljst z;$~qEr&3axl_J!Y(5P-&9Er^R6sJ2};WZU1Q>k=`=QzH%edtt8bEZz=zifwGQ9Oz~ zKVi7-Ph~08`1VCUh2&qA%4s_4suJY}AWVu40_<7_lAxKCO<_{qEhx0$adc9wzXy96 zDwt(uVze$)zDuceWXB0tsZ_?-weNK$Rr~8LOqN+h!9i&!<1*H(=8J+~$t%SEaOy0Y*`?w54%6X!Q9PAg3@i|o83nwl6xe$S{}Q;$uc(-s9@?$VM)rf(8f)YMNo`hH7Zn8Q6r?nNt`NC zDioCxr9zj*Cd0bfh^~lt_BGBzW|nnYV5uonp{a@BOv|$}g6*i~M#Tzl1d8AlLa?j@ zIHNcfD8C`Jg9D1OG7RI&v@zkfL#)jrZ(aL0usMxy3D2%oM+E5>P3?t}%@8dLMiM28 qg+%N{Ulee4S^u{j9N?)HB*x1Fwp}5Cg=A}y@Gj(vaG@aB$m!Y*#@^om From bc1305ab954d6f7eadd77d1ecc576b65006a5206 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Tue, 15 Nov 2022 19:08:56 +0000 Subject: [PATCH 15/20] add failsafe for dfBounds --- R/Make_Snapshot.R | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index f9ea6d47a..aaec6bfcd 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -181,6 +181,7 @@ bQuiet = TRUE # meta_param -------------------------------------------------------------- meta_param <- gsm::meta_param + # results_summary --------------------------------------------------------- results_summary <- purrr::map(lResults, ~ .x[["lResults"]]) %>% purrr::discard(is.null) %>% @@ -205,6 +206,7 @@ bQuiet = TRUE hasQTL <- grep("qtl", names(lResults)) if (length(hasQTL) > 0) { + results_analysis <- purrr::imap_dfr(lResults[hasQTL], function(qtl, qtl_name) { if (qtl$bStatus) { @@ -217,13 +219,6 @@ bQuiet = TRUE pivot_longer(-c("GroupID", "workflowid")) %>% rename(param = "name", studyid = "GroupID") - } else { - tibble( - studyid = unique(lMeta$config_workflow$studyid), - workflowid = qtl_name, - param = NA, - value = NA - ) } }) @@ -233,17 +228,26 @@ bQuiet = TRUE # results_bounds ---------------------------------------------------------- results_bounds <- lResults %>% purrr::map(~ .x$lResults$lData$dfBounds) %>% - purrr::discard(is.null) %>% - purrr::imap_dfr(~ .x %>% mutate(workflowid = .y)) %>% - mutate(studyid = unique(lMeta$config_workflow$studyid)) %>% # not sure if this is a correct assumption - select( - "studyid", - "workflowid", - "threshold" = "Threshold", - "numerator" = "Numerator", - "denominator" = "Denominator", - "log_denominator" = "LogDenominator" - ) + purrr::discard(is.null) + + if (length(results_bounds) > 0) { + results_bounds <- results_bounds %>% + purrr::imap_dfr(~ .x %>% mutate(workflowid = .y)) %>% + mutate(studyid = unique(lMeta$config_workflow$studyid)) %>% # not sure if this is a correct assumption + select( + "studyid", + "workflowid", + "threshold" = "Threshold", + "numerator" = "Numerator", + "denominator" = "Denominator", + "log_denominator" = "LogDenominator" + ) + } else { + results_bounds <- results_bounds %>% + as_tibble() + } + + From 94ffae6b779805d3ff30a892503eb62674c32ad2 Mon Sep 17 00:00:00 2001 From: Matt Roumaya Date: Wed, 16 Nov 2022 15:04:04 +0000 Subject: [PATCH 16/20] styler + news updates --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/AE_Map_Raw.R | 1 - R/Analyze_NormalApprox_PredictBounds.R | 10 +++++----- R/Analyze_Poisson_PredictBounds.R | 8 ++++---- R/Flag_QTL.R | 4 +--- R/Make_Snapshot.R | 20 +++++++++++--------- tests/testthat/test_Flag_QTL.R | 4 ++-- 8 files changed, 28 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6ce5f467c..3c8fb862f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gsm Title: Gilead Statistical Monitoring -Version: 1.3.0 +Version: 1.3.1 Authors@R: c( person("George", "Wu", email="george.wu@gilead.com", role = c("aut", "cre")), person("Jeremy", "Wildfire", email="jwildfire@gmail.com", role = c("aut")), diff --git a/NEWS.md b/NEWS.md index c4acf72a3..08db68684 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# gsm v1.3.1 + +This minor release adds a data frame to the output/data model of `Make_Snapshot()` that includes parameters and values for QTL analyses. + # gsm v1.3.0 This release introduces new and refined statistical methods for qualified assessments. diff --git a/R/AE_Map_Raw.R b/R/AE_Map_Raw.R index ea99b3cc5..ff6e64e6a 100644 --- a/R/AE_Map_Raw.R +++ b/R/AE_Map_Raw.R @@ -48,7 +48,6 @@ AE_Map_Raw <- function( bReturnChecks = FALSE, bQuiet = TRUE ) { - stopifnot( "bReturnChecks must be logical" = is.logical(bReturnChecks), "bQuiet must be logical" = is.logical(bQuiet) diff --git a/R/Analyze_NormalApprox_PredictBounds.R b/R/Analyze_NormalApprox_PredictBounds.R index acd011fa8..b8ea3e7f8 100644 --- a/R/Analyze_NormalApprox_PredictBounds.R +++ b/R/Analyze_NormalApprox_PredictBounds.R @@ -58,11 +58,11 @@ #' @export Analyze_NormalApprox_PredictBounds <- function( - dfTransformed, - vThreshold = c(-3, -2, 2, 3), - nStep = 100, - strType = "binary", - bQuiet = TRUE + dfTransformed, + vThreshold = c(-3, -2, 2, 3), + nStep = 100, + strType = "binary", + bQuiet = TRUE ) { if (is.null(vThreshold)) { vThreshold <- c(-3, -2, 2, 3) diff --git a/R/Analyze_Poisson_PredictBounds.R b/R/Analyze_Poisson_PredictBounds.R index 724de0f85..7078f3afc 100644 --- a/R/Analyze_Poisson_PredictBounds.R +++ b/R/Analyze_Poisson_PredictBounds.R @@ -47,10 +47,10 @@ #' @export Analyze_Poisson_PredictBounds <- function( - dfTransformed, - vThreshold = c(-5, 5), - nStep = .05, - bQuiet = TRUE + dfTransformed, + vThreshold = c(-5, 5), + nStep = .05, + bQuiet = TRUE ) { if (is.null(vThreshold)) { vThreshold <- c(-5, 5) diff --git a/R/Flag_QTL.R b/R/Flag_QTL.R index 3f28b4014..44b0fbaec 100644 --- a/R/Flag_QTL.R +++ b/R/Flag_QTL.R @@ -32,14 +32,12 @@ Flag_QTL <- function( dfAnalyzed, vThreshold = NULL ) { - stopifnot( "dfAnalyzed is not a data frame" = is.data.frame(dfAnalyzed), "Required columns not found" = all(c("Estimate", "LowCI") %in% names(dfAnalyzed)), "vThreshold is not numeric" = is.numeric(vThreshold), "vThreshold must be length of 1" = length(vThreshold) == 1, "vThreshold cannot be NULL" = !is.null(vThreshold) - ) # Flag values outside the specified threshold. @@ -53,7 +51,7 @@ Flag_QTL <- function( ) dfFlagged <- dfFlagged %>% - arrange(match(.data$Flag, c( 2, 1, 0))) + arrange(match(.data$Flag, c(2, 1, 0))) return(dfFlagged) } diff --git a/R/Make_Snapshot.R b/R/Make_Snapshot.R index aaec6bfcd..8fed31cbb 100644 --- a/R/Make_Snapshot.R +++ b/R/Make_Snapshot.R @@ -206,21 +206,23 @@ bQuiet = TRUE hasQTL <- grep("qtl", names(lResults)) if (length(hasQTL) > 0) { - results_analysis <- purrr::imap_dfr(lResults[hasQTL], function(qtl, qtl_name) { if (qtl$bStatus) { qtl$lResults$lData$dfAnalyzed %>% - select("GroupID", - "LowCI", - "UpCI", - "Score") %>% + select( + "GroupID", + "LowCI", + "UpCI", + "Score" + ) %>% mutate(workflowid = qtl_name) %>% pivot_longer(-c("GroupID", "workflowid")) %>% - rename(param = "name", - studyid = "GroupID") + rename( + param = "name", + studyid = "GroupID" + ) } - }) } @@ -268,7 +270,7 @@ bQuiet = TRUE purrr::map(~ .x %>% mutate(gsm_analysis_date = gsm_analysis_date)) -# save lSnapshot ---------------------------------------------------------- + # save lSnapshot ---------------------------------------------------------- if (!is.null(cPath)) { # write each snapshot item to location diff --git a/tests/testthat/test_Flag_QTL.R b/tests/testthat/test_Flag_QTL.R index 3fda96435..31a18c4f5 100644 --- a/tests/testthat/test_Flag_QTL.R +++ b/tests/testthat/test_Flag_QTL.R @@ -1,6 +1,6 @@ dfAnalyzed <- tibble::tribble( - ~GroupID, ~Numerator, ~Denominator, ~Metric, ~Method, ~ConfLevel, ~Estimate, ~LowCI, ~UpCI, ~Score, - "AA-AA-000-0000", 122, 1301, 0.0937, "Exact binomial test", 0.95, 0.0937, 0.0784, 0.1109, 0.0784 + ~GroupID, ~Numerator, ~Denominator, ~Metric, ~Method, ~ConfLevel, ~Estimate, ~LowCI, ~UpCI, ~Score, + "AA-AA-000-0000", 122, 1301, 0.0937, "Exact binomial test", 0.95, 0.0937, 0.0784, 0.1109, 0.0784 ) dfAnalyzed %>% From 2dc3b402f649390a51b1164f7475a3fb20f2aeac Mon Sep 17 00:00:00 2001 From: Spencer Childress Date: Wed, 16 Nov 2022 11:12:21 -0500 Subject: [PATCH 17/20] fix #870; fix #881 --- R/Analyze_NormalApprox_PredictBounds.R | 21 ++++++++++-- R/Analyze_Poisson_PredictBounds.R | 22 +++++++++++-- R/Visualize_Scatter.R | 30 +++++++++++------ inst/report/studySummary.rmd | 45 ++++++++++++++++---------- tests/testthat/_snaps/AE_Assess.md | 1 + tests/testthat/_snaps/Disp_Assess.md | 1 + tests/testthat/_snaps/LB_Assess.md | 1 + tests/testthat/_snaps/Make_Snapshot.md | 7 ++++ tests/testthat/_snaps/PD_Assess.md | 1 + tests/testthat/_snaps/Study_Assess.md | 2 ++ 10 files changed, 100 insertions(+), 31 deletions(-) diff --git a/R/Analyze_NormalApprox_PredictBounds.R b/R/Analyze_NormalApprox_PredictBounds.R index acd011fa8..e870358c0 100644 --- a/R/Analyze_NormalApprox_PredictBounds.R +++ b/R/Analyze_NormalApprox_PredictBounds.R @@ -52,6 +52,7 @@ #' dfAnalyzed <- Analyze_NormalApprox(dfTransformed, strType = "rate") #' dfBounds <- Analyze_NormalApprox_PredictBounds(dfTransformed, c(-3, -2, 2, 3), strType = "rate") #' +#' @importFrom cli cli_alert #' @import dplyr #' @importFrom tidyr expand_grid #' @@ -60,13 +61,29 @@ Analyze_NormalApprox_PredictBounds <- function( dfTransformed, vThreshold = c(-3, -2, 2, 3), - nStep = 100, strType = "binary", + nStep = NULL, bQuiet = TRUE ) { if (is.null(vThreshold)) { vThreshold <- c(-3, -2, 2, 3) - cli::cli_alert("vThreshold was not provided. Setting default threshold to c(-3, -2, 2, 3)") + if (bQuiet == FALSE) + cli::cli_alert("vThreshold was not provided. Setting default threshold to {vThreshold}") + } + + # Set [ nStep ] to the range of the denominator divided by 250. + if (is.null(nStep)) { + nMinDenominator <- min(dfTransformed$Denominator) + nMaxDenominator <- max(dfTransformed$Denominator) + nRange <- nMaxDenominator - nMinDenominator + + if (!is.null(nRange) & !is.na(nRange) & nRange != 0) + nStep <- nRange/250 + else + nStep <- 1 + + if (bQuiet == FALSE) + cli::cli_alert("nStep was not provided. Setting default step to {nStep}") } # add a 0 threhsold to calcultate estimate without an offset diff --git a/R/Analyze_Poisson_PredictBounds.R b/R/Analyze_Poisson_PredictBounds.R index 724de0f85..5ec9db79e 100644 --- a/R/Analyze_Poisson_PredictBounds.R +++ b/R/Analyze_Poisson_PredictBounds.R @@ -39,6 +39,7 @@ #' #' dfBounds <- Analyze_Poisson_PredictBounds(dfTransformed, c(-5, 5)) #' +#' @importFrom cli cli_alert #' @importFrom lamW lambertWm1 lambertW0 #' @importFrom stats glm offset poisson qchisq #' @importFrom tibble tibble @@ -49,12 +50,14 @@ Analyze_Poisson_PredictBounds <- function( dfTransformed, vThreshold = c(-5, 5), - nStep = .05, + nStep = NULL, bQuiet = TRUE ) { if (is.null(vThreshold)) { vThreshold <- c(-5, 5) - cli::cli_alert("vThreshold was not provided. Setting default threshold to c(-5, 5)") + + if (bQuiet == FALSE) + cli::cli_alert("vThreshold was not provided. Setting default threshold to c(-5, 5)") } # add a 0 threhsold to calcultate estimate without an offset @@ -65,6 +68,21 @@ Analyze_Poisson_PredictBounds <- function( dfTransformed$Denominator ) + # Set [ nStep ] to the range of the log denominator divided by 250. + if (is.null(nStep)) { + nMinLogDenominator <- min(dfTransformed$LogDenominator) + nMaxLogDenominator <- max(dfTransformed$LogDenominator) + nRange <- nMaxLogDenominator - nMinLogDenominator + + if (!is.null(nRange) & !is.na(nRange) & nRange != 0) + nStep <- nRange/250 + else + nStep <- .05 + + if (bQuiet == FALSE) + cli::cli_alert("nStep was not provided. Setting default step to {nStep}") + } + # Fit GLM of number of events at each site predicted by total exposure. cModel <- glm( Numerator ~ stats::offset(LogDenominator), diff --git a/R/Visualize_Scatter.R b/R/Visualize_Scatter.R index cd8bb28a7..d078ab36e 100644 --- a/R/Visualize_Scatter.R +++ b/R/Visualize_Scatter.R @@ -33,12 +33,13 @@ Visualize_Scatter <- function( "GroupID: ", strGroupLabel ) + colors <- c("#999999", "#FADB14", "#FF4D4F") # Account for incomplete set of flags dfFlagged$FlagAbs <- abs(dfFlagged$Flag) maxFlag <- max(dfFlagged$FlagAbs) flagBreaks <- as.character(seq(0, maxFlag)) - flagValues <- c("#999999", "#FADB14", "#FF4D4F")[1:length(flagBreaks)] + flagValues <- colors[1:length(flagBreaks)] # Define tooltip for use in plotly. dfFlaggedWithTooltip <- dfFlagged %>% @@ -78,18 +79,27 @@ Visualize_Scatter <- function( xlab(glue::glue("{groupLabel} Total (Denominator) ({strUnit} - log scale)")) + ylab(glue::glue("{groupLabel} Total (Numerator)")) + # Add bound lines one at a time. if (!is.null(dfBounds)) { - for (current_threshold in unique(dfBounds$Threshold)) { - color <- case_when( - current_threshold == 0 ~ "gray", - current_threshold == min(unique(dfBounds$Threshold)) ~ "#FF4D4F", - current_threshold == max(unique(dfBounds$Threshold)) ~ "#FF4D4F", - TRUE ~ "#FADB14" - ) + dfBounds$ThresholdAbs <- abs(dfBounds$Threshold) + thresholds <- unique(dfBounds$Threshold) %>% sort() + thresholdAbs <- unique(dfBounds$ThresholdAbs) %>% sort() + + for (i in seq_along(thresholds)) { + threshold <- thresholds[i] + thresholdAb <- thresholdAbs[thresholdAbs == abs(threshold)] + color <- colors[match(thresholdAb, thresholdAbs)] p <- p + geom_line( - data = dfBounds %>% filter(.data$Threshold == current_threshold, !is.nan(.data$Numerator)), - aes(x = .data$LogDenominator, y = .data$Numerator), + data = dfBounds %>% + filter( + .data$Threshold == threshold, + !is.nan(.data$Numerator) + ), + aes( + x = .data$LogDenominator, + y = .data$Numerator + ), color = color, inherit.aes = FALSE ) diff --git a/inst/report/studySummary.rmd b/inst/report/studySummary.rmd index 83c8d0f7b..f9eb04206 100644 --- a/inst/report/studySummary.rmd +++ b/inst/report/studySummary.rmd @@ -108,10 +108,15 @@ function showDetails(elem){ for (i in seq_along(results)) { result <- results[[i]] - title <- gsm::meta_workflow %>% - dplyr::filter(workflowid == names(params$assessments)[i]) %>% + workflow <- gsm::meta_workflow %>% + dplyr::filter(workflowid == names(params$assessments)[i]) + title <- workflow %>% dplyr::pull(metric) + isQTL <- grepl('^qtl', workflow$workflowid) + if (isQTL) + title <- paste0(title, ' (QTL)') + # title cat(paste0('\n\n## ', title, '\n\n')) @@ -136,35 +141,41 @@ for (i in seq_along(results)) { # table - cat("

Flagged Sites

") + if (!isQTL) + cat("

Flagged Sites

") - - flagged <- result$lData$dfSummary %>% - dplyr::filter(Flag != 0) + if (isQTL) + flagged <- result$lData$dfSummary + else + flagged <- result$lData$dfSummary %>% + dplyr::filter( + Flag != 0 + ) - if (nrow(flagged) > 0) { + if (nrow(flagged) > 0 || isQTL) { flagged %>% kableExtra::kbl(escape = FALSE) %>% kableExtra::kable_styling() %>% cat() } - cat( - paste0( - "

", - length(unique(flagged$GroupID)), - " of ", - length(unique(result$lData$dfSummary$GroupID)), - " sites flagged for this assessment.", - "

" + if (!isQTL) + cat( + paste0( + "

", + length(unique(flagged$GroupID)), + " of ", + length(unique(result$lData$dfSummary$GroupID)), + " sites flagged for this assessment.", + "

" + ) ) - ) details <- result$lData$dfFlagged %>% dplyr::filter(Flag != 0) %>% dplyr::arrange(., match(GroupID, flagged$GroupID)) - if (length(unique(flagged$GroupID)) > 0) { + if (length(unique(flagged$GroupID)) > 0 & !isQTL) { cat("
") cat("