diff --git a/R/error-checks.R b/R/error-checks.R index 8ceb5338..a5dc67bc 100644 --- a/R/error-checks.R +++ b/R/error-checks.R @@ -264,35 +264,6 @@ validateHasReferencePopulation <- function(workflowType, simulationSets) { stop(messages$warningNoReferencePopulation(workflowType)) } -validateSameOutputsBetweenSets <- function(simulationSets) { - pkParametersTableRef <- NULL - for (set in simulationSets) { - pkParametersTable <- getPKParametersInSimulationSet(set) - # In case output or pkParameters are in different orders - pkParametersTable <- pkParametersTable[order(pkParametersTable$path, pkParametersTable$group), c("path", "group")] - - if (is.null(pkParametersTableRef)) { - pkParametersTableRef <- pkParametersTable - next - } - if (all(pkParametersTable$path == pkParametersTableRef$path)) { - pkParametersTableTest <- NULL - for (pkParameterIndex in seq_along(pkParametersTable$group)) { - pkParametersTableTest[pkParameterIndex] <- isIncluded(pkParametersTable$group[pkParameterIndex], pkParametersTableRef$group[pkParameterIndex]) - } - if (all(pkParametersTableTest)) { - pkParametersTableRef <- pkParametersTable - next - } - } - stop(messages$errorNotSameOutputsBetweenSets(sapply( - simulationSets, function(set) { - set$simulationSetName - } - ))) - } -} - #' @title validateNoDuplicate #' @description #' Leverage `ospsuite.utils::validateHasOnlyDistinctValues()` to diff --git a/R/messages.R b/R/messages.R index 750434d2..6b019047 100644 --- a/R/messages.R +++ b/R/messages.R @@ -112,9 +112,6 @@ messages <- list( errorUnitNotFromDimension = function(unit, dimension) { paste0(callingFunction(), "Unit '", paste0(unit, collapse = "', '"), "' is not included in available units for dimension: '", paste0(dimension, collapse = "', '"), "'.") }, - errorNotSameOutputsBetweenSets = function(setNames) { - paste0(callingFunction(), "Simulation sets '", paste0(setNames, collapse = "', '"), "' require same outputs and PK parameters. Verify the outputs and PK parameters of simulation sets using the function: 'getPKParametersInSimulationSet'.") - }, errorHasNoUniqueValues = function(values, variableName = NULL, na.rm = TRUE) { if (na.rm) { values <- values[!is.na(values)] @@ -265,6 +262,33 @@ messages <- list( paste0("'", highlight(ids), "'", collapse = ", ") ) }, + warningPKAnalysesMissingIds = function(ids, setName){ + paste0( + "Missing ", highlight("IndividualIds"), " in PKAnalysis file for simulation set '", + highlight(setName), "': ", + paste0("'", highlight(ids), "'", collapse = ", ") + ) + }, + warningMissingFromReferenceSet = function(path, simulationSetName, pkParameters = NULL){ + if(is.null(pkParameters)){ + return( + paste0( + "Output path '", highlight(path), + "' was NOT defined for reference simulation set '", highlight(simulationSetName), + "'. Ouptut path and its PK Parameters were added to the list of figures to export." + ) + ) + } + return( + paste0( + "The following PK Parameters '", + paste(highlight(pkParameters), collapse = "', '"), + "' were NOT defined for the Ouptut path '", highlight(path), + "' in the reference simulation set '", highlight(simulationSetName), + "'. The PK Parameters were added to the list of figures to export." + ) + ) + }, #----- Info messages ---- runStarting = function(runName, subRun = NULL) { diff --git a/R/utilities-pop-pk-parameters.R b/R/utilities-pop-pk-parameters.R index 46b0feed..6d3b1f8d 100644 --- a/R/utilities-pop-pk-parameters.R +++ b/R/utilities-pop-pk-parameters.R @@ -22,14 +22,9 @@ plotPopulationPKParameters <- function(structureSets, validateIsOfType(c(structureSets), "SimulationStructure") validateIsString(c(xParameters), nullAllowed = TRUE) validateIsOfType(c(yParameters), "Output", nullAllowed = TRUE) - validateSameOutputsBetweenSets( - c(lapply(structureSets, function(set) { - set$simulationSet - })) - ) - - # Use first structure set as reference - yParameters <- yParameters %||% structureSets[[1]]$simulationSet$outputs + + # Use union of outputs from all the structure sets + yParameters <- yParameters %||% getOutputsForPKPlot(structureSets) # Get first simulation, in case mol weight is needed simulation <- loadSimulationWithUpdatedPaths(structureSets[[1]]$simulationSet, loadFromCache = TRUE) simulationSetDescriptor <- structureSets[[1]]$simulationSetDescriptor @@ -164,8 +159,16 @@ plotPopulationPKParameters <- function(structureSets, } # Report tables summarizing the distributions + # Caution: since simulationSetName is a factor, + # Unused levels need to be removed first to prevent errors in tlf::getPKParameterMeasure + allSetNames <-levels(pkParameterData$simulationSetName) + usedSetNames <- unique(as.character(pkParameterData$simulationSetName)) pkParameterTable <- getPKParameterMeasure( - data = pkParameterData, + data = pkParameterData %>% + mutate(simulationSetName = factor( + simulationSetName, + levels = intersect(allSetNames, usedSetNames) + )), dataMapping = pkParametersMapping ) # A different table needs to be created here @@ -210,7 +213,12 @@ plotPopulationPKParameters <- function(structureSets, "median" = pkParameterMetaData$Value ) # Include reference population if defined - if (!isEmpty(referenceSimulationSetName)) { + includeReferenceInRangePlot <- all( + !isEmpty(referenceSimulationSetName), + isIncluded(referenceSimulationSetName, unique(pkParameterData$simulationSetName)), + length(unique(pkParameterData$simulationSetName)) > 1 + ) + if (includeReferenceInRangePlot) { # Get the table for reference population referenceData <- data.frame( x = c(-Inf, Inf), @@ -296,6 +304,16 @@ plotPopulationPKParameters <- function(structureSets, # Regular range plots not associated to workflow type for (simulationSetName in simulationSetNames) { vpcData <- pkParameterData[pkParameterData$simulationSetName %in% simulationSetName, ] + if(nrow(vpcData) == 0){ + logDebug(paste( + "No data found for simulation set", + simulationSetName, + "for parameter", + pkParameter$pkParameter, + "of output", output$displayName + )) + next + } vpcData <- getDemographyAggregatedData( data = vpcData, xParameterName = demographyParameter, @@ -359,7 +377,12 @@ plotPopulationPKParameters <- function(structureSets, #---- Ratio comparisons ----- # Checks ratios of statistics and parameters # Table is output for every workflow except parallel no reference - if (isEmpty(referenceSimulationSetName)) { + noRatio <- any( + isEmpty(referenceSimulationSetName), + !isIncluded(referenceSimulationSetName, unique(pkParameterData$simulationSetName)), + isOfLength(unique(pkParameterData$simulationSetName), 1) + ) + if (noRatio) { next } # Output table of relative change in the respective statistics @@ -778,3 +801,73 @@ getPopulationPKAnalysesFromOutput <- function(data, metaData, output, pkParamete metaData = pkAnalysesFromOutputMetaData )) } + +#' @title getOutputsForPKPlot +#' @description +#' Get the list of outputs and their PK parameters for population PK parameter plot +#' @param structureSets List of `SimulationStructure` objects +#' @return list of `Output` objects +#' @keywords internal +#' @import dplyr +getOutputsForPKPlot <- function(structureSets){ + # Use the first simulation set as reference for PK parameters to plot + # Clone R6 objects to prevent potential issues in other workflow steps + outputsToPlot <- lapply( + structureSets[[1]]$simulationSet$outputs, + function(output){ + output$clone() + }) + for (structureSet in structureSets) { + outputsToAdd <- structureSet$simulationSet$outputs + for(output in outputsToAdd){ + # Check if output path is included in the initial outputs to plot + outputIndex <- head(which(sapply( + outputsToPlot, + function(outputToPlot) { + isIncluded(outputToPlot$path, output$path) + } + )), 1) + if(isEmpty(outputIndex)){ + warning( + messages$warningMissingFromReferenceSet( + path = output$path, + simulationSetName = structureSets[[1]]$simulationSet$simulationSetName + ), + call. = FALSE + ) + outputsToPlot <- c(outputsToPlot, output$clone()) + next + } + # If output path is included, check if PK parameters are the same + pkParametersToPlot <- sapply( + outputsToPlot[[outputIndex]]$pkParameters, + function(pkParameter){ + pkParameter$pkParameter + } + ) + pkParametersToAdd <- sapply( + output$pkParameters, + function(pkParameter){ + pkParameter$pkParameter + } + ) + if(isIncluded(pkParametersToAdd, pkParametersToPlot)){ + next + } + indicesToAdd <- which(!(pkParametersToAdd %in% pkParametersToPlot)) + warning( + messages$warningMissingFromReferenceSet( + path = output$path, + simulationSetName = structureSets[[1]]$simulationSet$simulationSetName, + pkParameters = pkParametersToAdd[indicesToAdd] + ), + call. = FALSE + ) + outputsToPlot[[outputIndex]]$pkParameters <- c( + outputsToPlot[[outputIndex]]$pkParameters, + output$pkParameters[indicesToAdd] + ) + } + } + return(outputsToPlot) +} \ No newline at end of file diff --git a/man/CalculatePKParametersTask.Rd b/man/CalculatePKParametersTask.Rd index 9b5a06a2..4e9d409a 100644 --- a/man/CalculatePKParametersTask.Rd +++ b/man/CalculatePKParametersTask.Rd @@ -8,7 +8,7 @@ R6 class for defining how pk parameters are calculated and save } \keyword{internal} \section{Super classes}{ -\code{ospsuite.reportingengine::Task} -> \code{ospsuite.reportingengine::SimulationTask} -> \code{CalculatePKParametersTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{\link[ospsuite.reportingengine:SimulationTask]{ospsuite.reportingengine::SimulationTask}} -> \code{CalculatePKParametersTask} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/GofPlotTask.Rd b/man/GofPlotTask.Rd index 05956913..be247a99 100644 --- a/man/GofPlotTask.Rd +++ b/man/GofPlotTask.Rd @@ -32,7 +32,7 @@ Other workflow tasks: } \concept{workflow tasks} \section{Super classes}{ -\code{ospsuite.reportingengine::Task} -> \code{ospsuite.reportingengine::PlotTask} -> \code{GofPlotTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{\link[ospsuite.reportingengine:PlotTask]{ospsuite.reportingengine::PlotTask}} -> \code{GofPlotTask} } \section{Methods}{ \subsection{Public methods}{ diff --git a/man/GofTaskSettings.Rd b/man/GofTaskSettings.Rd index a0388ce7..b372f00d 100644 --- a/man/GofTaskSettings.Rd +++ b/man/GofTaskSettings.Rd @@ -39,7 +39,7 @@ workflow$plotTimeProfilesAndResiduals$settings$getStatistics() } \keyword{internal} \section{Super class}{ -\code{ospsuite.reportingengine::TaskSettings} -> \code{GofTaskSettings} +\code{\link[ospsuite.reportingengine:TaskSettings]{ospsuite.reportingengine::TaskSettings}} -> \code{GofTaskSettings} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/MeanModelWorkflow.Rd b/man/MeanModelWorkflow.Rd index 4c6a11f7..341fb0fa 100644 --- a/man/MeanModelWorkflow.Rd +++ b/man/MeanModelWorkflow.Rd @@ -13,7 +13,7 @@ Other workflows: } \concept{workflows} \section{Super class}{ -\code{ospsuite.reportingengine::Workflow} -> \code{MeanModelWorkflow} +\code{\link[ospsuite.reportingengine:Workflow]{ospsuite.reportingengine::Workflow}} -> \code{MeanModelWorkflow} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/PlotTask.Rd b/man/PlotTask.Rd index 9b2d86bf..42ed480d 100644 --- a/man/PlotTask.Rd +++ b/man/PlotTask.Rd @@ -32,7 +32,7 @@ Other workflow tasks: } \concept{workflow tasks} \section{Super class}{ -\code{ospsuite.reportingengine::Task} -> \code{PlotTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{PlotTask} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/PopulationPlotTask.Rd b/man/PopulationPlotTask.Rd index 357d6ac2..7e6fc2d0 100644 --- a/man/PopulationPlotTask.Rd +++ b/man/PopulationPlotTask.Rd @@ -32,7 +32,7 @@ Other workflow tasks: } \concept{workflow tasks} \section{Super classes}{ -\code{ospsuite.reportingengine::Task} -> \code{ospsuite.reportingengine::PlotTask} -> \code{PopulationPlotTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{\link[ospsuite.reportingengine:PlotTask]{ospsuite.reportingengine::PlotTask}} -> \code{PopulationPlotTask} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/PopulationSensitivityAnalysisTask.Rd b/man/PopulationSensitivityAnalysisTask.Rd index f277871f..c20a58ac 100644 --- a/man/PopulationSensitivityAnalysisTask.Rd +++ b/man/PopulationSensitivityAnalysisTask.Rd @@ -32,7 +32,7 @@ Other workflow tasks: } \concept{workflow tasks} \section{Super classes}{ -\code{ospsuite.reportingengine::Task} -> \code{ospsuite.reportingengine::SensitivityAnalysisTask} -> \code{PopulationSensitivityAnalysisTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{\link[ospsuite.reportingengine:SensitivityAnalysisTask]{ospsuite.reportingengine::SensitivityAnalysisTask}} -> \code{PopulationSensitivityAnalysisTask} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/PopulationSimulationSet.Rd b/man/PopulationSimulationSet.Rd index cd398618..69127fd4 100644 --- a/man/PopulationSimulationSet.Rd +++ b/man/PopulationSimulationSet.Rd @@ -7,7 +7,7 @@ R6 class representing Reporting Engine Population Model Set } \section{Super class}{ -\code{ospsuite.reportingengine::SimulationSet} -> \code{PopulationSimulationSet} +\code{\link[ospsuite.reportingengine:SimulationSet]{ospsuite.reportingengine::SimulationSet}} -> \code{PopulationSimulationSet} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/PopulationWorkflow.Rd b/man/PopulationWorkflow.Rd index 02b9d278..76fc9850 100644 --- a/man/PopulationWorkflow.Rd +++ b/man/PopulationWorkflow.Rd @@ -13,7 +13,7 @@ Other workflows: } \concept{workflows} \section{Super class}{ -\code{ospsuite.reportingengine::Workflow} -> \code{PopulationWorkflow} +\code{\link[ospsuite.reportingengine:Workflow]{ospsuite.reportingengine::Workflow}} -> \code{PopulationWorkflow} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/QualificationTask.Rd b/man/QualificationTask.Rd index bf1a7e22..71b8df58 100644 --- a/man/QualificationTask.Rd +++ b/man/QualificationTask.Rd @@ -32,7 +32,7 @@ Other workflow tasks: } \concept{workflow tasks} \section{Super classes}{ -\code{ospsuite.reportingengine::Task} -> \code{ospsuite.reportingengine::PlotTask} -> \code{QualificationTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{\link[ospsuite.reportingengine:PlotTask]{ospsuite.reportingengine::PlotTask}} -> \code{QualificationTask} } \section{Methods}{ \subsection{Public methods}{ diff --git a/man/QualificationWorkflow.Rd b/man/QualificationWorkflow.Rd index 476cd45c..95d5de8d 100644 --- a/man/QualificationWorkflow.Rd +++ b/man/QualificationWorkflow.Rd @@ -13,7 +13,7 @@ Other workflows: } \concept{workflows} \section{Super class}{ -\code{ospsuite.reportingengine::Workflow} -> \code{QualificationWorkflow} +\code{\link[ospsuite.reportingengine:Workflow]{ospsuite.reportingengine::Workflow}} -> \code{QualificationWorkflow} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/SensitivityAnalysisTask.Rd b/man/SensitivityAnalysisTask.Rd index 4d9c8e74..0519313c 100644 --- a/man/SensitivityAnalysisTask.Rd +++ b/man/SensitivityAnalysisTask.Rd @@ -32,7 +32,7 @@ Other workflow tasks: } \concept{workflow tasks} \section{Super class}{ -\code{ospsuite.reportingengine::Task} -> \code{SensitivityAnalysisTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{SensitivityAnalysisTask} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/SimulationTask.Rd b/man/SimulationTask.Rd index 9ffd3656..49160e85 100644 --- a/man/SimulationTask.Rd +++ b/man/SimulationTask.Rd @@ -8,7 +8,7 @@ R6 class for SimulationTask settings } \keyword{internal} \section{Super class}{ -\code{ospsuite.reportingengine::Task} -> \code{SimulationTask} +\code{\link[ospsuite.reportingengine:Task]{ospsuite.reportingengine::Task}} -> \code{SimulationTask} } \section{Public fields}{ \if{html}{\out{
}} diff --git a/man/getOutputsForPKPlot.Rd b/man/getOutputsForPKPlot.Rd new file mode 100644 index 00000000..7c59a236 --- /dev/null +++ b/man/getOutputsForPKPlot.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-pop-pk-parameters.R +\name{getOutputsForPKPlot} +\alias{getOutputsForPKPlot} +\title{getOutputsForPKPlot} +\usage{ +getOutputsForPKPlot(structureSets) +} +\arguments{ +\item{structureSets}{List of `SimulationStructure` objects} +} +\value{ +list of `Output` objects +} +\description{ +Get the list of outputs and their PK parameters for population PK parameter plot +} +\keyword{internal} diff --git a/tests/data/pop-pk-diff/11_pk_parameters_C_max.csv b/tests/data/pop-pk-diff/11_pk_parameters_C_max.csv new file mode 100644 index 00000000..09e46872 --- /dev/null +++ b/tests/data/pop-pk-diff/11_pk_parameters_C_max.csv @@ -0,0 +1,2 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Pediatric",100,1.62024307074021,1.37856550981097,1.40225541303946,1.41401283394198,1.63118301540273,1.5105438452436,1.80346323636488,1.48746137029503,1.03060463296714 diff --git a/tests/data/pop-pk-diff/14_pk_parameters_Thalf.csv b/tests/data/pop-pk-diff/14_pk_parameters_Thalf.csv new file mode 100644 index 00000000..d3a49075 --- /dev/null +++ b/tests/data/pop-pk-diff/14_pk_parameters_Thalf.csv @@ -0,0 +1,2 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Pediatric",100,2.6718474,3.20246725,3.703302,4.33782725,9.45496805,5.0152532,7.16856473488834,4.04297352336446,1.61114262893437 diff --git a/tests/data/pop-pk-diff/18_pk_parameters_AUC_tEnd.csv b/tests/data/pop-pk-diff/18_pk_parameters_AUC_tEnd.csv new file mode 100644 index 00000000..0158decf --- /dev/null +++ b/tests/data/pop-pk-diff/18_pk_parameters_AUC_tEnd.csv @@ -0,0 +1,2 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Pediatric",100,185.691355,223.086375,264.4261,322.711725,398.277415,276.893055,71.1736784654361,268.613582178082,1.27682192538938 diff --git a/tests/data/pop-pk-diff/21_pk_parameters_C_max.csv b/tests/data/pop-pk-diff/21_pk_parameters_C_max.csv new file mode 100644 index 00000000..d0e4b0d7 --- /dev/null +++ b/tests/data/pop-pk-diff/21_pk_parameters_C_max.csv @@ -0,0 +1,2 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Pediatric",100,0.49638881,0.692672975,0.88179135,1.19939175,1.62077775,0.962632795,0.38752584204697,0.89348446740771,1.4714492167564 diff --git a/tests/data/pop-pk-diff/4_pk_parameters_AUC_tEnd.csv b/tests/data/pop-pk-diff/4_pk_parameters_AUC_tEnd.csv new file mode 100644 index 00000000..e2987436 --- /dev/null +++ b/tests/data/pop-pk-diff/4_pk_parameters_AUC_tEnd.csv @@ -0,0 +1,3 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Adults",100,725.21641,943.26235,1129.8035,1363.26475,1764.97505,1181.104562,320.807889400206,1138.85331223173,1.31346575932359 +"Pediatric",100,1067.15685,1299.56425,1570.4085,1901.34675,2575.60545,1639.460566,463.068489852523,1580.93166118953,1.30649062461577 diff --git a/tests/data/pop-pk-diff/6_pk_parameters_AUC_tEnd.csv b/tests/data/pop-pk-diff/6_pk_parameters_AUC_tEnd.csv new file mode 100644 index 00000000..85338dfb --- /dev/null +++ b/tests/data/pop-pk-diff/6_pk_parameters_AUC_tEnd.csv @@ -0,0 +1,2 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Pediatric",100,1.47150124471122,1.37773361779997,1.38998374496096,1.39470102927549,1.45928717235975,1.38807402726804,1.44344483147934,1.38817848111755,0.994689519191265 diff --git a/tests/data/pop-pk-diff/9_pk_parameters_C_max.csv b/tests/data/pop-pk-diff/9_pk_parameters_C_max.csv new file mode 100644 index 00000000..0410b98a --- /dev/null +++ b/tests/data/pop-pk-diff/9_pk_parameters_C_max.csv @@ -0,0 +1,3 @@ +"Population","N","5th pctl","25th pctl","50th pctl","75th pctl","95th pctl","Mean","SD","Geo Mean","Geo SD" +"Adults",100,1.79217375,2.94131325,3.6337025,4.58841875,6.12726215,3.75946195,1.30846781361633,3.53530137849457,1.43304539627776 +"Pediatric",100,2.9037571,4.054793,5.095379,6.488083,9.99468595,5.67883211,2.35977359782379,5.25862423286142,1.4769032246561 diff --git a/tests/testthat/test-different-pk.R b/tests/testthat/test-different-pk.R new file mode 100644 index 00000000..559759ed --- /dev/null +++ b/tests/testthat/test-different-pk.R @@ -0,0 +1,128 @@ +context("Population workflows with different PK parameters") +# Get test data +simulationFile <- getTestDataFilePath("input-data/Larson 2013 8-18y meal.pkml") +populationFilePeds <- getTestDataFilePath("input-data/Larson 2013 8-18y meal-Population.csv") +populationFileAdults <- getTestDataFilePath("input-data/Raltegravir Adult Population.csv") + +# List of necessary in results to test +refOutput <- getTestDataFilePath("pop-pk-diff") +# Sort files because list.files ordering is character by character +getOrderedFiles <- function(dirPath, pattern) { + fileNames <- list.files(dirPath, pattern = pattern) + # Keep only numbers included in filenames + fileNumbers <- as.numeric(gsub("[^[:digit:]]", "\\1", fileNames)) + return(file.path(dirPath, fileNames[order(fileNumbers)])) +} + +# Ensure the PK parameters are reset before test +updatePKParameter("C_max", displayName = "C_max", displayUnit = "µmol/l") +updatePKParameter("AUC_tEnd", displayName = "AUC_tEnd", displayUnit = "µmol*min/l") +initialOutput <- Output$new( + path = "Organism|PeripheralVenousBlood|Raltegravir|Plasma (Peripheral Venous Blood)", + displayName = "Venous Blood", + pkParameters = c("AUC_tEnd", "C_max") +) +# New PK parameter +outputPK <- Output$new( + path = "Organism|PeripheralVenousBlood|Raltegravir|Plasma (Peripheral Venous Blood)", + displayName = "Venous Blood", + pkParameters = c("AUC_tEnd", "C_max", "Thalf") +) +# New output path +outputPath <- Output$new( + path = "Organism|PeripheralVenousBlood|Raltegravir|Plasma Unbound (Peripheral Venous Blood)", + displayName = "Unbound Venous Blood", + pkParameters = c("AUC_tEnd", "C_max") +) + +setPeds <- PopulationSimulationSet$new( + simulationSetName = "Pediatric", + simulationFile = simulationFile, + populationFile = populationFilePeds, + outputs = c(outputPK, outputPath) +) +setAdults <- PopulationSimulationSet$new( + referencePopulation = TRUE, + simulationSetName = "Adults", + simulationFile = simulationFile, + populationFile = populationFileAdults, + outputs = initialOutput +) + +workflowFolderPediatric <- "test-pk-parameters-pediatric" +workflowFolderParallel <- "test-pk-parameters-parallel" + +workflowPediatric <- PopulationWorkflow$new( + createWordReport = FALSE, + workflowType = PopulationWorkflowTypes$pediatric, + simulationSets = c(setAdults, setPeds), + workflowFolder = workflowFolderPediatric +) +workflowParallel <- PopulationWorkflow$new( + createWordReport = FALSE, + workflowType = PopulationWorkflowTypes$parallelComparison, + simulationSets = c(setAdults, setPeds), + workflowFolder = workflowFolderParallel +) + +# Save time preventing run of same simulations and pk parameter analyses +workflowPediatric$activateTasks(c("simulate", "calculatePKParameters", "plotPKParameters")) +workflowParallel$inactivateTasks() +workflowParallel$activateTasks("plotPKParameters") + +workflowPediatric$runWorkflow() +# Before running parallel and ratio, save time by copying/pasting simulations and pk parameter analyses +file.copy(from = "test-pk-parameters-pediatric/SimulationResults", to = "test-pk-parameters-parallel", recursive = TRUE) +file.copy(from = "test-pk-parameters-pediatric/PKAnalysisResults", to = "test-pk-parameters-parallel", recursive = TRUE) +workflowParallel$runWorkflow() + +test_that("Workflows generate appropriate number of files", { + # Log files is 3 because of PK parameters union warnings + expect_length(list.files(workflowPediatric$workflowFolder, pattern = ".txt"), 3) + expect_length(list.files(workflowParallel$workflowFolder, pattern = ".txt"), 3) + # Reports + expect_length(list.files(workflowPediatric$workflowFolder, pattern = ".md"), 1) + expect_length(list.files(workflowParallel$workflowFolder, pattern = ".md"), 1) +}) + +pkAnalysisResultsPath <- file.path(workflowPediatric$workflowFolder, "PKAnalysisResults") +test_that("PKAnalysisResults includes appropriate number of files", { + expect_length(list.files(pkAnalysisResultsPath, pattern = ".csv"), 2) +}) + +pediatricPath <- file.path(workflowPediatric$workflowFolder, "PKAnalysis") +parallelPath <- file.path(workflowParallel$workflowFolder, "PKAnalysis") +test_that("PKAnalysis includes appropriate number of files", { + # Figures + expect_length(list.files(pediatricPath, pattern = ".png"), 86) + expect_length(list.files(parallelPath, pattern = ".png"), 14) + # Exported results + expect_length(list.files(pediatricPath, pattern = ".csv"), 7) + expect_length(list.files(parallelPath, pattern = ".csv"), 7) +}) + +test_that("Saved PK parameters summaries have correct values", { + pediatricFiles <- getOrderedFiles(pediatricPath, pattern = ".csv") + parallelFiles <- getOrderedFiles(parallelPath, pattern = ".csv") + refFiles <- getOrderedFiles(refOutput, pattern = ".csv") + for (fileIndex in seq_along(refFiles)) { + expect_equivalent( + readObservedDataFile(pediatricFiles[fileIndex]), + readObservedDataFile(refFiles[fileIndex]), + tolerance = comparisonTolerance() + ) + expect_equivalent( + readObservedDataFile(parallelFiles[fileIndex]), + readObservedDataFile(refFiles[fileIndex]), + tolerance = comparisonTolerance() + ) + } +}) + +# Ensure the PK parameters are reset after test +updatePKParameter("C_max", displayName = "C_max", displayUnit = "µmol/l") +updatePKParameter("AUC_tEnd", displayName = "AUC_tEnd", displayUnit = "µmol*min/l") + +# Clear test workflow folders +unlink(workflowPediatric$workflowFolder, recursive = TRUE) +unlink(workflowParallel$workflowFolder, recursive = TRUE)