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

2113 property molecule psv #2117

Merged
merged 3 commits into from
Mar 17, 2022
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
31 changes: 4 additions & 27 deletions src/Db/Diff/PKSimDB_diff.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
UPDATE tab_calculation_method_rates SET formula='f_int > 0 ? RC * rel_exp_org * f_exp_org_basolateral * 1 / f_int : 0' WHERE calculation_method='ExpressionParameters' AND formula_rate='InitialConcentrationInterstitial_Transporter';
CREATE TABLE tab_container_parameter_descriptor_conditions (container_id bigint NOT NULL, container_type text NOT NULL, container_name text NOT NULL, parameter_name text NOT NULL, tag text NOT NULL CONSTRAINT tab_container_parameter_descriptor_conditions_tab_tags_tag_fk REFERENCES tab_tags ON UPDATE CASCADE ON DELETE CASCADE, condition text NOT NULL CONSTRAINT tab_container_parameter_descriptor_conditions_tab_criteria_conditions_condition_fk REFERENCES tab_criteria_conditions ON UPDATE CASCADE ON DELETE CASCADE, operator TEXT DEFAULT "And" NOT NULL, CONSTRAINT tab_container_parameter_descriptor_conditions_tab_container_parameters_container_id_container_type_container_name_parameter_name_fk FOREIGN KEY (container_id, container_type, container_name, parameter_name) REFERENCES tab_container_parameters ON UPDATE CASCADE ON DELETE CASCADE);
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(1,5015,'GENERAL','PROTEIN','Fraction expressed interstitial','Interstitial','Has','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(2,5015,'GENERAL','PROTEIN','Fraction expressed intracellular','Intracellular','Has','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(3,5941,'GENERAL','TRANSPORTER','Fraction expressed at blood brain barrier','Brain','InContainer','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(4,5941,'GENERAL','TRANSPORTER','Fraction expressed at blood brain barrier','Plasma','Has','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(5,5941,'GENERAL','TRANSPORTER','Fraction expressed brain tissue','Brain','InContainer','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(6,5941,'GENERAL','TRANSPORTER','Fraction expressed brain tissue','Interstitial','Has','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(7,5015,'GENERAL','PROTEIN','Relative expression','Intracellular','Has','Or');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(8,5015,'GENERAL','PROTEIN','Relative expression','LumenSegment','Has','Or');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(9,5941,'GENERAL','TRANSPORTER','Relative expression','Intracellular','Has','Or');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(10,5941,'GENERAL','TRANSPORTER','Relative expression','LumenSegment','Has','Or');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(11,5941,'GENERAL','TRANSPORTER','Fraction expressed basolateral','Interstitial','Has','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(12,5941,'GENERAL','TRANSPORTER','Fraction expressed apical','Intracellular','Has','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(13,5941,'GENERAL','TRANSPORTER','Fraction expressed basolateral','Brain','NotInContainer','And');
INSERT INTO tab_container_parameter_descriptor_conditions(rowid,container_id,container_type,container_name,parameter_name,tag,condition,operator) VALUES(14,5941,'GENERAL','TRANSPORTER','Fraction expressed apical','Brain','NotInContainer','And');
UPDATE tab_container_parameter_rates SET formula_rate='PARAM_f_exp_interstitial' WHERE container_id=5015 AND container_type='GENERAL' AND container_name='PROTEIN' AND parameter_name='Fraction expressed interstitial' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='One_Rate' WHERE container_id=5015 AND container_type='GENERAL' AND container_name='PROTEIN' AND parameter_name='Fraction expressed intracellular' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='Zero_Rate' WHERE container_id=5015 AND container_type='GENERAL' AND container_name='PROTEIN' AND parameter_name='Relative expression' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='Zero_Rate' WHERE container_id=5941 AND container_type='GENERAL' AND container_name='TRANSPORTER' AND parameter_name='Fraction expressed apical' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='One_Rate' WHERE container_id=5941 AND container_type='GENERAL' AND container_name='TRANSPORTER' AND parameter_name='Fraction expressed at blood brain barrier' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='PARAM_f_exp_basolateral' WHERE container_id=5941 AND container_type='GENERAL' AND container_name='TRANSPORTER' AND parameter_name='Fraction expressed basolateral' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='PARAM_f_exp_brn_tissue' WHERE container_id=5941 AND container_type='GENERAL' AND container_name='TRANSPORTER' AND parameter_name='Fraction expressed brain tissue' AND calculation_method='ExpressionParameters';
UPDATE tab_container_parameter_rates SET formula_rate='Zero_Rate' WHERE container_id=5941 AND container_type='GENERAL' AND container_name='TRANSPORTER' AND parameter_name='Relative expression' AND calculation_method='ExpressionParameters';
UPDATE tab_rate_generic_parameters SET alias='f_exp_org_basolateral' WHERE calculation_method='ExpressionParameters' AND formula_rate='InitialConcentrationInterstitial_Transporter' AND path_id=139 AND parameter_name='Fraction expressed basolateral';
INSERT INTO tab_rate_generic_parameters(calculation_method,formula_rate,path_id,parameter_name,alias) VALUES('ExpressionParameters','PARAM_f_exp_bc_membrane',139,'Fraction expressed in blood cells','f_exp_bc_cell');
DELETE FROM tab_rate_generic_parameters WHERE calculation_method='ExpressionParameters' AND formula_rate='PARAM_f_exp_bc_membrane' AND path_id=240 AND parameter_name='Fraction expressed in blood cells';
INSERT INTO tab_rate_generic_parameters(calculation_method,formula_rate,path_id,parameter_name,alias) VALUES('ExpressionParameters','PARAM_f_exp_vasc_tissue_side',139,'Fraction expressed in endosomes','f_exp_vasend_endosomes');
INSERT INTO tab_rate_generic_parameters(calculation_method,formula_rate,path_id,parameter_name,alias) VALUES('ExpressionParameters','PARAM_f_exp_vasc_tissue_side',139,'Fraction expressed on plasma-side membrane of vascular endothelium','f_exp_vasend_plasma');
Copy link
Member Author

Choose a reason for hiding this comment

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

.. instead of MOLECULE

DELETE FROM tab_rate_generic_parameters WHERE calculation_method='ExpressionParameters' AND formula_rate='PARAM_f_exp_vasc_tissue_side' AND path_id=240 AND parameter_name='Fraction expressed in endosomes';
DELETE FROM tab_rate_generic_parameters WHERE calculation_method='ExpressionParameters' AND formula_rate='PARAM_f_exp_vasc_tissue_side' AND path_id=240 AND parameter_name='Fraction expressed on plasma-side membrane of vascular endothelium';
4 changes: 2 additions & 2 deletions src/Db/Dump/PKSimDB_dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91552,8 +91552,8 @@ INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','InitialCo
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','InitialConcentrationEndosome',240,'Relative expression in vascular endothelium','rel_exp_vasend');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','InitialConcentrationEndosome',240,'Fraction expressed in endosomes','f_exp_vasend_endosomes');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','PARAM_f_exp_bc_membrane',139,'Fraction expressed in blood cells','f_exp_bc_cell');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','PARAM_f_exp_vasc_tissue_side',240,'Fraction expressed on plasma-side membrane of vascular endothelium','f_exp_vasend_plasma');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','PARAM_f_exp_vasc_tissue_side',240,'Fraction expressed in endosomes','f_exp_vasend_endosomes');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','PARAM_f_exp_vasc_tissue_side',139,'Fraction expressed on plasma-side membrane of vascular endothelium','f_exp_vasend_plasma');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','PARAM_f_exp_vasc_tissue_side',139,'Fraction expressed in endosomes','f_exp_vasend_endosomes');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','InitialConcentrationLumen',240,'Reference concentration','RC');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','InitialConcentrationLumen',139,'Relative expression','rel_exp_org');
INSERT INTO tab_rate_generic_parameters VALUES('ExpressionParameters','PARAM_f_exp_interstitial',4902,'Fraction expressed intracellular','f_exp_org_cell');
Expand Down
Binary file modified src/Db/PKSimDB.sqlite
Binary file not shown.
20 changes: 15 additions & 5 deletions src/PKSim.Core/Services/PKSimParameterStartValuesCreator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Diagnostics;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Extensions;
using PKSim.Core.Model;
using PKSim.Core.Model.Extensions;
using static PKSim.Core.CoreConstants.CalculationMethod;
using IFormulaFactory = PKSim.Core.Model.IFormulaFactory;

Expand Down Expand Up @@ -78,9 +79,9 @@ private bool isChangedSimulationParameter(IParameter parameter)

private void updateMoleculeParametersValues(IndividualMolecule molecule, Individual individual, Simulation simulation)
{
var allProteinParameters = individual.AllMoleculeParametersFor(molecule);
var allMoleculeParameters = individual.AllMoleculeParametersFor(molecule);
var modelConfiguration = simulation.ModelConfiguration;
allProteinParameters.Each(p => setParameter(p, modelConfiguration.ModelName == CoreConstants.Model.FOUR_COMP));
allMoleculeParameters.Each(p => setParameter(p, modelConfiguration.ModelName == CoreConstants.Model.FOUR_COMP));
}

private void setParameter(IParameter parameter, bool isSmallMolecule)
Expand All @@ -89,13 +90,16 @@ private void setParameter(IParameter parameter, bool isSmallMolecule)
if (parameter.HasAncestorNamed(CoreConstants.Compartment.ENDOSOME) && isSmallMolecule)
return;

var parameterStartValue = getOrCreateStartValueFor(parameter);
//We do not generate value for this parameter by default. Exit
var parameterStartValue = getStartValueFor(parameter);
Copy link
Member Author

Choose a reason for hiding this comment

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

We were adding entries for formula that are the same everywhere. Not generated by default in Core and it should not be added here either

if (parameterStartValue == null)
return;

if (parameter.Formula.IsExplicit())
{
var formula = _formulaFactory.RateFor(EXPRESSION_PARAMETERS, parameter.Formula.Name, _defaultStartValues.FormulaCache);
parameterStartValue.Formula = formula;
//There if a formula, make sure we use it. We set this flag to false to ensure that the formula will not be replaced with a constant formula
//There is a formula, make sure we use it. We set this flag to false to ensure that the formula will not be replaced with a constant formula
parameterStartValue.OverrideFormulaWithValue = false;
}

Expand Down Expand Up @@ -124,5 +128,11 @@ private IParameterStartValue getOrCreateStartValueFor(IParameter parameter)

return parameterStartValue;
}

private IParameterStartValue getStartValueFor(IParameter parameter)
{
var parameterPath = _entityPathResolver.ObjectPathFor(parameter);
return _defaultStartValues[parameterPath];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Linq;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Utility.Container;
using PKSim.Core.Services;
using PKSim.Infrastructure;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Container;
using OSPSuite.Utility.Extensions;
using PKSim.Core.Model;
using PKSim.Core.Repositories;
using PKSim.Core.Services;
using PKSim.Infrastructure;
using PKSim.Infrastructure.ProjectConverter;

namespace PKSim.IntegrationTests
{
Expand All @@ -16,13 +20,39 @@ public class When_creating_a_parameter_start_value_building_block_for_a_simulati
private IEntityPathResolver _entityPathResolver;
private IObjectPath _parameterPath;
private IParameterStartValuesBuildingBlock _psv;
private Individual _individual;
private Compound _compound;
private Protocol _protocol;
private IndividualMolecule _enzyme;
private PartialProcess _metabolizationProcess;

public override void GlobalContext()
{
base.GlobalContext();
_buildConfigurationTask = IoC.Resolve<IBuildConfigurationTask>();
_entityPathResolver = IoC.Resolve<IEntityPathResolver>();
_simulation = DomainFactoryForSpecs.CreateDefaultSimulation();
var enzymeFactory = IoC.Resolve<IIndividualEnzymeFactory>();
var compoundProcessRepository = IoC.Resolve<ICompoundProcessRepository>();
var cloneManager = IoC.Resolve<ICloneManager>();
_compound = DomainFactoryForSpecs.CreateStandardCompound();
_individual = DomainFactoryForSpecs.CreateStandardIndividual();
_protocol = DomainFactoryForSpecs.CreateStandardIVBolusProtocol();
_enzyme = enzymeFactory.AddMoleculeTo(_individual, "CYP").DowncastTo<IndividualEnzyme>();
_metabolizationProcess = cloneManager.Clone(compoundProcessRepository
.ProcessByName(CoreConstantsForSpecs.Process.METABOLIZATION_SPECIFIC_FIRST_ORDER).DowncastTo<PartialProcess>());
_metabolizationProcess.Name = "My Partial Process";
_metabolizationProcess.Parameter(ConverterConstants.Parameters.CLspec).Value = 15;
_compound.AddProcess(_metabolizationProcess);

_simulation = DomainFactoryForSpecs.CreateModelLessSimulationWith(_individual, _compound, _protocol)
.DowncastTo<IndividualSimulation>();

_simulation.CompoundPropertiesList.First()
.Processes
.MetabolizationSelection
.AddPartialProcessSelection(new EnzymaticProcessSelection {ProcessName = _metabolizationProcess.Name, MoleculeName = _enzyme.Name});

DomainFactoryForSpecs.AddModelToSimulation(_simulation);
}

protected override void Because()
Expand All @@ -40,5 +70,17 @@ public void should_have_created_one_entry_for_the_changed_parameter_in_the_param
_psv[_parameterPath].ShouldNotBeNull();
_psv[_parameterPath].StartValue.ShouldBeEqualTo(10);
}

[Observation]
public void should_have_not_created_entries_for_property_parameter_of_the_enzyme()
{
var propertyParameters = _enzyme.AllParameters().Where(x => x.BuildMode == ParameterBuildMode.Property).ToList();
propertyParameters.Count.ShouldBeGreaterThan(0);
propertyParameters.Each(x =>
{
var parameterPath = _entityPathResolver.ObjectPathFor(x);
_psv[parameterPath].ShouldBeNull();
Copy link
Member Author

Choose a reason for hiding this comment

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

do not add entries for property parameters (they should be excluded from psv)

});
}
}
}