public override async Task <ModelSchema> MapToModel(SnapshotSchema snapshot, SnapshotContext snapshotContext)
        {
            var schema = _schemaFactory.Create();

            MapSnapshotPropertiesToModel(snapshot, schema);
            await UpdateParametersFromSnapshot(snapshot, schema, snapshotContext, PKSimConstants.ObjectTypes.Schema);

            var schemaItems = await _schemaItemMapper.MapToModels(snapshot.SchemaItems, snapshotContext);

            schemaItems?.Each(schema.AddSchemaItem);
            return(schema);
        }
Ejemplo n.º 2
0
        public override async Task <ModelProject> MapToModel(SnapshotProject snapshot, ProjectContext projectContext)
        {
            _logger.AddDebug($"Loading project '{snapshot.Name}' from snapshot...", snapshot.Name);

            var project = new ModelProject
            {
                Name        = snapshot.Name,
                Description = snapshot.Description,
                Creation    = _creationMetaDataFactory.Create()
            };

            //The entry point of our context structure.
            var snapshotContext = new SnapshotContext(project, snapshot.Version);

            project.Creation.InternalVersion = snapshot.Version;
            project.Creation.Version         = ProjectVersions.FindBy(snapshot.Version)?.VersionDisplay;

            await allBuildingBlocksFrom(snapshot, snapshotContext);

            var observedData = await observedDataFrom(snapshot.ObservedData, snapshotContext);

            observedData?.Each(repository => addObservedDataToProject(project, repository));

            var allSimulations = await allSimulationsFrom(project, projectContext, snapshot.Simulations, snapshotContext);

            allSimulations?.Each(simulation => addSimulationToProject(project, simulation));

            var allSimulationComparisons = await allSimulationComparisonsFrom(snapshot.SimulationComparisons, snapshotContext);

            allSimulationComparisons?.Each(comparison => addComparisonToProject(project, comparison));

            var allParameterIdentifications = await allParameterIdentificationsFrom(snapshot.ParameterIdentifications, snapshotContext);

            allParameterIdentifications?.Each(parameterIdentification => addParameterIdentificationToProject(project, parameterIdentification));

            var allQualificationPlans = await allQualificationPlansFrom(snapshot.QualificationPlans, snapshotContext);

            allQualificationPlans?.Each(qualificationPlan => addQualificationPlanToProject(project, qualificationPlan));

            //Map all classifications once project is loaded
            await updateProjectClassifications(snapshot, snapshotContext);

            return(project);
        }
Ejemplo n.º 3
0
        private Task updateProjectClassifications(SnapshotProject snapshot, SnapshotContext snapshotContext)
        {
            var project = snapshotContext.Project;
            var tasks   = new[]
            {
                _classificationSnapshotTask.UpdateProjectClassifications <ClassifiableObservedData, ModelDataRepository>(
                    snapshot.ObservedDataClassifications, snapshotContext, project.AllObservedData),
                _classificationSnapshotTask.UpdateProjectClassifications <ClassifiableSimulation, Model.Simulation>(snapshot.SimulationClassifications,
                                                                                                                    snapshotContext, project.All <Model.Simulation>()),
                _classificationSnapshotTask.UpdateProjectClassifications <ClassifiableComparison, ISimulationComparison>(
                    snapshot.SimulationComparisonClassifications, snapshotContext, project.AllSimulationComparisons),
                _classificationSnapshotTask.UpdateProjectClassifications <ClassifiableParameterIdentification, ModelParameterIdentification>(
                    snapshot.ParameterIdentificationClassifications, snapshotContext, project.AllParameterIdentifications),
                _classificationSnapshotTask.UpdateProjectClassifications <ClassifiableQualificationPlan, Model.QualificationPlan>(
                    snapshot.QualificationPlanClassifications, snapshotContext, project.AllQualificationPlans),
            };

            return(Task.WhenAll(tasks));
        }
Ejemplo n.º 4
0
        private async Task allBuildingBlocksFrom(SnapshotProject snapshot, SnapshotContext snapshotContext)
        {
            //Expression profile needs to be added first
            var expressionProfiles = await mapSnapshotToBuildingBlocks <Model.ExpressionProfile, ExpressionProfile>(snapshot.ExpressionProfiles, snapshotContext);

            expressionProfiles.Each(snapshotContext.Project.AddBuildingBlock);

            //other can be loaded independently
            var buildingBlocks = new List <IPKSimBuildingBlock>();

            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <Model.Individual, Individual>(snapshot.Individuals, snapshotContext));
            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <Model.Compound, Compound>(snapshot.Compounds, snapshotContext));
            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <PKSimEvent, Event>(snapshot.Events, snapshotContext));
            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <Model.Formulation, Formulation>(snapshot.Formulations, snapshotContext));
            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <Model.Protocol, Protocol>(snapshot.Protocols, snapshotContext));
            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <Model.Population, Population>(snapshot.Populations, snapshotContext));
            buildingBlocks.AddRange(await mapSnapshotToBuildingBlocks <Model.ObserverSet, ObserverSet>(snapshot.ObserverSets, snapshotContext));

            buildingBlocks.Each(snapshotContext.Project.AddBuildingBlock);
        }
Ejemplo n.º 5
0
        private async Task addProcessToProcessSelection(CompoundProcessesSelection compoundProcessesSelection, CompoundProcessSelection snapshotCompoundProcessSelection, Model.CompoundProcess process, SnapshotContext snapshotContext)
        {
            var processSelectionGroup = selectionGroupFor(compoundProcessesSelection, process);
            var processContext        = new CompoundProcessSnapshotContext(process, snapshotContext);
            var processSelection      = await _processMappingMapper.MapToModel(snapshotCompoundProcessSelection, processContext);

            processSelectionGroup.AddProcessSelection(processSelection);
        }
Ejemplo n.º 6
0
        public override Task <IQualificationStep> MapToModel(SnapshotQualificationStep snapshot, SnapshotContext snapshotContext)
        {
            var qualificationStep = createQualificationStepFrom(snapshot.Type);

            if (qualificationStep == null)
            {
                _logger.AddWarning(PKSimConstants.Error.CouldNotFindQualificationStep(snapshot.Type));
                return(Task.FromResult <IQualificationStep>(null));
            }

            mapQualificationStepPropertiesToModel(qualificationStep, snapshot, snapshotContext.Project);

            return(Task.FromResult(qualificationStep));
        }
        private async Task updateProcesses(SnapshotCompound snapshot, ModelCompound compound, SnapshotContext snapshotContext)
        {
            var processes = await _processMapper.MapToModels(snapshot.Processes, snapshotContext);

            processes?.Each(compound.AddProcess);
        }
Ejemplo n.º 8
0
        public override async Task <IPopulationAnalysisField> MapToModel(PopulationAnalysisField snapshot, SnapshotContext snapshotContext)
        {
            var populationAnalysisField = await createFieldFrom(snapshot, snapshotContext);

            MapSnapshotPropertiesToModel(snapshot, populationAnalysisField);
            mapIf <PopulationAnalysisParameterField>(snapshot, populationAnalysisField, mapParameterFieldToModel);
            mapIf <PopulationAnalysisPKParameterField>(snapshot, populationAnalysisField, mapPKParameterFieldToModel);
            mapIf <PopulationAnalysisCovariateField>(snapshot, populationAnalysisField, mapCovariateFieldToModel);
            mapIf <PopulationAnalysisOutputField>(snapshot, populationAnalysisField, mapOutputFieldToModel);
            return(populationAnalysisField);
        }
        public override async Task <ModelFormulation> MapToModel(SnapshotFormulation snapshotFormulation, SnapshotContext snapshotContext)
        {
            var template    = _formulationRepository.FormulationBy(snapshotFormulation.FormulationType);
            var formulation = _cloner.Clone(template);

            MapSnapshotPropertiesToModel(snapshotFormulation, formulation);
            await UpdateParametersFromSnapshot(snapshotFormulation, formulation, snapshotContext);

            formulation.UpdateParticleParametersVisibility();
            return(formulation);
        }
        public override async Task <ModelPopulation> MapToModel(SnapshotPopulation snapshot, SnapshotContext snapshotContext)
        {
            var randomPopulationSettings = await _randomPopulationSettingsMapper.MapToModel(snapshot.Settings, snapshotContext);

            //Do not add default molecule variability as this will be loaded from snapshot
            var population = await _randomPopulationFactory.CreateFor(randomPopulationSettings, CancellationToken.None, snapshot.Seed, addMoleculeParametersVariability : false);

            MapSnapshotPropertiesToModel(snapshot, population);
            await _advancedParameterMapper.MapToModel(snapshot.AdvancedParameters, population, snapshotContext);

            return(population);
        }
 public ParameterSnapshotContext(IParameter parameter, SnapshotContext baseContext) : base(baseContext)
 {
     Parameter = parameter;
 }
        private Task mapParameters <T>(IReadOnlyList <T> snapshots, Func <T, IParameter> parameterRetrieverFunc, Func <T, string> parameterIdentifierFunc, string containerDescriptor, SnapshotContext snapshotContext, bool showParameterNotFoundWarning = true) where T : SnapshotParameter
        {
            if (snapshots == null || !snapshots.Any())
            {
                return(Task.FromResult(false));
            }

            var tasks = new List <Task>();

            foreach (var snapshot in snapshots)
            {
                var parameter = parameterRetrieverFunc(snapshot);

                if (parameter == null)
                {
                    if (showParameterNotFoundWarning)
                    {
                        _logger.AddWarning(PKSimConstants.Error.SnapshotParameterNotFoundInContainer(parameterIdentifierFunc(snapshot), containerDescriptor));
                    }
                }
                else
                {
                    tasks.Add(MapToModel(snapshot, new ParameterSnapshotContext(parameter, snapshotContext)));
                }
            }

            return(Task.WhenAll(tasks));
        }
 public virtual Task MapParameters(IReadOnlyList <SnapshotParameter> snapshots, IContainer container, string containerDescriptor, SnapshotContext snapshotContext)
 {
     return(mapParameters(snapshots, x => container.Parameter(x.Name), x => x.Name, containerDescriptor, snapshotContext));
 }
        public virtual Task MapLocalizedParameters(IReadOnlyList <LocalizedParameter> localizedParameters, IContainer container, SnapshotContext snapshotContext, bool showParameterNotFoundWarning = true)
        {
            //undefined or empty or actually not localized parameters (coming from conversions probably)
            if (localizedParameters == null || !localizedParameters.Any() || localizedParameters.All(x => x.Path.IsNullOrEmpty()))
            {
                return(Task.FromResult(false));
            }

            var allParameters = _containerTask.CacheAllChildren <IParameter>(container);

            return(mapParameters(localizedParameters, x => allParameters[x.Path], x => x.Path, container.Name, snapshotContext, showParameterNotFoundWarning));
        }
 public SimulationAnalysisContext(IEnumerable <ModelDataRepository> dataRepositories, SnapshotContext baseContext) : base(baseContext)
 {
     AddDataRepositories(dataRepositories);
 }
Ejemplo n.º 16
0
        private async Task updatePopulationComparisonModel(PopulationSimulationComparison populationSimulationComparison, SimulationComparison snapshot, SnapshotContext snapshotContext)
        {
            var simulationComparisonContext = new SimulationAnalysisContext(snapshotContext.Project.AllObservedData, snapshotContext);
            var allPopulationAnalysis       = await _populationAnalysisChartMapper.MapToModels(snapshot.PopulationComparisons, simulationComparisonContext);

            allPopulationAnalysis?.Each(populationSimulationComparison.AddAnalysis);
            populationSimulationComparison.ReferenceGroupingItem = snapshot.ReferenceGroupingItem;
            populationSimulationComparison.ReferenceSimulation   = snapshotContext.Project.BuildingBlockByName <PopulationSimulation>(snapshot.ReferenceSimulation);
        }
        public override async Task <ModelDataInfo> MapToModel(SnapshotDataInfo snapshot, SnapshotContext snapshotContext)
        {
            var origin   = ModelValueFor(snapshot.Origin, ColumnOrigins.Undefined);
            var dataInfo = new ModelDataInfo(origin)
            {
                AuxiliaryType       = snapshot.AuxiliaryType,
                Category            = snapshot.Category,
                ComparisonThreshold = snapshot.ComparisonThreshold,
                LLOQ      = snapshot.LLOQ,
                MolWeight = molWeightToBaseValue(snapshot),
            };

            var extendedProperties = await _extendedPropertyMapper.MapToModels(snapshot.ExtendedProperties, snapshotContext);

            extendedProperties?.Each(dataInfo.ExtendedProperties.Add);

            return(dataInfo);
        }
Ejemplo n.º 18
0
        public override async Task <ModelParameterIdentification> MapToModel(SnapshotParameterIdentification snapshot, SnapshotContext snapshotContext)
        {
            var parameterIdentification        = _objectBaseFactory.Create <ModelParameterIdentification>();
            var parameterIdentificationContext = new ParameterIdentificationContext(parameterIdentification, snapshotContext);

            MapSnapshotPropertiesToModel(snapshot, parameterIdentification);

            snapshot.Simulations?.Each(s => { addSimulation(s, parameterIdentification, snapshotContext.Project); });

            await _parameterIdentificationConfigurationMapper.MapToModel(snapshot.Configuration, parameterIdentificationContext);

            var outputMappings = await _outputMappingMapper.MapToModels(snapshot.OutputMappings, parameterIdentificationContext);

            outputMappings?.Each(parameterIdentification.AddOutputMapping);

            var identificationParameters = await _identificationParameterMapper.MapToModels(snapshot.IdentificationParameters, parameterIdentificationContext);

            identificationParameters?.Each(parameterIdentification.AddIdentificationParameter);

            var simulationAnalysis = await _parameterIdentificationAnalysisMapper.MapToModels(snapshot.Analyses, parameterIdentificationContext);

            simulationAnalysis?.Each(parameterIdentification.AddAnalysis);

            parameterIdentification.IsLoaded = true;
            return(parameterIdentification);
        }
Ejemplo n.º 19
0
        public override async Task <ModelEvent> MapToModel(SnapshotEvent snapshotEvent, SnapshotContext snapshotContext)
        {
            var modelEvent = _eventFactory.Create(snapshotEvent.Template);

            MapSnapshotPropertiesToModel(snapshotEvent, modelEvent);
            await UpdateParametersFromSnapshot(snapshotEvent, modelEvent, snapshotContext, snapshotEvent.Template);

            return(modelEvent);
        }
Ejemplo n.º 20
0
 public override Task <ModelValueOrigin> MapToModel(SnapshotValueOrigin snapshot, SnapshotContext snapshotContext)
 {
     return(Task.FromException <ModelValueOrigin>(new SnapshotMapToModelNotSupportedException <ModelValueOrigin, ModelValueOrigin>()));
 }
Ejemplo n.º 21
0
        private async Task <IPopulationAnalysisField> createFieldFrom(PopulationAnalysisField snapshot, SnapshotContext snapshotContext)
        {
            if (snapshot.ParameterPath != null)
            {
                return(new PopulationAnalysisParameterField());
            }

            if (snapshot.PKParameter != null)
            {
                return(new PopulationAnalysisPKParameterField());
            }

            if (snapshot.Covariate != null)
            {
                return(new PopulationAnalysisCovariateField());
            }

            if (snapshot.GroupingDefinition != null)
            {
                var groupingDefinition = await _groupingDefinitionMapper.MapToModel(snapshot.GroupingDefinition, snapshotContext);

                return(new PopulationAnalysisGroupingField(groupingDefinition));
            }

            return(new PopulationAnalysisOutputField());
        }
 public override Task <ModelParameterIdentificationRunMode> MapToModel(SnapshotParameterIdentificationRunMode snapshot, SnapshotContext snapshotContext)
 {
     return(Task.FromResult(mapRunModeFrom(snapshot)));
 }
        public override async Task <ModelCompound> MapToModel(SnapshotCompound snapshot, SnapshotContext snapshotContext)
        {
            var compound = _compoundFactory.Create();

            MapSnapshotPropertiesToModel(snapshot, compound);
            _calculationMethodCacheMapper.UpdateCalculationMethodCache(compound, snapshot.CalculationMethods);

            await updateAlternatives(compound, snapshot.Lipophilicity, COMPOUND_LIPOPHILICITY, snapshotContext);
            await updateAlternatives(compound, snapshot.FractionUnbound, COMPOUND_FRACTION_UNBOUND, snapshotContext);
            await updateAlternatives(compound, snapshot.Solubility, COMPOUND_SOLUBILITY, snapshotContext);
            await updateAlternatives(compound, snapshot.IntestinalPermeability, COMPOUND_INTESTINAL_PERMEABILITY, snapshotContext);
            await updateAlternatives(compound, snapshot.Permeability, COMPOUND_PERMEABILITY, snapshotContext);

            updatePkaTypes(compound, snapshot);

            await updateProcesses(snapshot, compound, snapshotContext);
            await UpdateParametersFromSnapshot(snapshot, compound, snapshotContext);

            synchronizeMolWeightValueOrigins(compound);
            return(compound);
        }
        public override async Task <ModelQualificationPlan> MapToModel(SnapshotQualificationPlan snapshot, SnapshotContext snapshotContext)
        {
            var qualificationPlan = _objectBaseFactory.Create <ModelQualificationPlan>();

            MapSnapshotPropertiesToModel(snapshot, qualificationPlan);

            var qualificationSteps = await _qualificationStepMapper.MapToModels(snapshot.Steps, snapshotContext);

            qualificationSteps?.Each(qualificationPlan.Add);
            return(qualificationPlan);
        }
        private async Task updateAlternatives(ModelCompound compound, Alternative[] snapshotAlternatives, string alternativeGroupName, SnapshotContext snapshotContext)
        {
            if (snapshotAlternatives == null)
            {
                return;
            }

            var alternativeGroup = compound.ParameterAlternativeGroup(alternativeGroupName);

            //Remove all alternatives except calculated ones
            alternativeGroup.AllAlternatives.ToList().Where(x => !x.IsCalculated).Each(alternativeGroup.RemoveAlternative);

            //Reset the default flag that will be read from snapshot
            alternativeGroup.AllAlternatives.Each(x => x.IsDefault = false);

            var alternativeSnapshotContext = new AlternativeMapperSnapshotContext(alternativeGroup, snapshotContext);
            var alternatives = await _alternativeMapper.MapToModels(snapshotAlternatives, alternativeSnapshotContext);

            alternatives?.Each(alternativeGroup.AddAlternative);

            //Ensure that we have at least one default alternative (might not be the case if only calculated alternatives were saved)
            var defaultAlternative = alternativeGroup.DefaultAlternative;

            if (defaultAlternative != null)
            {
                defaultAlternative.IsDefault = true;
            }
        }
Ejemplo n.º 26
0
        private Task <IndividualSimulationComparison> createIndividualComparisonModel(SimulationComparison snapshot, SnapshotContext snapshotContext)
        {
            var simulationComparisonContext = new SimulationAnalysisContext(snapshotContext.Project.AllObservedData, snapshotContext);
            var comparedSimulations         = allComparedSimulationsFrom <IndividualSimulation>(snapshot, snapshotContext.Project);

            comparedSimulations.Each(s => simulationComparisonContext.AddDataRepository(s.DataRepository));
            return(_individualSimulationComparisonMapper.MapToModel(snapshot.IndividualComparison, simulationComparisonContext));
        }
Ejemplo n.º 27
0
        private async Task <CompoundProcessesSelection> modelProcessSelectionFrom(CompoundProcessSelection[] snapshotProcesses, Model.Compound compound, ISimulationSubject simulationSubject, SnapshotContext snapshotContext)
        {
            var compoundProcessesSelection = new CompoundProcessesSelection();

            if (snapshotProcesses == null)
            {
                return(compoundProcessesSelection);
            }

            foreach (var snapshotProcess in snapshotProcesses)
            {
                var process = compound.ProcessByName(snapshotProcess.Name) ?? notSelectedProcessFrom(snapshotProcess, simulationSubject);
                if (process == null)
                {
                    //No process found and a name was specified. This is a snapshot that is corrupted
                    if (!string.IsNullOrEmpty(snapshotProcess.Name))
                    {
                        _logger.AddWarning(PKSimConstants.Error.ProcessNotFoundInCompound(snapshotProcess.Name, compound.Name));
                    }

                    continue;
                }

                await addProcessToProcessSelection(compoundProcessesSelection, snapshotProcess, process, snapshotContext);
            }

            return(compoundProcessesSelection);
        }
Ejemplo n.º 28
0
        public override async Task <ISimulationComparison> MapToModel(SimulationComparison snapshot, SnapshotContext snapshotContext)
        {
            var simulationComparison = await createSimulationComparisonFrom(snapshot, snapshotContext);

            MapSnapshotPropertiesToModel(snapshot, simulationComparison);
            simulationComparison.IsLoaded = true;
            return(simulationComparison);
        }
Ejemplo n.º 29
0
 public CalculationMethodCacheSnapshotContext(ModelCalculationMethodCache calculationMethodCache, SnapshotContext baseContext) : base(baseContext)
 {
     CalculationMethodCache = calculationMethodCache;
 }
Ejemplo n.º 30
0
        private async Task <ISimulationComparison> createSimulationComparisonFrom(SimulationComparison snapshot, SnapshotContext snapshotContext)
        {
            var project = snapshotContext.Project;

            if (snapshot.IndividualComparison != null)
            {
                var individualSimulationComparison = await createIndividualComparisonModel(snapshot, snapshotContext);

                return(addSimulationsToComparison(individualSimulationComparison, snapshot, project));
            }

            var populationSimulationComparison = _objectBaseFactory.Create <PopulationSimulationComparison>();

            await updatePopulationComparisonModel(populationSimulationComparison, snapshot, snapshotContext);

            return(addSimulationsToComparison(populationSimulationComparison, snapshot, project));
        }