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

Investigate differences batch #2002

Merged
merged 2 commits into from
Dec 1, 2021
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
9 changes: 9 additions & 0 deletions src/PKSim.Core/Snapshots/Mappers/ExpressionProfileMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,20 @@ public override async Task<ModelExpressionProfile> MapToModel(SnapshotExpression

//We need to normalize relative expressions when loading from old format
if (isV9Format(snapshot))
{
//Global parameters were saved directly under the snapshot parameter
await updateGlobalMoleculeParameters(snapshot, molecule);
NormalizeRelativeExpressionCommand.NormalizeExpressions(individual, molecule);
}

return expressionProfile;
}

private Task updateGlobalMoleculeParameters(SnapshotExpressionProfile snapshot, IndividualMolecule molecule)
{
return _parameterMapper.MapParameters(snapshot.Parameters, molecule, molecule.Name);
}

private void updateMoleculePropertiesToMolecule(IndividualMolecule molecule, SnapshotExpressionProfile snapshot, ModelIndividual individual)
{
switch (molecule)
Expand Down
4 changes: 3 additions & 1 deletion src/PKSim.Core/Snapshots/Mappers/IndividualMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ private async Task convertMoleculesToExpressionProfiles(SnapshotIndividual indiv
var expressionProfiles = await _expressionProfileMapper.MapToModels(individualSnapshot.Molecules);
foreach (var expressionProfile in expressionProfiles)
{
var (molecule, individual) = expressionProfile;
project.AddBuildingBlock(expressionProfile);
//this needs to happen here since molecule parameters were defined in individual in v10
await updateIndividualParameters(individualSnapshot, expressionProfile.Individual);
await updateIndividualParameters(individualSnapshot, individual);
}

individualSnapshot.ExpressionProfiles = expressionProfiles.AllNames().ToArray();
Expand All @@ -102,5 +103,6 @@ private Task updateIndividualParameters(SnapshotIndividual snapshot, ModelIndivi
//We do not show warning for v10 format as we will FOR SURE have missing parameters
return _parameterMapper.MapLocalizedParameters(snapshot.Parameters, individual, showParameterNotFoundWarning: !isV10Format(snapshot));
}

}
}
4 changes: 3 additions & 1 deletion src/PKSim.Core/Snapshots/Mappers/ParameterMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OSPSuite.Core.Domain.Services;
using OSPSuite.Core.Domain.UnitSystem;
using OSPSuite.Core.Services;
using OSPSuite.Utility.Extensions;
using PKSim.Assets;
using SnapshotParameter = PKSim.Core.Snapshots.Parameter;
using SnapshotTableFormula = PKSim.Core.Snapshots.TableFormula;
Expand Down Expand Up @@ -136,7 +137,8 @@ private async Task<LocalizedParameter[]> orderByPath(Task<LocalizedParameter[]>

public virtual Task MapLocalizedParameters(IReadOnlyList<LocalizedParameter> localizedParameters, IContainer container, bool showParameterNotFoundWarning = true)
{
if (localizedParameters == null || !localizedParameters.Any())
//undefined or empty or actually not localized parameters (coming from conversions probably)
if (localizedParameters == null || !localizedParameters.Any() || localizedParameters.All(x=> x.Path.IsNullOrEmpty()))
return Task.FromResult(false);

var allParameters = _containerTask.CacheAllChildren<IParameter>(container);
Expand Down
190 changes: 190 additions & 0 deletions tests/PKSim.Tests/Data/ind_expression_v9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"Version": 77,
"Individuals": [
{
"Name": "Ind",
"Seed": 17189110,
"OriginData": {
"CalculationMethods": [
"SurfaceAreaPlsInt_VAR1",
"Body surface area - Mosteller"
],
"Species": "Human",
"Population": "European_ICRP_2002",
"Gender": "MALE",
"Age": {
"Value": 30.0,
"Unit": "year(s)"
}
},
"Parameters": [
{
"Path": "Organism|Liver|EHC continuous fraction",
"Value": 1.0,
"ValueOrigin": {
"Source": "Unknown"
}
}
],
"Molecules": [
{
"Name": "CYP3A4",
"Type": "Enzyme",
"MembraneLocation": "Apical",
"TissueLocation": "Intracellular",
"IntracellularVascularEndoLocation": "Endosomal",
"Expression": [
{
"Name": "Brain",
"Value": 0.0041682898325
},
{
"Name": "Gonads",
"Value": 0.00078691079081
},
{
"Name": "Kidney",
"Value": 0.0053603428126
},
{
"Name": "Periportal",
"Value": 1.0
},
{
"Name": "Pericentral",
"Value": 1.0
},
{
"Name": "Lung",
"Value": 0.00042695753798
},
{
"Name": "SmallIntestine",
"Value": 0.0727697702
},
{
"Name": "Duodenum",
"Value": 0.0727697702
},
{
"Name": "UpperJejunum",
"Value": 0.0727697702
},
{
"Name": "LowerJejunum",
"Value": 0.0727697702
},
{
"Name": "UpperIleum",
"Value": 0.0727697702
},
{
"Name": "LowerIleum",
"Value": 0.0727697702
}
],
"Ontogeny": {
"Name": "CYP3A4"
},
"Parameters": [
{
"Name": "Reference concentration",
"Value": 4.32,
"Unit": "µmol/l"
},
{
"Name": "t1/2 (liver)",
"Value": 36.0,
"Unit": "h",
"ValueOrigin": {
"Source": "Unknown"
}
},
{
"Name": "t1/2 (intestine)",
"Value": 23.0,
"Unit": "h"
}
]
},
{
"Name": "CYP2C8",
"Type": "Enzyme",
"MembraneLocation": "Apical",
"TissueLocation": "Intracellular",
"IntracellularVascularEndoLocation": "Endosomal",
"Expression": [
{
"Name": "Brain",
"Value": 0.00041051218109
},
{
"Name": "Gonads",
"Value": 0.0138116248
},
{
"Name": "Kidney",
"Value": 0.0012660656052
},
{
"Name": "Periportal",
"Value": 1.0
},
{
"Name": "Pericentral",
"Value": 1.0
},
{
"Name": "Lung",
"Value": 0.00092269326683
},
{
"Name": "SmallIntestine",
"Value": 0.0031843468252
},
{
"Name": "Duodenum",
"Value": 0.0031843468252
},
{
"Name": "UpperJejunum",
"Value": 0.0031843468252
},
{
"Name": "LowerJejunum",
"Value": 0.0031843468252
},
{
"Name": "UpperIleum",
"Value": 0.0031843468252
},
{
"Name": "LowerIleum",
"Value": 0.0031843468252
}
],
"Ontogeny": {
"Name": "CYP2C8"
},
"Parameters": [
{
"Name": "Reference concentration",
"Value": 2.56,
"Unit": "µmol/l"
},
{
"Name": "t1/2 (liver)",
"Value": 23.000001425,
"Unit": "h"
},
{
"Name": "t1/2 (intestine)",
"Value": 23.0,
"Unit": "h"
}
]
}
]
}
]
}
46 changes: 46 additions & 0 deletions tests/PKSim.Tests/IntegrationTests/IndividualMapperSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,50 @@ public void should_have_added_the_newly_created_expression_profile_as_reference_
_individual.AllExpressionProfiles().ShouldContain(_expressionProfileEnzyme, _expressionProfileTransporter);
}
}

public class When_loading_a_snapshot_file_containing_expression_created_in_v9 : ContextWithLoadedSnapshot
{
private Individual _individual;
private ExpressionProfile _expressionProfileCYP3A4;
private ExpressionProfile _expressionProfileCYP2C8;

public override void GlobalContext()
{
base.GlobalContext();
LoadSnapshot("ind_expression_v9");
_individual = FindByName<Individual>("Ind");
_expressionProfileCYP3A4 = FindByName<ExpressionProfile>("CYP3A4|Human|Ind");
_expressionProfileCYP2C8 = FindByName<ExpressionProfile>("CYP2C8|Human|Ind");
}

[Observation]
public void should_have_created_an_expression_profile_based_on_the_value_defined_in_the_snapshot_file_for_the_enzyme_cyp3A4()
{
_expressionProfileCYP3A4.ShouldNotBeNull();
var (enzyme, individual) = _expressionProfileCYP3A4;
enzyme.Ontogeny.Name.ShouldBeEqualTo("CYP3A4");
enzyme.ReferenceConcentration.ValueInDisplayUnit.ShouldBeEqualTo(4.32);
var expressionInBone = individual.Organism.EntityAt<MoleculeExpressionContainer>("Brain", "Intracellular", enzyme.Name);
expressionInBone.RelativeExpressionParameter.Value.ShouldBeEqualTo(0.004168, 1e-2);
}

[Observation]
public void should_have_created_an_expression_profile_based_on_the_value_defined_in_the_snapshot_file_for_the_enzyme_cyp2C8()
{
_expressionProfileCYP2C8.ShouldNotBeNull();
var (enzyme, individual) = _expressionProfileCYP2C8;
enzyme.Ontogeny.Name.ShouldBeEqualTo("CYP2C8");
enzyme.ReferenceConcentration.ValueInDisplayUnit.ShouldBeEqualTo(2.56);
enzyme.HalfLifeIntestine.ValueInDisplayUnit.ShouldBeEqualTo(23);
var expressionInBone = individual.Organism.EntityAt<MoleculeExpressionContainer>("Kidney", "Intracellular", enzyme.Name);
expressionInBone.RelativeExpressionParameter.Value.ShouldBeEqualTo(0.0012661, 1e-2);
}

[Observation]
public void should_have_added_the_newly_created_expression_profile_as_reference_in_the_individual()
{
_individual.AllExpressionProfiles().ShouldContain(_expressionProfileCYP3A4, _expressionProfileCYP2C8);
}
}

}