public IEnumerable <PopulationPKAnalysis> CalculateFor(IPopulationDataCollector populationDataCollector, ChartData <TimeProfileXValue, TimeProfileYValue> timeProfileChartData) { var pkAnalyses = new List <PopulationPKAnalysis>(); if (timeProfileChartData == null) { return(pkAnalyses); // there are no analyses to calculate } var allColumns = timeProfileChartData.Panes.SelectMany(x => x.Curves).Select(x => new { curveData = x, column = columnFor(x, populationDataCollector) }) .Where(c => c.column != null) .Where(c => c.column.IsConcentration()); var columnsByMolecules = allColumns.GroupBy(x => x.column.MoleculeName()); foreach (var columnsByMolecule in columnsByMolecules) { var moleculeName = columnsByMolecule.Key; var options = _pkCalculationOptionsFactory.CreateFor(populationDataCollector, moleculeName); pkAnalyses.AddRange(columnsByMolecule.Select(pkAnalysisData => new PopulationPKAnalysis(pkAnalysisData.curveData, calculatePKFor(pkAnalysisData.column, moleculeName, options).PKAnalysis))); } return(pkAnalyses); }
protected virtual PopulationSimulationPKAnalyses CalculateFor(ISimulation simulation, int numberOfIndividuals, SimulationResults runResults, Action <int> performIndividualScalingAction) { _lazyLoadTask.Load(simulation); var popAnalyses = new PopulationSimulationPKAnalyses(); foreach (var selectedQuantityForMolecule in simulation.OutputSelections.GroupBy(moleculeNameFrom)) { var moleculeName = selectedQuantityForMolecule.Key; var pkCalculationOptions = _pkCalculationOptionsFactory.CreateFor(simulation, moleculeName); var allApplicationParameters = _pkCalculationOptionsFactory.AllApplicationParametersOrderedByStartTimeFor(simulation, moleculeName); foreach (var selectedQuantity in selectedQuantityForMolecule) { addPKParametersForOutput(simulation, numberOfIndividuals, runResults, performIndividualScalingAction, selectedQuantity, popAnalyses, moleculeName, pkCalculationOptions, allApplicationParameters); } } return(popAnalyses); }
public GlobalPKAnalysis CalculateGlobalPKAnalysisFor(IEnumerable <Simulation> simulations) { var globalPKAnalysis = new GlobalPKAnalysis(); var allSimulations = simulations.ToList(); if (allSimulations.Count != 1) { return(globalPKAnalysis); } var simulation = allSimulations[0] as IndividualSimulation; if (simulation == null) { return(globalPKAnalysis); } //one container per compound foreach (var compound in simulation.Compounds) { var compoundName = compound.Name; var container = new Container().WithName(compoundName); globalPKAnalysis.Add(container); var peripheralVenousBloodCurve = simulation.DataRepository.PeripheralVenousBloodColumn(compoundName); var venousBloodCurve = simulation.DataRepository.VenousBloodColumn(compoundName); if (peripheralVenousBloodCurve == null || venousBloodCurve == null) { continue; } var options = _pkCalculationOptionsFactory.CreateFor(simulation, compoundName); var venousBloodPlasmaPK = _pkAnalysisTask.CalculatePK(venousBloodCurve, options); var aucIV = simulation.AucIVFor(compoundName); var aucDDI = simulation.AucDDIFor(compoundName); var cmaxDDI = simulation.CmaxDDIFor(compoundName); var bioAvailability = createRatioParameter(CoreConstants.PKAnalysis.Bioavailability, venousBloodPlasmaPK[Constants.PKParameters.AUC_inf], aucIV, Constants.Dimension.DIMENSIONLESS); var bioAvailabilityValue = bioAvailability.Value; var bloodCurveForPKAnalysis = bloodCurveForSpecies(peripheralVenousBloodCurve, venousBloodCurve, simulation.Individual); var bloodPlasmaPK = _pkAnalysisTask.CalculatePK(bloodCurveForPKAnalysis, options); var applicationType = applicationTypeFor(simulation, compound); var aucRatio = createRatioParameter(CoreConstants.PKAnalysis.AUCRatio, bloodPlasmaPK[pkParameterNameForAUCRatio(applicationType)], aucDDI, Constants.Dimension.DIMENSIONLESS); var cmaxRatio = createRatioParameter(CoreConstants.PKAnalysis.C_maxRatio, bloodPlasmaPK[pkParameterNameForCmaxRatio(applicationType)], cmaxDDI, Constants.Dimension.DIMENSIONLESS); var vssPlasma = createParameter(CoreConstants.PKAnalysis.VssPlasma, bloodPlasmaPK[Constants.PKParameters.Vss], CoreConstants.Dimension.VolumePerBodyWeight); var vssPlasmaOverF = createParameter(CoreConstants.PKAnalysis.VssPlasmaOverF, bloodPlasmaPK[Constants.PKParameters.Vss], CoreConstants.Dimension.VolumePerBodyWeight); var vdPlasma = createParameter(CoreConstants.PKAnalysis.VdPlasma, bloodPlasmaPK[Constants.PKParameters.Vd], CoreConstants.Dimension.VolumePerBodyWeight); var vdPlasmaOverF = createParameter(CoreConstants.PKAnalysis.VdPlasmaOverF, bloodPlasmaPK[Constants.PKParameters.Vd], CoreConstants.Dimension.VolumePerBodyWeight); var vssPhysChem = createParameter(CoreConstants.PKAnalysis.VssPhysChem, calculateVSSPhysChemFor(simulation, compoundName), CoreConstants.Dimension.VolumePerBodyWeight); var totalPlasmaCL = createParameter(CoreConstants.PKAnalysis.TotalPlasmaCL, bloodPlasmaPK[Constants.PKParameters.CL], CoreConstants.Dimension.FlowPerWeight); var totalPlasmaCLOverF = createParameter(CoreConstants.PKAnalysis.TotalPlasmaCLOverF, bloodPlasmaPK[Constants.PKParameters.CL], CoreConstants.Dimension.FlowPerWeight); if (_interactionTask.HasInteractionInvolving(compound, simulation)) { container.AddChildren(aucRatio, cmaxRatio); } var fractionAbsorbed = fractionAbsorbedFor(simulation, compoundName); //multiple application or no application? in that case, only show fraction absorbed for oral if (applicationType != ApplicationType.Single) { if (isMultipleOral(simulation, compound)) { container.Add(fractionAbsorbed); } continue; } var schemaItem = singleDosingItem(simulation, compound); var pkValues = new List <IParameter>(); var bioAvailabilityCalculated = !double.IsNaN(bioAvailabilityValue); if (isIntravenous(schemaItem)) { container.AddChildren(vssPlasma, vdPlasma, vssPhysChem, totalPlasmaCL); continue; } var fractionAbsorbedWarningParameters = new List <IParameter>(); if (bioAvailabilityCalculated) { vssPlasma.Value *= bioAvailabilityValue; vdPlasma.Value *= bioAvailabilityValue; totalPlasmaCL.Value *= bioAvailabilityValue; fractionAbsorbedWarningParameters.AddRange(new[] { vssPlasma, vdPlasma }); pkValues.AddRange(new[] { vssPlasma, vdPlasma, totalPlasmaCL, bioAvailability }); } else { fractionAbsorbedWarningParameters.AddRange(new[] { vssPlasmaOverF, vdPlasmaOverF }); pkValues.AddRange(new[] { vssPlasmaOverF, vdPlasmaOverF, totalPlasmaCLOverF, bioAvailability }); } if (isOral(schemaItem)) { fractionAbsorbed.Rules.Add(fractionAbsorbedRule); pkValues.Add(fractionAbsorbed); if (bioAvailability.Value > fractionAbsorbed.Value) { bioAvailability.Rules.Add(bioAvailabilityRule); } addFractionAbsorvedWarningTo(fractionAbsorbed, fractionAbsorbedWarningParameters); } container.AddChildren(pkValues); } return(globalPKAnalysis); }