From acda3753314dc153c68bbb460dba56dae8b49642 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Fri, 29 Jul 2022 17:41:05 -0400 Subject: [PATCH] Fixes #2256 snapshot initial concentration issue --- .../Snapshots/Mappers/ParameterMapper.cs | 7 +- ...expression_with_modified_initial_conc.json | 154 ++++++++++++++++++ .../IntegrationTests/IndividualMapperSpecs.cs | 17 ++ 3 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 tests/PKSim.Tests/Data/ind_expression_with_modified_initial_conc.json diff --git a/src/PKSim.Core/Snapshots/Mappers/ParameterMapper.cs b/src/PKSim.Core/Snapshots/Mappers/ParameterMapper.cs index 38a22422c..aff7198dd 100644 --- a/src/PKSim.Core/Snapshots/Mappers/ParameterMapper.cs +++ b/src/PKSim.Core/Snapshots/Mappers/ParameterMapper.cs @@ -104,10 +104,11 @@ public override async Task MapToModel(SnapshotParameter snapshot, Pa parameter.DisplayUnit = parameter.Dimension.UnitOrDefault(displayUnit); //This needs to come AFTER formula update so that the base value is accurate - var baseValue = parameter.Value; var snapshotValueInBaseUnit = parameter.ConvertToBaseUnit(snapshot.Value); - - if (!ValueComparer.AreValuesEqual(baseValue, snapshotValueInBaseUnit)) + var (value, success) = parameter.TryGetValue(); + + //Value could not be parsed (e.g. Initial concentration was overwritten) or the value are indeed different + if (!success || !ValueComparer.AreValuesEqual(value, snapshotValueInBaseUnit)) { parameter.Value = snapshotValueInBaseUnit; parameter.IsDefault = false; diff --git a/tests/PKSim.Tests/Data/ind_expression_with_modified_initial_conc.json b/tests/PKSim.Tests/Data/ind_expression_with_modified_initial_conc.json new file mode 100644 index 000000000..2280c2ec8 --- /dev/null +++ b/tests/PKSim.Tests/Data/ind_expression_with_modified_initial_conc.json @@ -0,0 +1,154 @@ +{ + "Version": 79, + "ExpressionProfiles": [ + { + "Type": "Enzyme", + "Species": "Human", + "Molecule": "CYP3A4", + "Category": "European (P-gp modified, CYP3A4 REFINED 36 h)", + "Parameters": [ + { + "Path": "CYP3A4|Reference concentration", + "Value": 4.32, + "Unit": "µmol/l" + }, + { + "Path": "CYP3A4|t1/2 (intestine)", + "Value": 23.0, + "Unit": "h" + }, + { + "Path": "CYP3A4|t1/2 (liver)", + "Value": 36.0, + "Unit": "h", + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|Brain|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|Gonads|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|Kidney|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|Liver|Pericentral|Intracellular|CYP3A4|Initial concentration", + "Value": 3.414, + "Unit": "µmol/l" + }, + { + "Path": "Organism|Liver|Pericentral|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|Liver|Periportal|Intracellular|CYP3A4|Initial concentration", + "Value": 3.414, + "Unit": "µmol/l" + }, + { + "Path": "Organism|Liver|Periportal|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|Lung|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|SmallIntestine|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|SmallIntestine|Mucosa|Duodenum|Intracellular|CYP3A4|Initial concentration", + "Value": 0.516, + "Unit": "µmol/l" + }, + { + "Path": "Organism|SmallIntestine|Mucosa|Duodenum|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|SmallIntestine|Mucosa|LowerIleum|Intracellular|CYP3A4|Initial concentration", + "Value": 0.138, + "Unit": "µmol/l" + }, + { + "Path": "Organism|SmallIntestine|Mucosa|LowerIleum|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|SmallIntestine|Mucosa|LowerJejunum|Intracellular|CYP3A4|Initial concentration", + "Value": 0.268, + "Unit": "µmol/l" + }, + { + "Path": "Organism|SmallIntestine|Mucosa|LowerJejunum|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|SmallIntestine|Mucosa|UpperIleum|Intracellular|CYP3A4|Initial concentration", + "Value": 0.136, + "Unit": "µmol/l" + }, + { + "Path": "Organism|SmallIntestine|Mucosa|UpperIleum|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + }, + { + "Path": "Organism|SmallIntestine|Mucosa|UpperJejunum|Intracellular|CYP3A4|Initial concentration", + "Value": 0.283, + "Unit": "µmol/l" + }, + { + "Path": "Organism|SmallIntestine|Mucosa|UpperJejunum|Intracellular|CYP3A4|Relative expression", + "Value": 0.0, + "ValueOrigin": { + "Source": "Unknown" + } + } + ], + "Localization": "Intracellular, BloodCellsIntracellular, VascEndosome", + "Ontogeny": { + "Name": "CYP3A4" + } + } + ] +} \ No newline at end of file diff --git a/tests/PKSim.Tests/IntegrationTests/IndividualMapperSpecs.cs b/tests/PKSim.Tests/IntegrationTests/IndividualMapperSpecs.cs index 36c352ccf..0ce6a2534 100644 --- a/tests/PKSim.Tests/IntegrationTests/IndividualMapperSpecs.cs +++ b/tests/PKSim.Tests/IntegrationTests/IndividualMapperSpecs.cs @@ -223,4 +223,21 @@ public void should_have_set_the_value_of_the_global_molecule_parameters_as_expec } } + public class When_loading_a_snapshot_with_an_expression_profile_where_the_initial_concentration_was_overwritten : ContextWithLoadedSnapshot + { + private ExpressionProfile _expressionProfile; + + public override void GlobalContext() + { + base.GlobalContext(); + LoadSnapshot("ind_expression_with_modified_initial_conc"); + _expressionProfile = First(); + } + + [Observation] + public void should_have_been_able_to_load_the_profile() + { + _expressionProfile.ShouldNotBeNull(); + } + } } \ No newline at end of file