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

2615 overriding ref conc and applying hi should use the updated refconc #2620

Merged
Show file tree
Hide file tree
Changes from 5 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
Binary file modified src/Db/Dump/sqlite3.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public override IndividualBuildingBlock MapFrom(Individual individual)
buildingBlock.Icon = individual.Icon;

addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.DiseaseState, individual.OriginData.DiseaseState?.DisplayName);
individual.OriginData.DiseaseStateParameters.Each(x => addOriginDataToBuildingBlock(buildingBlock, x.Name, x));
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Species, individual.Species?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Gender, individual.OriginData.Gender?.DisplayName);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Age, individual.OriginData.Age);
Expand Down Expand Up @@ -124,17 +125,14 @@ private void addOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock,
addOriginDataToBuildingBlock(buildingBlock, keyForOriginDataParameter(key, parameter), $"{parameter.Value} {parameter.Unit}");
}

private string keyForOriginDataParameter(string key, OriginDataParameter parameter)
{
return string.IsNullOrEmpty(parameter.Name) ? key : parameter.Name;
}

private void addOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock, string key, string value)
{
if (string.IsNullOrEmpty(value))
return;

buildingBlock.OriginData.Add(new ExtendedProperty<string> {Name = key, Value = value});
}

private string keyForOriginDataParameter(string key, OriginDataParameter parameter) => string.IsNullOrEmpty(parameter.Name) ? key : parameter.Name;
}
}
6 changes: 1 addition & 5 deletions src/PKSim.Core/Mappers/PathAndValueBuildingBlockMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using OSPSuite.Utility;
using OSPSuite.Utility.Extensions;
using PKSim.Core.Model;
using PKSim.Core.Model.Extensions;
using IFormulaFactory = PKSim.Core.Model.IFormulaFactory;

namespace PKSim.Core.Mappers
Expand Down Expand Up @@ -126,10 +125,7 @@ private IFormula retrieveTemplateFormulaFromCache(IParameter parameter, TPKSimBu

protected abstract IFormula TemplateFormulaFor(IParameter parameter, IFormulaCache formulaCache, TPKSimBuildingBlock pkSimBuildingBlock);

private static double getParameterValue(IParameter parameter)
{
return parameter.TryGetValue().value;
}
private static double getParameterValue(IParameter parameter) => parameter.TryGetValue().value;

protected void MapAllParameters(TPKSimBuildingBlock sourcePKSimBuildingBlock, TBuildingBlock buildingBlock)
{
Expand Down
4 changes: 3 additions & 1 deletion src/PKSim.Core/Model/ExpressionProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public Individual Individual

public virtual Species Species => Individual?.Species;

public virtual DiseaseState DiseaseState => Individual?.OriginData?.DiseaseState;

public ExpressionProfile() : base(PKSimBuildingBlockType.ExpressionProfile)
{
}

public override IReadOnlyList<T> GetAllChildren<T>()
{
return Individual.GetAllChildren<T>();
Expand Down
10 changes: 5 additions & 5 deletions src/PKSim.Core/Model/IndividualFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class IndividualFactory : IIndividualFactory
private readonly IReportGenerator _reportGenerator;
private readonly IMoleculeOntogenyVariabilityUpdater _ontogenyVariabilityUpdater;
private readonly IGenderRepository _genderRepository;
private readonly IDiseaseStateImplementationFactory _diseaseStateImplementationFactory;
private readonly IDiseaseStateImplementationRepository _diseaseStateImplementationRepository;

public IndividualFactory(
IIndividualModelTask individualModelTask,
Expand All @@ -40,7 +40,7 @@ public IndividualFactory(
IReportGenerator reportGenerator,
IMoleculeOntogenyVariabilityUpdater ontogenyVariabilityUpdater,
IGenderRepository genderRepository,
IDiseaseStateImplementationFactory diseaseStateImplementationFactory)
IDiseaseStateImplementationRepository diseaseStateImplementationRepository)
{
_individualModelTask = individualModelTask;
_objectBaseFactory = objectBaseFactory;
Expand All @@ -50,7 +50,7 @@ public IndividualFactory(
_reportGenerator = reportGenerator;
_ontogenyVariabilityUpdater = ontogenyVariabilityUpdater;
_genderRepository = genderRepository;
_diseaseStateImplementationFactory = diseaseStateImplementationFactory;
_diseaseStateImplementationRepository = diseaseStateImplementationRepository;
}

public Individual CreateAndOptimizeFor(OriginData originData, int? seed = null)
Expand All @@ -63,7 +63,7 @@ public Individual CreateAndOptimizeFor(OriginData originData, int? seed = null)
_createIndividualAlgorithm.Optimize(individual);

//Apply disease states if required
var diseaseStateImplementation = _diseaseStateImplementationFactory.CreateFor(individual);
var diseaseStateImplementation = _diseaseStateImplementationRepository.FindFor(individual);
diseaseStateImplementation.ApplyTo(individual);

validate(individual);
Expand Down Expand Up @@ -138,7 +138,7 @@ private void validate(Individual individual)
throw new CannotCreateIndividualWithConstraintsException(_reportGenerator.StringReportFor(individual.OriginData));

//Apply disease states if required
var diseaseStateImplementation = _diseaseStateImplementationFactory.CreateFor(individual);
var diseaseStateImplementation = _diseaseStateImplementationRepository.FindFor(individual);
//This will throw if not valid
diseaseStateImplementation.Validate(individual.OriginData);
}
Expand Down
10 changes: 5 additions & 5 deletions src/PKSim.Core/Model/RandomPopulationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class RandomPopulationFactory : IRandomPopulationFactory
private readonly IReportGenerator _reportGenerator;
private readonly IMoleculeParameterVariabilityCreator _moleculeParameterVariabilityCreator;
private readonly IMoleculeOntogenyVariabilityUpdater _moleculeOntogenyVariabilityUpdater;
private readonly IDiseaseStateImplementationFactory _diseaseStateImplementationFactory;
private readonly IDiseaseStateImplementationRepository _diseaseStateImplementationRepository;
private Queue<Gender> _genderQueue;
private const int _maxIterations = 100;

Expand All @@ -63,7 +63,7 @@ public RandomPopulationFactory(
IReportGenerator reportGenerator,
IMoleculeParameterVariabilityCreator moleculeParameterVariabilityCreator,
IMoleculeOntogenyVariabilityUpdater moleculeOntogenyVariabilityUpdater,
IDiseaseStateImplementationFactory diseaseStateImplementationFactory)
IDiseaseStateImplementationRepository diseaseStateImplementationRepository)
{
_objectBaseFactory = objectBaseFactory;
_progressManager = progressManager;
Expand All @@ -76,7 +76,7 @@ public RandomPopulationFactory(
_reportGenerator = reportGenerator;
_moleculeParameterVariabilityCreator = moleculeParameterVariabilityCreator;
_moleculeOntogenyVariabilityUpdater = moleculeOntogenyVariabilityUpdater;
_diseaseStateImplementationFactory = diseaseStateImplementationFactory;
_diseaseStateImplementationRepository = diseaseStateImplementationRepository;
}

public Task<RandomPopulation> CreateFor(RandomPopulationSettings populationSettings, CancellationToken cancellationToken, int? seed = null, bool addMoleculeParametersVariability = true)
Expand All @@ -90,7 +90,7 @@ public Task<RandomPopulation> CreateFor(RandomPopulationSettings populationSetti
fllUpGenderQueueBasedOn(populationSettings);
progressUpdater.Initialize(populationSettings.NumberOfIndividuals, PKSimConstants.UI.CreatingPopulation);

var diseaseStateImplementation = _diseaseStateImplementationFactory.CreateFor(populationSettings.BaseIndividual);
var diseaseStateImplementation = _diseaseStateImplementationRepository.FindFor(populationSettings.BaseIndividual);
//the base individual is used to retrieve the default values.
var baseIndividual = diseaseStateImplementation.CreateBaseIndividualForPopulation(populationSettings.BaseIndividual);

Expand Down Expand Up @@ -242,7 +242,7 @@ private void perturbate(Individual currentIndividual, RandomPopulationSettings p
{
bool success = true;
var originData = currentIndividual.OriginData;
var diseaseStateImplementation = _diseaseStateImplementationFactory.CreateFor(originData.DiseaseState);
var diseaseStateImplementation = _diseaseStateImplementationRepository.FindFor(originData.DiseaseState);
uint numberOfTry = 0;
do
{
Expand Down
5 changes: 4 additions & 1 deletion src/PKSim.Core/Repositories/IDiseaseStateRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using OSPSuite.Core.Domain;
using OSPSuite.Utility.Collections;
using PKSim.Core.Model;

Expand All @@ -7,6 +9,7 @@ namespace PKSim.Core.Repositories
public interface IDiseaseStateRepository : IStartableRepository<DiseaseState>
{
IReadOnlyList<DiseaseState> AllFor(SpeciesPopulation population);
IReadOnlyList<DiseaseState> AllForExpressionProfile(Species species, QuantityType moleculeType);

DiseaseState HealthyState { get; }
}
Expand Down
5 changes: 0 additions & 5 deletions src/PKSim.Core/Services/CKDDiseaseStateImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ public override (bool isValid, string error) IsValid(OriginData originData)
return (false, PKSimConstants.Error.CKDOnlyAvailableForAdult);
}

public override void ApplyTo(Individual individual, IndividualMolecule individualMolecule)
{
//nothing to do here
}

protected override IReadOnlyList<IParameter> ParameterChangedByDiseaseStateAsList(Individual individual)
{
var (hct, gfrSpec, kidneyVolume, kidneySpecificBloodFlowRate, fatVolume, plasmaProteinScaleFactorParameter, smallIntestinalTransitTime, gastricEmptyingTime) = parametersChangedByCKDAlgorithm(individual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

namespace PKSim.Core.Services
{
public class DiseaseStateImplementationFactory : IDiseaseStateImplementationFactory
public class DiseaseStateImplementationRepository : IDiseaseStateImplementationRepository
{
private readonly IRepository<IDiseaseStateImplementation> _diseaseStateImplementations;

public DiseaseStateImplementationFactory(IRepository<IDiseaseStateImplementation> diseaseStateImplementations)
public DiseaseStateImplementationRepository(IRepository<IDiseaseStateImplementation> diseaseStateImplementations)
{
_diseaseStateImplementations = diseaseStateImplementations;
}

public IDiseaseStateImplementation CreateFor(DiseaseState diseaseState)
public IDiseaseStateImplementation FindFor(DiseaseState diseaseState)
{
//We use all here to ensure that we get new implementations every single time
var implementation = _diseaseStateImplementations.All().SingleOrDefault(x => x.IsSatisfiedBy(diseaseState));
return implementation ?? new HealthyDiseaseStateImplementation();
}

public IDiseaseStateImplementation CreateFor(Individual individual) => CreateFor(individual.OriginData.DiseaseState);
public IDiseaseStateImplementation FindFor(Individual individual) => FindFor(individual.OriginData.DiseaseState);
}
}
16 changes: 3 additions & 13 deletions src/PKSim.Core/Services/ExpressionProfileUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class ExpressionProfileUpdater : IExpressionProfileUpdater
private readonly ILazyLoadTask _lazyLoadTask;
private readonly IParameterIdUpdater _parameterIdUpdater;
private readonly IExecutionContext _executionContext;
private readonly IDiseaseStateImplementationFactory _diseaseStateImplementationFactory;
private readonly IDiseaseStateImplementationRepository _diseaseStateImplementationRepository;

public ExpressionProfileUpdater(
IParameterSetUpdater parameterSetUpdater,
Expand All @@ -76,7 +76,7 @@ public ExpressionProfileUpdater(
ILazyLoadTask lazyLoadTask,
IParameterIdUpdater parameterIdUpdater,
IExecutionContext executionContext,
IDiseaseStateImplementationFactory diseaseStateImplementationFactory)
IDiseaseStateImplementationRepository diseaseStateImplementationRepository)
{
_parameterSetUpdater = parameterSetUpdater;
_containerTask = containerTask;
Expand All @@ -86,7 +86,7 @@ public ExpressionProfileUpdater(
_lazyLoadTask = lazyLoadTask;
_parameterIdUpdater = parameterIdUpdater;
_executionContext = executionContext;
_diseaseStateImplementationFactory = diseaseStateImplementationFactory;
_diseaseStateImplementationRepository = diseaseStateImplementationRepository;
}

public ICommand UpdateExpressionFromQuery(ExpressionProfile expressionProfile, QueryExpressionResults queryResults)
Expand Down Expand Up @@ -144,16 +144,6 @@ public void SynchroniseSimulationSubjectWithExpressionProfile(ISimulationSubject
var (sourceMolecule, sourceIndividual) = expressionProfile;
// ExpressionProfile => SimulationSubject, we want to make sure that the parameters in simulation subject are linked to their expression profile origin parameters
synchronizeExpressionProfiles(sourceMolecule, sourceIndividual, moleculeInIndividual, simulationSubject, updateParameterOriginId: true);

//Once the synchronization was performed, apply changes to simulation subject molecules based on disease state
updateMoleculeParametersForDiseaseState(simulationSubject, moleculeInIndividual);
}

private void updateMoleculeParametersForDiseaseState(ISimulationSubject simulationSubject, IndividualMolecule moleculeInIndividual)
msevestre marked this conversation as resolved.
Show resolved Hide resolved
{
var individual = simulationSubject.Individual;
var diseaseStateImplementation = _diseaseStateImplementationFactory.CreateFor(individual);
diseaseStateImplementation.ApplyTo(individual, moleculeInIndividual);
}

public void SynchronizeExpressionProfileWithSimulationSubject(ExpressionProfile expressionProfile, ISimulationSubject simulationSubject)
Expand Down
Loading