Skip to content

Commit

Permalink
Merge branch 'v1.0-main' into results-data-model
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Sep 30, 2024
2 parents 44c51e3 + 45223f6 commit 79c4e58
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 134 deletions.
55 changes: 55 additions & 0 deletions R/Execution.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,61 @@ execute <- function(analysisSpecifications,
}
}

# Determine if the user has opted to subset to specific modules
# in the analysis specification. If so, validate that the
# modulesToExecute are present in the analysis specification
# before attempting to subset the analyses to run.
if (length(executionSettings$modulesToExecute) > 0) {
# Get the modules in the analysis specification with their
# index in the array
modulesWithIndex <- lapply(
X = seq_along(analysisSpecifications$moduleSpecifications),
FUN = function(i) {
list(
idx = i,
module = analysisSpecifications$moduleSpecifications[[i]]$module
)
}
)
modulesInAnalysisSpecification <- sapply(
X = modulesWithIndex,
FUN = function(x) {
x$module
}
)

modulesToExecuteString <- paste(executionSettings$modulesToExecute, collapse = ", ")
modulesInAnalysisSpecificationString <- paste(modulesInAnalysisSpecification, collapse = ", ")

# Stop if we cannot find all of the requested modules
# to execute in the overall analysis specification
if(!all(tolower(executionSettings$modulesToExecute) %in% tolower(modulesInAnalysisSpecification))) {
errorMsg <- paste0(
"The executionSettings specified to run only the modules: ",
modulesToExecuteString,
".\n However the analysis specification includes the following modules: ",
modulesInAnalysisSpecificationString
)
stop(errorMsg)
}

# Subset the analysis specifications to those modules
# specified by the user
cli::cli_alert_info(paste0("Runnning a subset of modules: ", modulesToExecuteString))
moduleSubset <- unlist(
lapply(
X = modulesWithIndex,
FUN = function(x) {
if (tolower(x$module) %in% tolower(executionSettings$modulesToExecute)) {
return(x$idx)
}
}
)
)
analysisSpecifications$moduleSpecifications <- analysisSpecifications$moduleSpecifications[moduleSubset]
}


# Set up logging
if (!dir.exists(dirname(executionSettings$logFileName))) {
dir.create(dirname(executionSettings$logFileName), recursive = T)
Expand Down
13 changes: 11 additions & 2 deletions R/Settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ createEmptyAnalysisSpecificiations <- function() {
#' and attempt to pick up where they left off when this value is set to TRUE.
#' @param maxCores The maximum number of processing cores to use for execution. The default is to
#' use all available cores on the machine.
#' @param modulesToExecute (Optional) A vector with the list of modules to execute. When an empty vector/NULL is supplied (default),
#' all modules in the analysis specification are executed.
#'
#' @return
#' An object of type `ExecutionSettings`.
Expand All @@ -272,7 +274,8 @@ createCdmExecutionSettings <- function(workDatabaseSchema,
logFileName = file.path(resultsFolder, "strategus-log.txt"),
minCellCount = 5,
incremental = TRUE,
maxCores = parallel::detectCores()) {
maxCores = parallel::detectCores(),
modulesToExecute = c()) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertCharacter(workDatabaseSchema, len = 1, add = errorMessages)
checkmate::assertCharacter(cdmDatabaseSchema, len = 1, add = errorMessages)
Expand All @@ -283,6 +286,7 @@ createCdmExecutionSettings <- function(workDatabaseSchema,
checkmate::assertInt(minCellCount, add = errorMessages)
checkmate::assertLogical(incremental, add = errorMessages)
checkmate::assertInt(maxCores, add = errorMessages)
checkmate::assertVector(modulesToExecute, null.ok = TRUE, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

# Normalize paths to convert relative paths to absolute paths
Expand All @@ -308,6 +312,9 @@ createCdmExecutionSettings <- function(workDatabaseSchema,
#' in results.
#' @param maxCores The maximum number of processing cores to use for execution. The default is to
#' use all available cores on the machine.
#' @param modulesToExecute (Optional) A vector with the list of modules to execute. When an empty vector/NULL is supplied (default),
#' all modules in the analysis specification are executed.
#'
#' @return
#' An object of type `ExecutionSettings`.
#'
Expand All @@ -317,14 +324,16 @@ createResultsExecutionSettings <- function(resultsDatabaseSchema,
resultsFolder,
logFileName = file.path(resultsFolder, "strategus-log.txt"),
minCellCount = 5,
maxCores = parallel::detectCores()) {
maxCores = parallel::detectCores(),
modulesToExecute = c()) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertCharacter(resultsDatabaseSchema, len = 1, add = errorMessages)
checkmate::assertCharacter(workFolder, len = 1, add = errorMessages)
checkmate::assertCharacter(resultsFolder, len = 1, add = errorMessages)
checkmate::assertCharacter(logFileName, len = 1, add = errorMessages)
checkmate::assertInt(minCellCount, add = errorMessages)
checkmate::assertInt(maxCores, add = errorMessages)
checkmate::assertVector(modulesToExecute, null.ok = TRUE, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

# Normalize paths to convert relative paths to absolute paths
Expand Down
6 changes: 2 additions & 4 deletions extras/PackageMaintenance.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ cdModuleSpecifications <- cdModuleSettingsCreator$createModuleSpecifications(
runBreakdownIndexEvents = TRUE,
runIncidenceRate = TRUE,
runCohortRelationship = TRUE,
runTemporalCohortCharacterization = TRUE,
incremental = FALSE
runTemporalCohortCharacterization = TRUE
)

# Cohort Generator -----------------
Expand Down Expand Up @@ -448,9 +447,8 @@ cdmModulesAnalysisSpecifications <- createEmptyAnalysisSpecificiations() |>
addCharacterizationModuleSpecifications(cModuleSpecifications) |>
addCohortDiagnosticsModuleSpecifications(cdModuleSpecifications) |>
addCohortGeneratorModuleSpecifications(cgModuleSpecifications) |>
#addCohortIncidenceModuleSpecifications(ciModuleSpecifications) |>
addCohortIncidenceModuleSpecifications(ciModuleSpecifications) |>
addCohortMethodeModuleSpecifications(cmModuleSpecifications) |>
#addEvidenceSynthesisModuleSpecifications(evidenceSynthesisAnalysisSpecifications) |>
addSelfControlledCaseSeriesModuleSpecifications(sccsModuleSpecifications) |>
addPatientLevelPredictionModuleSpecifications(plpModuleSpecifications)

Expand Down
Loading

0 comments on commit 79c4e58

Please sign in to comment.