Skip to content

Commit

Permalink
2364 export expression profile domain object (#2461)
Browse files Browse the repository at this point in the history
* initial try

* temp nuget update

* adjusting mapper

* Fixes #2344 Implement "Parameter Value Export" for Expression Profiles BB in PK-Sim (#2442)

* use GetAllChildren of Individual (#2445)

* 2438 outptu mappings not cleared (#2444)

* waiting for Core PR to be accepted

* nugets updated

* updating nuget

* temp nuget update

* working export

* spacing

* updating packages

* do not map object path for  'ROOT'

* do not repeat formulae in the formula cache

* adding tests

* fixing test

* correction

* consolidate assets

* correcting nugets

* code review changes

* code review

* PR feedback

* update core version

* Appveyor builds turned on

* PR feedback

* pr feedback

Co-authored-by: Robert McIntosh <261477+rwmcintosh@users.noreply.github.com>
  • Loading branch information
georgeDaskalakis and rwmcintosh authored Dec 9, 2022
1 parent 6ad7c98 commit 608c162
Show file tree
Hide file tree
Showing 53 changed files with 439 additions and 187 deletions.
13 changes: 8 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ image: Visual Studio 2019

version: '{build}'

# TODO make sure to revert this temporary 12.0. to $($env:ospsuite_version).

init:
- ps: Update-AppveyorBuild -Version "$($env:ospsuite_version).$($env:appveyor_build_version)"
- ps: Update-AppveyorBuild -Version "12.0.$($env:appveyor_build_version)"

clone_depth: 1

dotnet_csproj:
patch: true
file: '**\*.csproj'
version: '$(ospsuite_version).$(build_number)'
assembly_version: '$(ospsuite_version).$(build_number)'
file_version: '$(ospsuite_version).$(build_number)'
informational_version: '$(ospsuite_version).$(build_number)'
version: '12.0.$(build_number)'
assembly_version: '12.0.$(build_number)'
file_version: '12.0.$(build_number)'
informational_version: '12.0.$(build_number)'

skip_branch_with_pr: true

branches:
only:
- develop
- OSMOSES

pull_requests:
do_not_increment_build_number: true
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.Assets.Images/PKSim.Assets.Images.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.74" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.74" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.Assets/PKSim.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets.Images" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.74" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.74" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/PKSim.Assets/PKSimConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ public static string MultipleOperatorFoundForContainer(int containerId, string p

public static string ExpressionProfileForMoleculeNotFound(string molecule, string buildingBlockName, string buildingBlockType) =>
$"Expression profile for molecule '{molecule}' was not found in the project. Please delete this molecule from {buildingBlockType.ToLower()} '{buildingBlockName}'.";

public static string CouldNotFindMoleculeType(string moleculeType) =>
$"Could not find the molecule type {moleculeType}";
}

public static class Information
Expand Down Expand Up @@ -1945,6 +1948,7 @@ public static class UI
public static readonly string No = "No";
public static readonly string Yes = "Yes";
public static readonly string ExportObservedDataToPkml = "Export observed data to pkml";
public static readonly string ExportExpressionProfileToPkml = "Export expression profile to pkml";
public static readonly string ExportSimulationResultsToExcel = $"Export simulation results to {Excel}";
public static readonly string ExportPopulationAnalysisToExcelTitle = $"Export analysis to {Excel}";
public static readonly string ExportSimulationResultsToCSV = $"Export simulation results to CSV";
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.BatchTool/PKSim.BatchTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.65" />
<PackageReference Include="OSPSuite.Core" Version="12.0.74" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.74" />
<PackageReference Include="OSPSuite.DevExpress" Version="21.2.3" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.CLI.Core/PKSim.CLI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.74" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="11.1.65" />
<PackageReference Include="OSPSuite.Core" Version="12.0.74" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/PKSim.CLI/PKSim.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="OSPSuite.Core" Version="11.1.65" />
<PackageReference Include="OSPSuite.Presentation" Version="11.1.65" />
<PackageReference Include="OSPSuite.Assets" Version="11.1.65" />
<PackageReference Include="OSPSuite.Core" Version="12.0.74" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.74" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.74" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
54 changes: 11 additions & 43 deletions src/PKSim.Core/CoreConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using OSPSuite.Core.Domain;
using OSPSuite.Utility.Extensions;
using static OSPSuite.Core.Domain.Constants;

namespace PKSim.Core
{
Expand Down Expand Up @@ -98,8 +99,6 @@ public static class Filter
//tolerated precision to relatively compare to double values
public const double DOUBLE_RELATIVE_EPSILON = 1e-2;

public const char COMPOSITE_SEPARATOR = '-';

//not as readonly as the text will be updated with the current version
public static string ProductDisplayName = PRODUCT_NAME_WITH_TRADEMARK;

Expand All @@ -109,25 +108,6 @@ public static class Filter

public static string DefaultPopulationExportNameFor(string containerName) => $"{containerName}-Population";

public static string CompositeNameFor(params string[] names) => compositeNameFor(COMPOSITE_SEPARATOR, names);


private static string compositeNameFor(char separator, params string[] names)
{
if (names == null || names.Length == 0)
return string.Empty;

var nonEmptyNames = names.ToList();
nonEmptyNames.RemoveAll(string.IsNullOrEmpty);

return nonEmptyNames.Select(x=>x.Trim()).ToString($"{separator}");
}

public static IReadOnlyList<string> NamesFromCompositeName(string compositeName, char separator = COMPOSITE_SEPARATOR)
{
return compositeName.Split(separator);
}

public static class DirectoryKey
{
public static readonly string BATCH_INPUT = "BatchInput";
Expand Down Expand Up @@ -448,18 +428,6 @@ public static string BuildingBlockInSimulationNameFor(string buildingBlockName,

public static string PartialProcessName(string proteinName, string dataSource) => CompositeNameFor(proteinName, dataSource);

public static string ExpressionProfileName(string moleculeName, Core.Model.Species species, string category)
=> compositeNameFor(char.Parse(ObjectPath.PATH_DELIMITER), moleculeName, species?.DisplayName, category);

public static (string moleculeName, string speciesName, string category) NamesFromExpressionProfileName(string expressionProfileName)
{
var names = NamesFromCompositeName(expressionProfileName, char.Parse(ObjectPath.PATH_DELIMITER));
if (names.Count != 3)
return (string.Empty, string.Empty, string.Empty);

return (names[0], names[1], names[2]);
}

public static string GlobalExpressionContainerNameFor(string expressionParameter)
{
switch (expressionParameter)
Expand Down Expand Up @@ -885,16 +853,16 @@ public static class PKAnalysis

public static readonly IReadOnlyList<string> AllParametersInfluencedByFractionAbsorbed = new[]
{
Constants.PKParameters.Vd,
Constants.PKParameters.Vss,
Constants.PKParameters.MRT,
Constants.PKParameters.Thalf,
Constants.PKParameters.AUC_inf,
Constants.PKParameters.AUC_inf_norm,
Constants.PKParameters.AUC_inf_tD1,
Constants.PKParameters.AUC_inf_tD1_norm,
Constants.PKParameters.AUC_inf_tDLast,
Constants.PKParameters.AUC_inf_tLast_norm
PKParameters.Vd,
PKParameters.Vss,
PKParameters.MRT,
PKParameters.Thalf,
PKParameters.AUC_inf,
PKParameters.AUC_inf_norm,
PKParameters.AUC_inf_tD1,
PKParameters.AUC_inf_tD1_norm,
PKParameters.AUC_inf_tDLast,
PKParameters.AUC_inf_tLast_norm
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using OSPSuite.Core;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility;
using PKSim.Assets;
using PKSim.Core.Model;
using IFormulaFactory = PKSim.Core.Model.IFormulaFactory;

namespace PKSim.Core.Mappers
{
public interface IExpressionProfileToExpressionProfileBuildingBlockMapper : IMapper<ExpressionProfile, ExpressionProfileBuildingBlock>
{
}

public class ExpressionProfileToExpressionProfileBuildingBlockMapper : IExpressionProfileToExpressionProfileBuildingBlockMapper
{
private readonly IObjectBaseFactory _objectBaseFactory;
private readonly IEntityPathResolver _entityPathResolver;
private readonly IFormulaFactory _formulaFactory;
private readonly IApplicationConfiguration _applicationConfiguration;

public ExpressionProfileToExpressionProfileBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IFormulaFactory formulaFactory, IApplicationConfiguration applicationConfiguration)
{
_objectBaseFactory = objectBaseFactory;
_entityPathResolver = entityPathResolver;
_formulaFactory = formulaFactory;
_applicationConfiguration = applicationConfiguration;
}

public ExpressionProfileBuildingBlock MapFrom(ExpressionProfile expressionProfile)
{
var expressionProfileBuildingBlock = _objectBaseFactory.Create<ExpressionProfileBuildingBlock>();

expressionProfileBuildingBlock.Name = expressionProfile.Name;
expressionProfileBuildingBlock.PKSimVersion = _applicationConfiguration.Version;
expressionProfileBuildingBlock.Description = expressionProfile.Description;

expressionProfileBuildingBlock.Type = mapExpressionType(expressionProfile.Molecule.MoleculeType);

var allParameters = expressionProfile.GetAllChildren<IParameter>();

foreach (var parameter in allParameters)
{
var expressionParameter = mapExpressionParameterFromExpressionProfile(parameter, expressionProfileBuildingBlock);
expressionProfileBuildingBlock.Add(expressionParameter);
}

return expressionProfileBuildingBlock;
}

private ExpressionType mapExpressionType(QuantityType moleculeType)
{
switch (moleculeType)
{
case QuantityType.Enzyme:
return ExpressionTypes.MetabolizingEnzyme;
case QuantityType.Transporter:
return ExpressionTypes.TransportProtein;
case QuantityType.OtherProtein:
return ExpressionTypes.ProteinBindingPartner;
}

throw new PKSimException(PKSimConstants.Error.CouldNotFindMoleculeType(moleculeType.ToString()));
}

private ExpressionParameter mapExpressionParameterFromExpressionProfile(IParameter parameter,
ExpressionProfileBuildingBlock expressionProfileBuildingBlock)
{
var expressionParameter = _objectBaseFactory.Create<ExpressionParameter>();

if (parameter.Formula != null && parameter.Formula.IsCachable())
{
var formula = _formulaFactory.RateFor(CoreConstants.CalculationMethod.EXPRESSION_PARAMETERS, parameter.Formula.Name,
expressionProfileBuildingBlock.FormulaCache);
expressionParameter.Formula = formula;
}
else
{
(expressionParameter.StartValue, _) = parameter.TryGetValue();
}

expressionParameter.Name = parameter.Name;

expressionParameter.Path = _entityPathResolver.ObjectPathFor(parameter);
expressionParameter.Dimension = parameter.Dimension;
expressionParameter.DisplayUnit = parameter.DisplayUnit;
return expressionParameter;
}
}
}
7 changes: 4 additions & 3 deletions src/PKSim.Core/Mappers/PKSimPathToPathElementsMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using PKSim.Assets;
using PKSim.Core.Model.Extensions;
using PKSim.Core.Repositories;
using static OSPSuite.Core.Domain.Constants;
using ContainerExtensions = PKSim.Core.Model.ContainerExtensions;
using ContainerType = OSPSuite.Core.Domain.ContainerType;

Expand All @@ -26,7 +27,7 @@ public PKSimPathToPathElementsMapper(IRepresentationInfoRepository representatio
{
_representationInfoRepository = representationInfoRepository;
//Format is (Fraction of dose-DRUG_NAME)-Liver-COMPARTMENT
var fractionOfDoseLiverObserverPattern = $@"(?<{OBSERVER_NAME}>{CoreConstants.Observer.FRACTION_OF_DOSE}{CoreConstants.COMPOSITE_SEPARATOR}\w*){CoreConstants.COMPOSITE_SEPARATOR}{CoreConstants.Organ.LIVER}{CoreConstants.COMPOSITE_SEPARATOR}\w*";
var fractionOfDoseLiverObserverPattern = $@"(?<{OBSERVER_NAME}>{CoreConstants.Observer.FRACTION_OF_DOSE}{COMPOSITE_SEPARATOR}\w*){COMPOSITE_SEPARATOR}{CoreConstants.Organ.LIVER}{COMPOSITE_SEPARATOR}\w*";
_fractionOfDoseLiverRegex = new Regex(fractionOfDoseLiverObserverPattern);
}

Expand Down Expand Up @@ -214,7 +215,7 @@ private string dimensionDisplayNameFor(IQuantity quantity)
if (quantity.Dimension.Name == CoreConstants.Dimension.Fraction)
return CoreConstants.Output.FractionDose;

if (quantity.Dimension.Name.IsOneOf(Constants.Dimension.MASS_AMOUNT, Constants.Dimension.MOLAR_AMOUNT))
if (quantity.Dimension.Name.IsOneOf(Dimension.MASS_AMOUNT, Dimension.MOLAR_AMOUNT))
return CoreConstants.Output.Amount;

if (quantityIsConcentration(quantity))
Expand All @@ -226,7 +227,7 @@ private string dimensionDisplayNameFor(IQuantity quantity)
private bool quantityIsConcentration(IQuantity quantity)
{
return quantity.Dimension != null &&
quantity.Dimension.Name.IsOneOf(CoreConstants.Dimension.MASS_CONCENTRATION, Constants.Dimension.MOLAR_CONCENTRATION);
quantity.Dimension.Name.IsOneOf(CoreConstants.Dimension.MASS_CONCENTRATION, Dimension.MOLAR_CONCENTRATION);
}
}
}
9 changes: 5 additions & 4 deletions src/PKSim.Core/Mappers/ProcessToProcessBuilderMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using PKSim.Core.Model;
using PKSim.Core.Repositories;
using PKSim.Core.Services;
using static OSPSuite.Core.Domain.Constants;
using static PKSim.Core.CoreConstants.Compartment;
using static PKSim.Core.CoreConstants.Organ;

Expand Down Expand Up @@ -163,7 +164,7 @@ public IReactionBuilder TurnoverReactionFrom(IReactionBuilder templateReaction,
{
var reaction = createReactionFromProcess(templateReaction, forbiddenNames);
reaction.Name = reactionNameFor(reaction.Name, protein.Name);
reaction.Formula.Name = CoreConstants.CompositeNameFor(reaction.Name, reaction.Formula.Name);
reaction.Formula.Name = CompositeNameFor(reaction.Name, reaction.Formula.Name);

replaceKeywordsInProcess(reaction, new[] {CoreConstants.KeyWords.Protein, CoreConstants.KeyWords.Reaction},
new[] {protein.Name, reaction.Name});
Expand Down Expand Up @@ -199,7 +200,7 @@ private IReactionBuilder interactionReactionFrom(InteractionProcess interactionP
IReadOnlyCollection<string> forbiddenNames, IFormulaCache formulaCache)
{
var compound = interactionProcess.ParentCompound;
var reactionName = CoreConstants.CompositeNameFor(compound.Name, interactionProcess.Name);
var reactionName = CompositeNameFor(compound.Name, interactionProcess.Name);
var reaction = createReactionFromProcess(interactionProcess, reactionName, forbiddenNames);

//replace keywords
Expand Down Expand Up @@ -275,7 +276,7 @@ private IReactionBuilder createReactionFromProcess(IContainer reactionParameterC
private IReactionBuilder createReactionFromProcess(IMoleculeBuilder moleculeBuilder, CompoundProcess process,
IReadOnlyCollection<string> forbiddenNames)
{
var reactionName = CoreConstants.CompositeNameFor(moleculeBuilder.Name, process.Name);
var reactionName = CompositeNameFor(moleculeBuilder.Name, process.Name);
return createReactionFromProcess(process, reactionName, forbiddenNames);
}

Expand All @@ -286,7 +287,7 @@ private IReactionBuilder createReactionFromProcess(CompoundProcess process, stri
reactionName, forbiddenNames);

//make sure formula name is unique as it can be shared among processes
reaction.Formula.Name = CoreConstants.CompositeNameFor(reaction.Name, reaction.Formula.Name);
reaction.Formula.Name = CompositeNameFor(reaction.Name, reaction.Formula.Name);
return reaction;
}

Expand Down
9 changes: 5 additions & 4 deletions src/PKSim.Core/Mappers/RangeChartDataToDataTableMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using PKSim.Assets;
using PKSim.Core.Chart;
using OSPSuite.Utility.Extensions;
using static OSPSuite.Core.Domain.Constants;

namespace PKSim.Core.Mappers
{
Expand All @@ -20,10 +21,10 @@ protected override void AddSpecificChartColumns(DataTable dataTable, CurveData<R
{
_xValueColumn = curveData.XAxis.Caption;
_yValueColumn = curveData.YAxis.Caption;
_yLowerPercentileColumn = CoreConstants.CompositeNameFor(PKSimConstants.UI.LowerPercentile, _yValueColumn);
_yUpperPercentileColumn = CoreConstants.CompositeNameFor(PKSimConstants.UI.UpperPercentile, _yValueColumn);
_xMinimumColumn = CoreConstants.CompositeNameFor(PKSimConstants.UI.Minimum, _xValueColumn);
_xMaximumColumn = CoreConstants.CompositeNameFor(PKSimConstants.UI.Maximum, _xValueColumn);
_yLowerPercentileColumn = CompositeNameFor(PKSimConstants.UI.LowerPercentile, _yValueColumn);
_yUpperPercentileColumn = CompositeNameFor(PKSimConstants.UI.UpperPercentile, _yValueColumn);
_xMinimumColumn = CompositeNameFor(PKSimConstants.UI.Minimum, _xValueColumn);
_xMaximumColumn = CompositeNameFor(PKSimConstants.UI.Maximum, _xValueColumn);
_xNumberOfIndividualsColumn = PKSimConstants.UI.NumberOfIndividuals;

dataTable.AddColumn<float>(_xMinimumColumn);
Expand Down
Loading

0 comments on commit 608c162

Please sign in to comment.