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

2190 project conversion issue #2191

Merged
merged 2 commits into from
Apr 12, 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
10 changes: 7 additions & 3 deletions src/PKSim.Infrastructure/ProjectConverter/v11/Converter10to11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,16 @@ private void addEstimatedGFRParameterTo(Individual individual)

private void addExpressionProfilesUsedBySimulationSubjectToProject(ISimulationSubject simulationSubject)
{
var project = _projectRetriever.Current;
foreach (var molecule in simulationSubject.AllMolecules())
{
var defaultExpressionProfileName = CoreConstants.ContainerName.ExpressionProfileName(molecule.Name, simulationSubject.Species, simulationSubject.Name);

var expressionProfileName = _containerTask.CreateUniqueName(project.All<ExpressionProfile>(), defaultExpressionProfileName, canUseBaseName: true);
var expressionProfile = _expressionProfileFactory.Create(molecule.GetType(), simulationSubject.Species, molecule.Name);

//Make sure the name does not have our separator
expressionProfile.Category = simulationSubject.Name;
//Use a unique name in project
expressionProfile.Name = expressionProfileName;
_expressionProfileUpdater.SynchronizeExpressionProfileWithSimulationSubject(expressionProfile, simulationSubject);

//Some parameters are probably marked as FixedValue event thought they have not changed (Formula=>constant) due to change in
Expand All @@ -195,7 +199,7 @@ private void addExpressionProfilesUsedBySimulationSubjectToProject(ISimulationSu

//only add at the end once the expression profile has been updated
simulationSubject.AddExpressionProfile(expressionProfile);
_projectRetriever.Current.AddBuildingBlock(expressionProfile);
project.AddBuildingBlock(expressionProfile);
_registrationTask.Register(expressionProfile);
_eventPublisher.PublishEvent(new BuildingBlockAddedEvent(expressionProfile, _projectRetriever.Current));
}
Expand Down
34 changes: 34 additions & 0 deletions tests/PKSim.Tests/ProjectConverter/v11/Converter10to11Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public override void GlobalContext()
LoadProject("expression_v10");
_allPopulations = All<Population>();
_allIndividuals = All<Individual>();

_allPopulations.Each(Load);
_allIndividuals.Each(Load);
}
Expand Down Expand Up @@ -188,4 +189,37 @@ public void should_have_set_the_initial_concentration_parameter_to_not_variable_
allInitialConcentrationParameters.Each(x => x.CanBeVariedInPopulation.ShouldBeFalse());
}
}

public class When_converting_the_expression_v10_project_to_11_and_an_expression_profile_is_added_with_the_name_that_would_be_created_from_conversion : ContextWithLoadedProject<Converter10to11>
{
private Individual _ind;
private ExpressionProfile _existingExpressionProfile;

public override void GlobalContext()
{
base.GlobalContext();
LoadProject("expression_v10");
var individuals = All<Individual>();
_ind = individuals.FindByName("Ind");
}

protected override void Because()
{
//add an expression profile with the name
_existingExpressionProfile = DomainHelperForSpecs.CreateExpressionProfile<IndividualEnzyme>(_ind.Species.Name, "CYP3A4", _ind.Name);
Copy link
Member Author

Choose a reason for hiding this comment

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

@Yuri05 Adding first and then loading. This will also fix the issue when pop and ind had the same name..

_project.AddBuildingBlock(_existingExpressionProfile);

//now load to trigger conversion
Load(_ind);
}

[Observation]
public void should_have_created_an_expression_profile_named_differently()
{
_ind.Uses(_existingExpressionProfile).ShouldBeFalse();
var expressionProfile = FindByName<ExpressionProfile>($"{_existingExpressionProfile.Name} 1");
expressionProfile.ShouldNotBeNull();
_ind.Uses(expressionProfile).ShouldBeTrue();
}
}
}