Skip to content

Commit

Permalink
Add modulesToExecute in execution settings. (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena authored Sep 23, 2024
1 parent 4a3505a commit 45223f6
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 137 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Remotes:
ohdsi/SelfControlledCaseSeries
VignetteBuilder: knitr
NeedsCompilation: no
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
Config/testthat/edition: 3
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
4 changes: 2 additions & 2 deletions R/Module-CohortIncidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ CohortIncidenceModule <- R6::R6Class(
return(data)
},
.getResultsDataModelSpecification = function() {
rdms <- readr::read_csv(
rdms <- CohortGenerator::readCsv(
file = private$.getResultsDataModelSpecificationFileLocation(),
show_col_types = FALSE
warnOnCaseMismatch = FALSE
)
rdms$tableName <-paste0(self$tablePrefix, rdms$tableName)
return(rdms)
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 @@ -115,8 +115,7 @@ cdModuleSpecifications <- cdModuleSettingsCreator$createModuleSpecifications(
runBreakdownIndexEvents = TRUE,
runIncidenceRate = TRUE,
runCohortRelationship = TRUE,
runTemporalCohortCharacterization = TRUE,
incremental = FALSE
runTemporalCohortCharacterization = TRUE
)

# Cohort Generator -----------------
Expand Down Expand Up @@ -447,9 +446,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 45223f6

Please sign in to comment.