Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1213 provide default axes settings in qualification workflows #1216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions R/qualification-time-profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -586,25 +586,6 @@ getTimeProfileObservedDataFromResults <- function(observedResults, molWeight, ax
))
}

#' @title getDefaultTimeProfileAxesSettings
#' @description Get the default axes settings for mean and population time profiles
#' for keeping compatibility with configuration plan from Matlab version
#' @return List of `x` and `y` axes settings
#' @keywords internal
getDefaultTimeProfileAxesSettings <- function() {
xAxis <- list(
dimension = ospsuite::ospDimensions$Time, unit = ospsuite::ospUnits$Time$h,
min = NULL, max = NULL, scale = tlf::Scaling$lin,
grid = list(color = reEnv$theme$background$xGrid$color, linetype = reEnv$theme$background$xGrid$linetype)
)
yAxis <- list(
dimension = ospsuite::ospDimensions$`Concentration (mass)`, unit = ospsuite::ospUnits$`Concentration [mass]`$`µg/l`,
min = NULL, max = NULL, scale = tlf::Scaling$log,
grid = list(color = reEnv$theme$background$yGrid$color, linetype = reEnv$theme$background$yGrid$linetype)
)
return(list(x = xAxis, y = yAxis))
}

#' @title getObservedErrorValues
#' @description
#' Get the observed data error range to display on time profile plots
Expand Down
31 changes: 30 additions & 1 deletion R/utilities-configuration-plan.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ getAxesProperties <- function(axesSettings) {
return(list(x = xAxis, y = yAxis, y2 = y2Axis, y3 = y3Axis))
}

#' @title formatAxisProperties
#' @description
#' Format configuration plan field values to a list compatible with `tlf` package nomenclature
#' @param axisField List of configuration plan field properties
#' @return A list of properties compatible with `tlf` package nomenclature
#' @keywords internal
formatAxisProperties <- function(axisField) {
list(
dimension = axisField$Dimension,
Expand All @@ -137,6 +143,29 @@ formatAxisProperties <- function(axisField) {
)
}

#' @title getAxesPropertiesFromName
#' @description
#' Get axes properties from global field `AxesSettings` of configuration plan if defined,
#' otherwise use default values.
#' @param configurationPlan A `ConfigurationPlan` object
#' @param plotName Field name of the plot in the configuration plan `AxesSettings`
#' @return A list of properties for axes identified for `x`, `y` and `y2` axes.
#' The identified properties are directly compatible with `tlf` package nomenclature
#' @keywords internal
#' @import jsonlite
getAxesPropertiesFromName <- function(configurationPlan, plotName) {
axesProperties <- getAxesProperties(configurationPlan$plots$AxesSettings[[plotName]])
if (!isEmpty(axesProperties)) {
return(axesProperties)
}
# If no axes settings are defined, use default values stored in the package json file
defaultAxisSettings <- jsonlite::fromJSON(
txt = system.file("extdata", "qualification-axis-settings.json", package = "ospsuite.reportingengine"),
simplifyVector = FALSE
)
return(getAxesProperties(defaultAxisSettings[[plotName]]))
}

#' @title updatePlotAxes
#' @description Update the axes, grid and legend properties of a plot object based on the identified axes properties
#' @param plotObject A ggplot object
Expand Down Expand Up @@ -191,7 +220,7 @@ updatePlotAxes <- function(plotObject, axesProperties) {
tlfLinetype <- function(configurationLinetype) {
# Unknown or NULL value will translate as NULL
# which will lead to use default behaviour
if (isOfLength(configurationLinetype, 0)) {
if (isEmpty(configurationLinetype)) {
return()
}
# tolower is used to ensure that there is no issue with caps from field values
Expand Down
37 changes: 30 additions & 7 deletions R/utilities-task.R
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,10 @@ loadQualificationTimeProfilesTask <- function(workflow, configurationPlan) {
workflowFolder = workflow$workflowFolder,
active = active,
message = defaultWorkflowMessages$plotTimeProfiles,
settings = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$TimeProfile) %||% getDefaultTimeProfileAxesSettings())
settings = list(axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "TimeProfile"
))
))
}

Expand Down Expand Up @@ -960,8 +963,14 @@ loadGOFMergedTask <- function(workflow, configurationPlan) {
active = active,
message = defaultWorkflowMessages$plotGOFMerged,
settings = list(
predictedVsObserved = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$GOFMergedPlotsPredictedVsObserved)),
residualsOverTime = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$GOFMergedPlotsResidualsOverTime)),
predictedVsObserved = list(axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "GOFMergedPlotsPredictedVsObserved"
)),
residualsOverTime = list(axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "GOFMergedPlotsResidualsOverTime"
)),
digits = reEnv$formatNumericsDigits,
nsmall = reEnv$formatNumericsSmall,
scientific = reEnv$formatNumericsScientific
Expand Down Expand Up @@ -1007,7 +1016,12 @@ loadQualificationComparisonTimeProfileTask <- function(workflow, configurationPl
workflowFolder = workflow$workflowFolder,
active = active,
message = defaultWorkflowMessages$plotComparisonTimeProfiles,
settings = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$ComparisonTimeProfile))
settings = list(
axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "ComparisonTimeProfile"
)
)
))
}

Expand Down Expand Up @@ -1049,7 +1063,10 @@ loadPlotPKRatioTask <- function(workflow, configurationPlan) {
active = active,
message = defaultWorkflowMessages$plotPKRatio,
settings = list(
axes = getAxesProperties(configurationPlan$plots$AxesSettings$PKRatioPlots),
axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "PKRatioPlots"
),
digits = reEnv$formatNumericsDigits,
nsmall = reEnv$formatNumericsSmall,
scientific = reEnv$formatNumericsScientific,
Expand Down Expand Up @@ -1115,8 +1132,14 @@ loadPlotDDIRatioTask <- function(workflow, configurationPlan) {
active = active,
message = defaultWorkflowMessages$plotDDIRatio,
settings = list(
predictedVsObserved = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$DDIRatioPlotsPredictedVsObserved)),
residualsOverTime = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$DDIRatioPlotsResidualsVsObserved)),
predictedVsObserved = list(axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "DDIRatioPlotsPredictedVsObserved"
)),
residualsOverTime = list(axes = getAxesPropertiesFromName(
configurationPlan = configurationPlan,
plotName = "DDIRatioPlotsResidualsVsObserved"
)),
digits = reEnv$formatNumericsDigits,
nsmall = reEnv$formatNumericsSmall,
scientific = reEnv$formatNumericsScientific
Expand Down
114 changes: 114 additions & 0 deletions inst/extdata/qualification-axis-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yuri05
Let me know if some of the default properties need to be changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good for me so far

"GOFMergedPlotsPredictedVsObserved": [
{
"Type": "X",
"Dimension": "Concentration (mass)",
"Unit": "µg/l",
"GridLines": false,
"Scaling": "Log"
},
{
"Type": "Y",
"Dimension": "Concentration (mass)",
"Unit": "µg/l",
"GridLines": false,
"Scaling": "Log"
}
],
"GOFMergedPlotsResidualsOverTime": [
{
"Type": "X",
"Dimension": "Time",
"Unit": "h",
"GridLines": false,
"Scaling": "Linear"
},
{
"Type": "Y",
"Dimension": "Dimensionless",
"Unit": "",
"GridLines": false,
"Scaling": "Linear"
}
],
"ComparisonTimeProfile": [
{
"Type": "X",
"Dimension": "Time",
"Unit": "h",
"GridLines": false,
"Scaling": "Linear"
},
{
"Type": "Y",
"Dimension": "Concentration (mass)",
"Unit": "µg/l",
"GridLines": false,
"Scaling": "Log"
}
],
"DDIRatioPlotsPredictedVsObserved": [
{
"Type": "X",
"Dimension": "Dimensionless",
"Unit": "",
"GridLines": false,
"Scaling": "Log"
},
{
"Type": "Y",
"Dimension": "Dimensionless",
"Unit": "",
"GridLines": false,
"Scaling": "Log"
}
],
"DDIRatioPlotsResidualsVsObserved": [
{
"Type": "X",
"Dimension": "Dimensionless",
"Unit": "",
"GridLines": false,
"Scaling": "Log"
},
{
"Type": "Y",
"Dimension": "Dimensionless",
"Unit": "",
"GridLines": false,
"Scaling": "Log"
}
],
"PKRatioPlots": [
{
"Type": "X",
"Dimension": "Age",
"Unit": "year(s)",
"GridLines": false,
"Scaling": "Linear"
},
{
"Type": "Y",
"Dimension": "Dimensionless",
"Unit": "",
"GridLines": false,
"Scaling": "Log"
}
],
"TimeProfile": [
{
"Type": "X",
"Dimension": "Time",
"Unit": "h",
"GridLines": false,
"Scaling": "Linear"
},
{
"Type": "Y",
"Dimension": "Concentration (mass)",
"Unit": "µg/l",
"GridLines": false,
"Scaling": "Log"
}
]
}
18 changes: 18 additions & 0 deletions man/formatAxisProperties.Rd

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

22 changes: 22 additions & 0 deletions man/getAxesPropertiesFromName.Rd

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

16 changes: 0 additions & 16 deletions man/getDefaultTimeProfileAxesSettings.Rd

This file was deleted.

Loading