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

Fixes #2260 - including "Global" PK-Parameters into the box-plot/scatter plot #2359

Merged
merged 4 commits into from
Oct 18, 2022

Conversation

rwmcintosh
Copy link
Member

No description provided.

@@ -59,7 +59,7 @@ private PopulationAnalysisPKParameterField createFieldFrom(QuantityPKParameter p
{
var quantity = _allQuantities[pkParameter.QuantityPath];
if (quantity == null)
return null;
return _populationAnalysisFieldFactory.CreateFor(pkParameter, QuantityType.Drug | QuantityType.Observer, quantityDisplayPath);
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure here. Clearly the quantity is not going to be found in the _allQuantities cache. But I'm not sure how get around this. Should there be additional values added int _allQuantities?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is ok but this requires a comment explaining that this parameter is not found because it is a global PK Parameter (can we actually check if this is one?). It cil;d also be the the quantity was removed somehow (thinking about mobi models imported etc..)

}

private GlobalPKAnalysis calculateGlobalPKAnalysisFor(Simulation simulation)
private IContainer calculateGlobalPKAnalysisFor(Simulation simulation, Compound compound, DataColumn peripheralVenousBloodCurve, DataColumn venousBloodCurve, PKCalculationOptions options)
Copy link
Member Author

Choose a reason for hiding this comment

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

This method is now called per compound so that it was easier to do the body weight scaling. The content should be the same otherwise.

@@ -29,7 +30,7 @@ public abstract class concern_for_GlobalPKAnalysisTask : ContextSpecification<IG
private IVSSCalculator _vssCalculator;
protected DataColumn _peripheralVenousBloodPlasma;
protected DataColumn _venousBloodPlasma;
protected IndividualSimulation _simulation;
Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored this test a bit because the base abstract class was setting up everything for an individual simulation, then the population_based was subclassing that and adding some population simulations. When I wrote my tests, I couldn't figure out why they were failing. The assertions were using the wrong simulation!

@rwmcintosh rwmcintosh self-assigned this Oct 5, 2022
@rwmcintosh rwmcintosh marked this pull request as ready for review October 5, 2022 20:20
return medianAggregateDataColumns(VenousBloodColumns(compoundName));
}

public IReadOnlyList<DataColumn> VenousBloodColumns(string compoundName)
Copy link
Member

Choose a reason for hiding this comment

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

why is this public?

return medianAggregateDataColumns(PeripheralVenousBloodColumns(compoundName));
}

public IReadOnlyList<DataColumn> PeripheralVenousBloodColumns(string compoundName)
Copy link
Member

Choose a reason for hiding this comment

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

why is this public?

Copy link
Member Author

Choose a reason for hiding this comment

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

GlobalPKAnalysisTask needs to get access to all the columns for PeripheralVenousBlood and VenousBlood

@@ -20,7 +20,7 @@ protected override void Context()
public class When_checking_if_the_simulation_comparison_tree_node_context_menu_factory_can_create_a_context_menu_for_a_given_node : concern_for_SimulationComparisonTreeNodeContextMenuFactory
{
[Observation]
public void shouldu_return_true_if_the_node_is_a_classifiable_comparision_node()
public void should_return_true_if_the_node_is_a_classifiable_comparision_node()
Copy link
Member

Choose a reason for hiding this comment

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

still a typo lol comparision => comaprison

Copy link
Member Author

Choose a reason for hiding this comment

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

There are a few instances of that. I'll fix them all, but one is in a database query that I won't change.

migrateTo5_3

Copy link
Member

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

on going review. One big comment already

src/PKSim.Assets/PKSimConstants.cs Show resolved Hide resolved
private IReadOnlyList<DataColumn> drugColumnFor(string organ, string compartment, string columnName, string compoundName)
private DataColumn drugColumnForIndividual(string organ, string compartment, string columnName, string compoundName, int individualId)
{
return columnsFor(Results.IndividualResultsAsArray().FirstOrDefault(result => result.IndividualId == individualId), organ, compartment, columnName, compoundName);
Copy link
Member

Choose a reason for hiding this comment

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

There has to be away to access results by Id other than this? This looks very odd to me/.Plus the array conversion etc ..

Copy link
Member Author

Choose a reason for hiding this comment

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

Results.ResultsFor(individualId) :) Nice.

@@ -330,5 +337,15 @@ private DataColumn columnsFor(IndividualResults results, string organ, string co
Values = column.Values
};
}

public DataColumn VenousBloodColumnForIndividual(int individualId, string compoundName)
Copy link
Member

Choose a reason for hiding this comment

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

do they still need to be public?

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 are using that from PKAnalysesTask, or what do you mean? Do we need this to be a datacolumn at all? And can we work from the results directly?

Copy link
Member

Choose a reason for hiding this comment

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

just wondering if we need tthis sutff outside of the class. But we do. I wasn't sure

globalPKAnalysis.Add(calculateGlobalPKParameters(populationSimulation, individualId, compoundName, options, globalPKAnalysis));
});

mapQuantityPKParametersFromIndividualGlobalPKAnalyses(globalPKAnalysesForIndividuals.ToList()).Each(x => analyses.AddPKAnalysis(x));
Copy link
Member

Choose a reason for hiding this comment

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

why the ToList. It's already an enumerable
globalPKAnalysesForIndividuals.Each(analyses.AddPKAnalysis)

Copy link
Member

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

Looking very good. Just a few minor comments


var simulation = allSimulations[0];

var globalPKAnalysis = new GlobalPKAnalysis();
Copy link
Member

Choose a reason for hiding this comment

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

initialize right at the beginnign and return on line 155. Otherwise, you are sometimes initializing sometime returning. Not consistent (*with line 162)

var peripheralVenousBloodColumn = simulation.PeripheralVenousBloodColumnForIndividual(individualId, moleculeName);
var venousBloodColumn = simulation.VenousBloodColumnForIndividual(individualId, moleculeName);

return calculateGlobalPKAnalysisFor(simulation, simulation.Compounds.FirstOrDefault(x => string.Equals(x.Name, moleculeName)), peripheralVenousBloodColumn, venousBloodColumn, calculationOptions);
Copy link
Member

Choose a reason for hiding this comment

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

FindByName or even maybe a method CompoundByName r sthg? but the first one for sure we have as ExtMethod


private static GlobalPKAnalysis globalPkAnalysisForIndividual(ICache<int, GlobalPKAnalysis> globalPKAnalysesForIndividuals, int individualId)
{
GlobalPKAnalysis globalPKAnalysis;
Copy link
Member

Choose a reason for hiding this comment

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

There is something unpleasant about this code. It is a mix of two approaches
I would suggest to do either

1

         if (globalPKAnalysesForIndividuals.Keys.Contains(individualId))
                return globalPKAnalysesForIndividuals[individualId];
         
            globalPKAnalysesForIndividuals[individualId] =  new GlobalPKAnalysis();;
            return globalPKAnalysesForIndividuals[individualId];

or

         if (!globalPKAnalysesForIndividuals.Keys.Contains(individualId))
               globalPKAnalysesForIndividuals[individualId] = new GlobalPKAnalysis();;

         return globalPKAnalysesForIndividuals[individualId];

// use the first in series as a template to retrieve from all individual results.
// The list of parameters should be identical for all the individual global analyses.
var aPKAnalysis = globalIndividualPKParameterList.FirstOrDefault();
aPKAnalysis?.AllPKParameters.GroupBy(pkParameter => pkParameter.EntityPath().ToPathArray().MoleculeName()).Each(group =>
Copy link
Member

Choose a reason for hiding this comment

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

pkParameter.EntityPath().ToPathArray().MoleculeName()

That's ugly too. Let's create a method somewhere to extract MoleculeName for a pkParameter . There has to be something doing it somewhere too

private static QuantityPKParameter quantityPKParameterFor(IReadOnlyList<GlobalPKAnalysis> globalIndividualPKParameterList, IParameter pKParameter, string quantityPath)
{
var pKValuesForPKParameter = globalIndividualPKParameterList.SelectMany(globalPKAnalysisForAnIndividual => globalPKAnalysisForAnIndividual.AllPKParameters.Where(x => pathsEqual(x, pKParameter))).ToList();
var quantityPKParameter = new QuantityPKParameter { Dimension = pKValuesForPKParameter.First().Dimension, Name = pKValuesForPKParameter.First().Name, QuantityPath = quantityPath };
Copy link
Member

Choose a reason for hiding this comment

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

are we sure here that there will be at least one? (first)

_entityPathResolver = entityPathResolver;
}

public void UpdateBodyWeightForIndividual(PopulationSimulation populationSimulation, int individualId)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why this was moved out of the PK Stuff? Because you are doing line 24 to 26 now for EAch individual as opposed to one time.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason for it was that originally I was reproducing the scaling logic in a second location. I think it makes sense to put it back now.

@@ -69,6 +69,16 @@ private void createAvailableQuantitiesListBasedOn(IPopulationDataCollector popul
{
_allPKParameters.Clear();
_allPKParameters.AddRange(_entitiesInContainerRetriever.OutputsFrom(populationDataCollector).SelectMany(availablePKParametersFor));

populationDataCollector.Compounds.Select(x => x.Name).Each(compoundName =>
Copy link
Member

Choose a reason for hiding this comment

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

Extension method AllNames

@@ -59,7 +59,7 @@ private PopulationAnalysisPKParameterField createFieldFrom(QuantityPKParameter p
{
var quantity = _allQuantities[pkParameter.QuantityPath];
if (quantity == null)
return null;
return _populationAnalysisFieldFactory.CreateFor(pkParameter, QuantityType.Drug | QuantityType.Observer, quantityDisplayPath);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is ok but this requires a comment explaining that this parameter is not found because it is a global PK Parameter (can we actually check if this is one?). It cil;d also be the the quantity was removed somehow (thinking about mobi models imported etc..)

@msevestre msevestre merged commit 59bf200 into develop Oct 18, 2022
@msevestre msevestre deleted the 2260-include-global-pk-parameters-in-pop-analyses branch October 18, 2022 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants