Skip to content

Commit

Permalink
Fixes #1208 use IndividualId intersect for PK ratio in same population (
Browse files Browse the repository at this point in the history
  • Loading branch information
pchelle authored Apr 26, 2024
1 parent ed3eb41 commit 935612d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
33 changes: 33 additions & 0 deletions R/error-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,36 @@ checkHasRunOnAllCores <- function(coreResults, inputName, inputType, runType = "
)
return(invisible())
}

#' @title checkSamePopulationIds
#' @description
#' Check if PKAnalses with same population actually use the same IndividualIds
#' @param setIds A vector of IndividualIds for a simulation set
#' @param referenceSetIds A vector of IndividualIds for the reference simulation set
#' @param setName Name of simulation set for warning message
#' @param referenceSetName Name of the reference simulation set for warning message
#' @keywords internal
checkSamePopulationIds <- function(setIds,
referenceSetIds,
setName,
referenceSetName) {
tryCatch(
{
validateIsIncluded(referenceSetIds, setIds)
},
error = function(e) {
missingIds <- setdiff(referenceSetIds, setIds)
warning(messages$warningPKAnalysesMissingIds(missingIds, setName), call. = FALSE)
}
)
tryCatch(
{
validateIsIncluded(setIds, referenceSetIds)
},
error = function(e) {
missingIds <- setdiff(setIds, referenceSetIds)
warning(messages$warningPKAnalysesMissingIds(missingIds, referenceSetName), call. = FALSE)
}
)
return(invisible())
}
9 changes: 8 additions & 1 deletion R/messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,14 @@ messages <- list(
warningNAFoundInPKAnalysisFile = function(filePath) {
paste0(highlight("NaN"), " found in PK analysis file '", highlight(filePath), "'.")
},

warningPKAnalysesMissingIds = function(ids, setName){
paste0(
"Missing ", highlight("IndividualIds"), " in PKAnalysis file for simulation set '",
highlight(setName), "': ",
paste0("'", highlight(ids), "'", collapse = ", ")
)
},

#----- Info messages ----
runStarting = function(runName, subRun = NULL) {
if (is.null(subRun)) {
Expand Down
10 changes: 10 additions & 0 deletions R/utilities-ratio-comparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ getPKRatioSummaryForSamePopulation <- function(structureSet, referenceSet) {
# Check that both PK data to be compared are included in reference PK data
validateIsIncluded(unique(pkData$QuantityPath), unique(referencePKData$QuantityPath))
validateIsIncluded(unique(pkData$Parameter), unique(referencePKData$Parameter))
# Check that same individuals are present in both data sets and use intersection
checkSamePopulationIds(
setIds = pkData$IndividualId,
referenceSetIds = referencePKData$IndividualId,
setName = structureSet$simulationSet$simulationSetName,
referenceSetName = referenceSet$simulationSet$simulationSetName
)
ids <- intersect(pkData$IndividualId, referencePKData$IndividualId)
pkData <- pkData %>% filter(IndividualId %in% ids)
referencePKData <- referencePKData %>% filter(IndividualId %in% ids)

# Pivot table to get fast computation of ratios and their statistics
quantityPaths <- unique(pkData$QuantityPath)
Expand Down
21 changes: 21 additions & 0 deletions man/checkSamePopulationIds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 935612d

Please sign in to comment.