Snapshot class for OSP snapshots
Snapshot.RdAn R6 class that represents an OSP snapshot file. This class provides methods to access different components of the snapshot and visualize its structure.
Supported snapshot versions
Snapshot accepts PK-Sim snapshots whose integer Version is within the
supported band 79 (v11.2) to 81 (v13), inclusive (see
osp.snapshots:::SUPPORTED_VERSION_MIN and
osp.snapshots:::SUPPORTED_VERSION_MAX). A snapshot above the ceiling
aborts as not supported in this version. A below-floor snapshot in the
74-78 band can be migrated by passing upgrade = TRUE, which round-trips
it through PK-Sim up to the version the installed ospsuite core emits;
migration requires that core to emit a supported version (79 to 81) and
aborts before converting when it would emit something above the ceiling.
Without upgrade = TRUE, a below-floor snapshot reports how to migrate and
does not load. Snapshots below 74 are too old to migrate and abort. A
snapshot newer than the installed ospsuite core (but still in band) loads
with a warning that it may not load or run there. Hand-rolled list input
must supply Version.
Active bindings
dataThe aggregated data of the snapshot from all components
pksim_versionThe human-readable PKSIM version corresponding to the snapshot version
pathThe path to the snapshot file relative to the working directory
compoundsList of Compound objects in the snapshot
expression_profilesList of ExpressionProfile objects in the snapshot
individualsList of Individual objects in the snapshot
formulationsList of Formulation objects in the snapshot
populationsList of Population objects in the snapshot
eventsList of Event objects in the snapshot
observer_setsList of ObserverSet objects in the snapshot
protocolsList of Protocol objects in the snapshot
observed_dataList of DataSet objects (observed data) in the snapshot
simulationsList of Simulation objects in the snapshot
Methods
Snapshot$new()
Create a new Snapshot object from a JSON file or a list
Usage
Snapshot$new(input, upgrade = FALSE)Arguments
inputPath to the snapshot JSON file, URL, template name, or a list containing snapshot data. The parsed data must contain an integer
Versionfield. Versions79to81load normally; versions74to78load only withupgrade = TRUE(otherwise they report how to migrate and abort); all other or missing versions abort (see the "Supported snapshot versions" section).upgradeLogical, default
FALSE. WhenTRUEand the snapshot'sVersionis in the below-floor migration band (74-78), the snapshot is round-tripped through the installed PK-Sim core to upgrade it to a supported version before loading (slow, several minutes). WhenFALSE, a below-floor snapshot reports how to migrate and aborts. Ignored for in-band snapshots, which are never migrated.
Snapshot$add_individual()
Add one or more Individual objects to the snapshot. References to expression profiles not yet in the snapshot trigger one informational warning per individual; the add proceeds either way.
Arguments
individualAn Individual object created with create_individual(), or a list of such objects.
Examples
# Create a new individual
ind <- create_individual(name = "New Patient", age = 35, weight = 70)
# Add the individual to a snapshot
snapshot$add_individual(ind)
# Add several at once
patients <- list(
create_individual("Patient_A", age = 25),
create_individual("Patient_B", age = 45)
)
snapshot$add_individual(patients)Snapshot$add_formulation()
Add one or more Formulation objects to the snapshot.
Arguments
formulationA Formulation object created with create_formulation(), or a list of such objects.
Examples
# Create a new formulation
form <- create_formulation(name = "Tablet", type = "Weibull")
# Add the formulation to a snapshot
snapshot$add_formulation(form)
# Add several at once
forms <- list(
create_formulation("Tablet", type = "Weibull"),
create_formulation("Oral solution", type = "First Order")
)
snapshot$add_formulation(forms)Snapshot$add_expression_profile()
Add one or more ExpressionProfile objects to the snapshot.
Examples
# Create a new expression profile
profile_data <- list(
Type = "Enzyme",
Species = "Human",
Molecule = "CYP3A4",
Category = "Healthy",
Parameters = list()
)
profile <- ExpressionProfile$new(profile_data)
# Add the expression profile to a snapshot
snapshot$add_expression_profile(profile)
# Add several at once
snapshot$add_expression_profile(list(profile, profile))Snapshot$add_observed_data()
Add one or more DataSet objects (observed data) to the snapshot.
Snapshot$add_simulation()
Build a simulation from named arguments and attach it, or attach a pre-built simulation.
The build mode is the entry point: with the snapshot in hand it
resolves compound references and derives defaults (calculation
methods, formulation key, alternatives) before attaching. Supply
name plus exactly one of individual / population to build; each
inline compounds entry is a config list
(list(name =, protocol =, formulation =, processes =, calculation_methods =, alternatives =)). Alternatively supply a
pre-built Simulation (or a list of them) through simulation.
References to building blocks not yet in the snapshot trigger one
informational warning per simulation; the add proceeds either way.
Usage
Snapshot$add_simulation(
simulation = NULL,
name = NULL,
model = "4Comp",
individual = NULL,
population = NULL,
compounds = NULL,
events = NULL,
observer_sets = NULL,
observed_data_names = NULL,
solver = NULL,
output_schema = NULL,
output_selections = NULL,
output_mappings = NULL,
parameters = NULL,
advanced_parameters = NULL,
description = NULL,
allow_aging = NULL
)Arguments
simulationA pre-built Simulation object, or a list of such objects. Leave
NULLto build a simulation from the named arguments instead.nameCharacter. Simulation name (required in build mode).
modelCharacter. PK-Sim model name (defaults to
"4Comp").individualCharacter. Name of the individual building block. Mutually exclusive with
population.populationCharacter. Name of the population building block. Mutually exclusive with
individual.compoundsList of inline compound-config lists (
list(name =, protocol =, formulation =, processes =, calculation_methods =, alternatives =)).alternativesis a named character vector (or named list of length-one strings) mapping a friendly property name (lipophilicity,fraction_unbound,solubility,intestinal_permeability,permeability) to the alternative label to select on that compound, for examplealternatives = c(solubility = "FaSSIF"); it overrides the derived default for the named groups only, every other group is still defaulted from the compound.formulationaccepts a single string (bound to the protocol's inferred first slot key, unchanged) or a named character vector (or named list of length-one strings) mapping application-slot key to formulation name for a multi-slot protocol, for exampleformulation = c(Formulation = "Oral solution", "Formulation 2" = "IV solution").eventsList of EventSelection objects or raw lists.
observer_setsList of ObserverSetSelection objects or raw lists.
observed_data_namesCharacter vector of observed-data names.
solverA SolverSettings object or raw list. Defaults to PK-Sim defaults.
output_schemaAn OutputSchema object or raw list. Defaults to an empty schema.
output_selectionsCharacter vector of output quantity paths.
output_mappingsList of OutputMapping objects or raw lists.
parametersList of LocalizedParameter objects (created with
create_parameter(path = ..., ...)) or raw parameter lists.advanced_parametersList of AdvancedParameter objects or raw lists (population simulations only).
descriptionCharacter. Free-text description of the simulation.
allow_agingLogical. Whether the simulation allows aging.
Examples
## ------------------------------------------------
## Method `Snapshot$add_individual()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Create a new individual
ind <- create_individual(name = "New Patient", age = 35, weight = 70)
# Add the individual to a snapshot
snapshot$add_individual(ind)
# Add several at once
patients <- list(
create_individual("Patient_A", age = 25),
create_individual("Patient_B", age = 45)
)
snapshot$add_individual(patients)
} # }
## ------------------------------------------------
## Method `Snapshot$remove_individual()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Remove an individual from the snapshot
snapshot$remove_individual("Subject_001")
} # }
## ------------------------------------------------
## Method `Snapshot$add_formulation()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Create a new formulation
form <- create_formulation(name = "Tablet", type = "Weibull")
# Add the formulation to a snapshot
snapshot$add_formulation(form)
# Add several at once
forms <- list(
create_formulation("Tablet", type = "Weibull"),
create_formulation("Oral solution", type = "First Order")
)
snapshot$add_formulation(forms)
} # }
## ------------------------------------------------
## Method `Snapshot$remove_formulation()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Remove a formulation from the snapshot
snapshot$remove_formulation("Tablet")
} # }
## ------------------------------------------------
## Method `Snapshot$remove_population()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Remove a population from the snapshot
snapshot$remove_population("pop_1")
} # }
## ------------------------------------------------
## Method `Snapshot$add_expression_profile()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Create a new expression profile
profile_data <- list(
Type = "Enzyme",
Species = "Human",
Molecule = "CYP3A4",
Category = "Healthy",
Parameters = list()
)
profile <- ExpressionProfile$new(profile_data)
# Add the expression profile to a snapshot
snapshot$add_expression_profile(profile)
# Add several at once
snapshot$add_expression_profile(list(profile, profile))
} # }
## ------------------------------------------------
## Method `Snapshot$remove_expression_profile()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Remove an expression profile from the snapshot
snapshot$remove_expression_profile("CYP3A4_Human_Healthy")
} # }