Skip to content

Commit

Permalink
Fixes #1330 export snapshot protein parameters (#1418)
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre authored Feb 11, 2020
1 parent 3903078 commit 62a3e72
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/PKSim.Core/Snapshots/Mappers/MoleculeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public override async Task<Molecule> MapToSnapshot(IndividualMolecule molecule)
return snapshot;
}

protected override bool ShouldExportParameterToSnapshot(IParameter parameter)
{
//For a protein, we export all global parameters to ensure that they do not get out of sync when loading from snapshot
var defaultShouldExport = base.ShouldExportParameterToSnapshot(parameter);
return defaultShouldExport || parameter.IsIndividualMoleculeGlobal();
}

private async Task<ExpressionContainer[]> expressionFor(IndividualMolecule molecule)
{
var expression = await _expressionContainerMapper.MapToSnapshots(molecule.AllExpressionsContainers());
Expand Down
48 changes: 25 additions & 23 deletions tests/PKSim.Tests/Core/MoleculeMapperSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading.Tasks;
using FakeItEasy;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
Expand All @@ -22,8 +20,8 @@ public abstract class concern_for_MoleculeMapper : ContextSpecificationAsync<Mol
protected IndividualTransporter _transporter;
protected IndividualOtherProtein _otherProtein;
protected Molecule _snapshot;
private IParameter _enzymeParameter;
private Parameter _enzymeParameterSnapshot;
private IParameter _enzymeGlobalParameter;
protected Parameter _enzymeGlobalParameterSnapshot;
private MoleculeExpressionContainer _expressionContainer1;
protected IParameter _relativeExpressionParameter1;
private IParameter _relativeExpressionParameterNotSet;
Expand All @@ -45,15 +43,15 @@ public abstract class concern_for_MoleculeMapper : ContextSpecificationAsync<Mol
protected override Task Context()
{
_parameterMapper = A.Fake<ParameterMapper>();
_expressionContainerMapper= A.Fake<ExpressionContainerMapper>();
_expressionContainerMapper = A.Fake<ExpressionContainerMapper>();
_executionContext = A.Fake<IExecutionContext>();
_individualMoleculeFactoryResolver = A.Fake<IIndividualMoleculeFactoryResolver>();
_ontogenyMapper= A.Fake<OntogenyMapper>();
_ontogenyTask= A.Fake<IOntogenyTask<Individual>>();
_individualMoleculeParametersTask= A.Fake<IMoleculeParameterTask>();
_ontogenyMapper = A.Fake<OntogenyMapper>();
_ontogenyTask = A.Fake<IOntogenyTask<Individual>>();
_individualMoleculeParametersTask = A.Fake<IMoleculeParameterTask>();

sut = new MoleculeMapper(_parameterMapper,_expressionContainerMapper,
_ontogenyMapper,_individualMoleculeFactoryResolver, _executionContext, _ontogenyTask,_individualMoleculeParametersTask);
sut = new MoleculeMapper(_parameterMapper, _expressionContainerMapper,
_ontogenyMapper, _individualMoleculeFactoryResolver, _executionContext, _ontogenyTask, _individualMoleculeParametersTask);

_ontogeny = new DatabaseOntogeny
{
Expand All @@ -63,30 +61,30 @@ protected override Task Context()
_enzyme = new IndividualEnzyme
{
Name = "Enzyme",
Description = "Hellp",
Description = "Help",
Ontogeny = _ontogeny,
};

_transporter = new IndividualTransporter
{
Name = "Transporter",
Description = "Hellp"
Description = "Help"
};

_otherProtein = new IndividualOtherProtein
{
Name = "OtherProtein",
Description = "Hellp"
Description = "Help"
};

_enzymeParameter = DomainHelperForSpecs.ConstantParameterWithValue(5).WithName("HalfLife");
_enzymeParameterSnapshot = new Parameter();
_enzymeGlobalParameter = DomainHelperForSpecs.ConstantParameterWithValue(5, isDefault: true).WithName(CoreConstants.Parameters.HALF_LIFE_LIVER);
_enzymeGlobalParameterSnapshot = new Parameter();

A.CallTo(() => _parameterMapper.MapToSnapshot(_enzymeParameter)).Returns(_enzymeParameterSnapshot);
A.CallTo(() => _parameterMapper.MapToSnapshot(_enzymeGlobalParameter)).Returns(_enzymeGlobalParameterSnapshot);

_expressionContainer1 = new MoleculeExpressionContainer {Name = "Exp Container1"};
_expressionContainer2 = new MoleculeExpressionContainer { Name = "Exp Container2"};
_enzyme.AddChildren(_expressionContainer1, _expressionContainer2);
_expressionContainer2 = new MoleculeExpressionContainer {Name = "Exp Container2"};
_enzyme.AddChildren(_expressionContainer1, _expressionContainer2, _enzymeGlobalParameter);

_relativeExpressionParameter1 = DomainHelperForSpecs.ConstantParameterWithValue(0.5).WithName(CoreConstants.Parameters.REL_EXP);
_relativeExpressionParameterNorm1 = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName(CoreConstants.Parameters.REL_EXP_NORM);
Expand All @@ -106,7 +104,7 @@ protected override Task Context()

_snapshotOntogeny = new Snapshots.Ontogeny();
A.CallTo(() => _ontogenyMapper.MapToSnapshot(_ontogeny)).Returns(_snapshotOntogeny);
_individual =new Individual();
_individual = new Individual();

return _completed;
}
Expand All @@ -126,7 +124,6 @@ public void should_return_a_snapshot_having_the_expected_properties_set_for_enzy
_snapshot.Description.ShouldBeEqualTo(_enzyme.Description);
}


[Observation]
public void should_have_saved_the_relative_expression_parameters_values_that_are_set()
{
Expand All @@ -147,6 +144,12 @@ public void should_have_saved_the_ontogeny_of_the_molecule()
{
_snapshot.Ontogeny.ShouldBeEqualTo(_snapshotOntogeny);
}

[Observation]
public void should_have_saved_the_global_parameters_of_the_molecule_even_if_they_were_not_changed_by_the_user()
{
_snapshot.Parameters.ShouldContain(_enzymeGlobalParameterSnapshot);
}
}

public class When_mapping_an_individual_transporter_to_snapshot : concern_for_MoleculeMapper
Expand All @@ -173,7 +176,7 @@ public void should_have_saved_transporter_specific_properties()
}
}

public class When_mapping_a_valid_enzyme_molecule_snahpshot_to_a_molecule : concern_for_MoleculeMapper
public class When_mapping_a_valid_enzyme_molecule_snapshot_to_a_molecule : concern_for_MoleculeMapper
{
private IndividualEnzyme _newMolecule;

Expand Down Expand Up @@ -236,7 +239,6 @@ public void should_have_restored_the_ontogeny()
}
}


public class When_mapping_a_valid_transporter_molecule_snahpshot_to_a_molecule : concern_for_MoleculeMapper
{
private IndividualTransporter _newTransporter;
Expand Down

0 comments on commit 62a3e72

Please sign in to comment.