Esempio n. 1
0
        private Task performBuildingBlockSwap(Project projectSnapshot, BuildingBlockSwap[] buildingBlockSwaps)
        {
            if (buildingBlockSwaps == null)
            {
                return(Task.CompletedTask);
            }

            return(Task.WhenAll(buildingBlockSwaps.Select(x => swapBuildingBlockIn(projectSnapshot, x))));
        }
Esempio n. 2
0
        private Task performSimulationParameterSwap(Project projectSnapshot, SimulationParameterSwap[] simulationParameters)
        {
            if (simulationParameters == null)
            {
                return(Task.CompletedTask);
            }

            return(Task.WhenAll(simulationParameters.Select(x => swapSimulationParametersIn(projectSnapshot, x))));
        }
        protected override async Task Context()
        {
            await base.Context();

            var projectSnapshot = new Project();
            var project         = new PKSimProject();

            A.CallTo(() => _jsonSerializer.DeserializeAsArray(_fileName, typeof(Project))).Returns(new object[] { projectSnapshot, });
            A.CallTo(() => _projectMapper.MapToModel(projectSnapshot, A <ProjectContext> ._)).Returns(project);
        }
Esempio n. 4
0
 private void validateInputs(Project snapshotProject, QualifcationConfiguration configuration)
 {
     configuration.Inputs?.Each(x =>
     {
         var buildingBlock = snapshotProject.BuildingBlockByTypeAndName(x.Type, x.Name);
         if (buildingBlock == null)
         {
             throw new QualificationRunException(CannotFindBuildingBlockInSnapshot(x.Type.ToString(), x.Name, snapshotProject.Name));
         }
     });
 }
Esempio n. 5
0
        protected override async Task Context()
        {
            await base.Context();

            var snapshotType    = typeof(PKSimProject);
            var projectSnapshot = new Project();
            var project         = new PKSimProject();

            A.CallTo(() => _snapshotMapper.SnapshotTypeFor <PKSimProject>()).Returns(snapshotType);
            A.CallTo(() => _jsonSerializer.DeserializeAsArray(_fileName, snapshotType)).Returns(new object[] { projectSnapshot, });
            A.CallTo(() => _snapshotMapper.MapToModel(projectSnapshot)).Returns(project);
        }
Esempio n. 6
0
        private PlotMapping[] retrievePlotDefinitionsFrom(Project snapshotProject, QualifcationConfiguration configuration)
        {
            var plotMappings        = configuration.SimulationPlots?.SelectMany(x => retrievePlotDefinitionsForSimulation(x, snapshotProject));
            var plotMappingsArray   = plotMappings?.ToArray() ?? Array.Empty <PlotMapping>();
            var exportedSimulations = configuration.Simulations?.ToArray() ?? Array.Empty <string>();
            var unmappedSimulations = plotMappingsArray.Select(x => x.Simulation).Distinct().Where(x => !exportedSimulations.Contains(x)).ToList();

            //All simulations referenced in the the plot mapping are also exported. We are good
            if (!unmappedSimulations.Any())
            {
                return(plotMappingsArray);
            }

            throw new QualificationRunException(SimulationUsedInPlotsAreNotExported(unmappedSimulations, snapshotProject.Name));
        }
Esempio n. 7
0
        private async Task swapSimulationParametersIn(Project projectSnapshot, SimulationParameterSwap simulationParameter)
        {
            var(parameterPath, simulationName, snapshotPath) = simulationParameter;
            var referenceSnapshot = await snapshotProjectFromFile(snapshotPath);

            var referenceSimulation = simulationFrom(referenceSnapshot, simulationName);

            var referenceParameter = referenceSimulation.ParameterByPath(parameterPath);

            if (referenceParameter == null)
            {
                throw new QualificationRunException(CannotFindSimulationParameterInSnapshot(parameterPath, simulationName, referenceSnapshot.Name));
            }

            simulationParameter.TargetSimulations?.Each(targetSimulationName =>
            {
                var targetSimulation = simulationFrom(projectSnapshot, targetSimulationName);
                targetSimulation.AddOrUpdate(referenceParameter);
            });
        }
Esempio n. 8
0
        private async Task swapBuildingBlockIn(Project projectSnapshot, BuildingBlockSwap buildingBlockSwap)
        {
            var(buildingBlockType, name, snapshotPath) = buildingBlockSwap;
            var referenceSnapshot = await snapshotProjectFromFile(snapshotPath);

            var typeDisplay = buildingBlockType.ToString();

            var buildingBlockToUse = referenceSnapshot.BuildingBlockByTypeAndName(buildingBlockType, name);

            if (buildingBlockToUse == null)
            {
                throw new QualificationRunException(CannotFindBuildingBlockInSnapshot(typeDisplay, name, referenceSnapshot.Name));
            }

            var buildingBlock = projectSnapshot.BuildingBlockByTypeAndName(buildingBlockType, name);

            if (buildingBlock == null)
            {
                throw new QualificationRunException(CannotFindBuildingBlockInSnapshot(typeDisplay, name, projectSnapshot.Name));
            }

            projectSnapshot.Swap(buildingBlockToUse);
        }
Esempio n. 9
0
        private Simulation simulationFrom(Project snapshotProject, string simulationName)
        {
            var referenceSimulation = snapshotProject.Simulations?.FindByName(simulationName);

            return(referenceSimulation ?? throw new QualificationRunException(CannotFindSimulationInSnapshot(simulationName, snapshotProject.Name)));
        }
Esempio n. 10
0
        private IEnumerable <PlotMapping> retrievePlotDefinitionsForSimulation(SimulationPlot simulationPlot, Project snapshotProject)
        {
            var simulationName = simulationPlot.Simulation;
            var simulation     = simulationFrom(snapshotProject, simulationName);

            return(simulation.Analyses.Select(plot => new PlotMapping
            {
                Plot = plot,
                SectionId = simulationPlot.SectionId,
                Simulation = simulationName,
                Project = snapshotProject.Name
            }));
        }
Esempio n. 11
0
        private PlotMapping[] retrievePlotDefinitionsFrom(Project snapshotProject, QualifcationConfiguration configuration)
        {
            var plotMappings = configuration.SimulationPlots?.SelectMany(x => retrievePlotDefinitionsForSimulation(x, snapshotProject));

            return(plotMappings?.ToArray() ?? Array.Empty <PlotMapping>());
        }
Esempio n. 12
0
        private async Task exportToFolder(string exportFolder)
        {
            var project    = new Project();
            var individual = await _snapshotObjectCreator.DefaultIndividual();

            project.Individuals = new[] { individual };

            var compound = await _snapshotObjectCreator.StandardCompound(lipophilicity : 3, fractionUnbound : 0.1, molWeight : 400, name : "Standard Molecule");

            compound.Name     = "Standard Molecule";
            project.Compounds = new[] { compound };

            var intrevanousBolusMgPerKg = await _snapshotObjectCreator.SimpleProtocol(dose : 1, doseUnit : "mg/kg", applicationType : ApplicationTypes.IntravenousBolus);

            var intrevanousBolusMg = await _snapshotObjectCreator.SimpleProtocol(dose : 1, doseUnit : "mg", applicationType : ApplicationTypes.IntravenousBolus);

            project.Protocols = new[] { intrevanousBolusMgPerKg, intrevanousBolusMg };

            var snapshotConfiguration = new SimulationConstruction
            {
                Individual = individual,
                Compounds  = new[] { compound },
                Protocols  = new [] { intrevanousBolusMgPerKg },
                ModelName  = CoreConstants.Model.FourComp,
            };

            var fourCompIvBolusMgPerKg = await configurationFrom(snapshotConfiguration);

            snapshotConfiguration.ModelName = CoreConstants.Model.TwoPores;
            var twoPore = await configurationFrom(snapshotConfiguration);

            snapshotConfiguration.Protocols = new[] { intrevanousBolusMg };
            snapshotConfiguration.ModelName = CoreConstants.Model.FourComp;
            var fourCompIvBolusMg = await configurationFrom(snapshotConfiguration);


            twoPore.SpatialStructure.Name  = "Human 2 Pores";
            twoPore.PassiveTransports.Name = "2 Pores Passive Transports";

            fourCompIvBolusMgPerKg.SpatialStructure.Name  = "Human Standard";
            fourCompIvBolusMgPerKg.PassiveTransports.Name = "Standard Passive Transports";
            fourCompIvBolusMgPerKg.EventGroups.Name       = "IV Bolus";
            fourCompIvBolusMgPerKg.Molecules.Name         = "Standard Molecule";
            fourCompIvBolusMgPerKg.Observers.Name         = "Standard Observer";


            fourCompIvBolusMg.EventGroups.Name = "IV Bolus (mg)";

            var defaultCompound = fourCompIvBolusMgPerKg.Molecules.First();

            defaultCompound.Name = string.Empty;
            defaultCompound.Parameter(CoreConstants.Parameters.LIPOPHILICITY).Value    = double.NaN;
            defaultCompound.Parameter(CoreConstants.Parameters.MOLECULAR_WEIGHT).Value = double.NaN;
            defaultCompound.Parameter(CoreConstants.Parameters.FRACTION_UNBOUND_PLASMA_REFERENCE_VALUE).Value = double.NaN;
            defaultCompound.Parameter(CoreConstants.Parameters.SOLUBILITY_AT_REFERENCE_PH).Value = double.NaN;

            _moBiExportTask.UpdateObserverForAllFlag(fourCompIvBolusMgPerKg.Observers);

            var buildingBlocks = new IBuildingBlock[]
            {
                twoPore.SpatialStructure,
                twoPore.PassiveTransports,
                fourCompIvBolusMgPerKg.SpatialStructure,
                fourCompIvBolusMgPerKg.PassiveTransports,
                fourCompIvBolusMgPerKg.EventGroups,
                fourCompIvBolusMgPerKg.Molecules,
                fourCompIvBolusMgPerKg.Observers,
                fourCompIvBolusMg.EventGroups
            };

            buildingBlocks.Each(bb => saveToPKML(bb, exportFolder));
        }