Ejemplo n.º 1
0
        protected override Task Context()
        {
            _containerTask           = A.Fake <IContainerTask>();
            _progressManager         = A.Fake <IProgressManager>();
            _individualCacheImporter = A.Fake <IIndividualPropertiesCacheImporter>();
            _cloner                   = A.Fake <ICloner>();
            _objectBaseFactory        = A.Fake <IObjectBaseFactory>();
            _advancedParameterFactory = A.Fake <IAdvancedParameterFactory>();
            _createdPopulation        = A.Fake <ImportPopulation>();
            _individual               = new Individual();
            _cloneIndividual          = new Individual();

            A.CallTo(() => _cloner.Clone(_individual)).Returns(_cloneIndividual);
            A.CallTo(() => _objectBaseFactory.Create <ImportPopulation>()).Returns(_createdPopulation);
            A.CallTo(() => _createdPopulation.IndividualPropertiesCache).Returns(A.Fake <IndividualPropertiesCache>());
            sut = new ImportPopulationFactory(_objectBaseFactory, _progressManager, _individualCacheImporter, _cloner, _containerTask, _advancedParameterFactory);

            A.CallTo(() => _containerTask.CacheAllChildren <IParameter>(_cloneIndividual)).Returns(_allParameters);
            A.CallTo(() => _containerTask.CacheAllChildrenSatisfying(_cloneIndividual, A <Func <IParameter, bool> > ._)).Returns(_allCreateIndividualParameters);

            _popFile1 = A.Fake <IndividualPropertiesCache>();
            _popFile2 = A.Fake <IndividualPropertiesCache>();
            A.CallTo(() => _individualCacheImporter.ImportFrom(_file1, _allParameters, A <IImportLogger> ._)).Returns(_popFile1);
            A.CallTo(() => _individualCacheImporter.ImportFrom(_file2, _allParameters, A <IImportLogger> ._)).Returns(_popFile2);

            return(_completed);
        }
        public Individual CreateBaseIndividualForPopulation(Individual originalIndividual)
        {
            //we need to create a new individual WITHOUT CKD and set all percentiles as in the original individuals. Other parameters, value wil be taken as is
            var originData = originalIndividual.OriginData.Clone();

            //remove the disease state to create a healthy Individual
            originData.DiseaseState = null;
            var healthyIndividual = _individualFactory.CreateAndOptimizeFor(originData, originalIndividual.Seed);

            var allCKDParameters = parametersChangedByCKDAlgorithmAsList(healthyIndividual);

            //Make sure we update the flags that might not be set coming from the database
            allCKDParameters.Each(x => x.IsChangedByCreateIndividual = true);

            //do not update parameters changed by CKD algorithm or that are not visible
            var allHealthyParameters  = _containerTask.CacheAllChildrenSatisfying <IParameter>(healthyIndividual, x => !allCKDParameters.Contains(x) && x.Visible);
            var allOriginalParameters = _containerTask.CacheAllChildren <IParameter>(originalIndividual);

            _parameterSetUpdater.UpdateValues(allOriginalParameters, allHealthyParameters);

            //we have a healthy individuals based on the CKD individual where all changes were all manual changes were accounted for
            //we now need to add the disease state contributions from the original individual
            originData.DiseaseState = originalIndividual.OriginData.DiseaseState;
            originalIndividual.OriginData.DiseaseStateParameters.Each(x => originData.AddDiseaseStateParameter(x.Clone()));

            return(healthyIndividual);
        }
Ejemplo n.º 3
0
        private void randomizeDistributedParameterIn(Individual individual)
        {
            //all distribued parameters in individual that are not standard parameters
            var allDistributedParameer = _containerTask.CacheAllChildrenSatisfying <IDistributedParameter>(
                individual, p => !CoreConstants.Parameter.StandardCreateIndividualParameters.Contains(p.Name));

            foreach (var parameter in allDistributedParameer)
            {
                parameter.Value = parameter.RandomDeviateIn(_randomGenerator);
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <ParameterScaling> AllParameterScalingsFrom(Individual originIndividual, Individual targetIndividual)
        {
            //only show parameter for scaling that are visble parameters
            var allTargetParameters = _containerTask.CacheAllChildren <IParameter>(targetIndividual);

            //default individul based on origin indivudal (used to retrieve default value)
            var allOriginParameters = _containerTask.CacheAllChildrenSatisfying <IParameter>(originIndividual, scalingAllowedFor);

            //return parameter scaling for all parameters existing in the source and target compartment
            return(from originParameter in allOriginParameters.KeyValues
                   let targetParameter = allTargetParameters[originParameter.Key]
                                         where scalingRequiredFor(originParameter.Value, targetParameter)
                                         select parameterScalingFor(originParameter.Value, targetParameter));
        }
Ejemplo n.º 5
0
        public async Task <ImportPopulation> CreateFor(IReadOnlyCollection <string> files, Individual individual, CancellationToken cancellationToken)
        {
            try
            {
                using (var progressUpdater = _progressManager.Create())
                {
                    var importPopulation = createPopulationFor(individual);
                    var popIndiviudal    = importPopulation.Settings.BaseIndividual;
                    _allParameters = _containerTask.CacheAllChildren <IParameter>(popIndiviudal);
                    _allCreateIndividualParameters = _containerTask.CacheAllChildrenSatisfying <IParameter>(popIndiviudal, x => x.IsChangedByCreateIndividual);

                    var settings = importPopulation.Settings;
                    progressUpdater.Initialize(files.Count, PKSimConstants.UI.CreatingPopulation);

                    //Create the new task and start the import using to list
                    var tasks = files.Select(f => importFiles(f, cancellationToken)).ToList();

                    // Add a loop to process the tasks one at a time until none remain.
                    while (tasks.Count > 0)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        // Identify the first task that completes.
                        var firstFinishedTask = await Task.WhenAny(tasks);

                        // Remove the selected task from the list so that you don't
                        // process it more than once.
                        tasks.Remove(firstFinishedTask);

                        // Await the completed task.
                        var importResult = await firstFinishedTask;

                        settings.AddFile(importResult.PopulationFile);
                        mergeImportedIndividualsInPopulation(importPopulation, importResult.IndividualValues);
                        progressUpdater.IncrementProgress();
                    }

                    //once all individuals have been imported, we need to create advanced parameters
                    createAdvancedParametersFor(importPopulation);
                    return(importPopulation);
                }
            }
            finally
            {
                _allCreateIndividualParameters.Clear();
                _allParameters.Clear();
            }
        }
Ejemplo n.º 6
0
        private void updateIsChangedByCreatedIndividualFlag(Individual individual)
        {
            var defaultHuman = _defaultIndividualRetriever.DefaultHuman();
            var allIsChangedByIndividualParameter = _containerTask.CacheAllChildrenSatisfying <IParameter>(defaultHuman, x => x.IsChangedByCreateIndividual);
            var allParameters = _containerTask.CacheAllChildren <IParameter>(individual);

            allIsChangedByIndividualParameter.KeyValues.Each(kv =>
            {
                var parameter = allParameters[kv.Key];
                //can be null for a new parameter added at some point in the future
                if (parameter != null)
                {
                    parameter.IsChangedByCreateIndividual = true;
                }
            });
        }
        private IReadOnlyList <string> parameterPathsToVaryFrom(SensitivityAnalysis sensitivityAnalysis)
        {
            var simulation = sensitivityAnalysis.Simulation;
            var constantParametersCache = _containerTask.CacheAllChildrenSatisfying <IParameter>(simulation.Model.Root, ParameterCanBeUsedForSensitivity);

            var allUsedParameterPaths = sensitivityAnalysis.ParameterPaths.Any()
            ? sensitivityAnalysis.ParameterPaths
            : _simulationAnalyzer.AllPathOfParametersUsedInSimulation(sensitivityAnalysis.Simulation);

            return(allUsedParameterPaths.Select(x => new
            {
                Parameter = constantParametersCache[x],
                Path = x
            })
                   .Where(x => x.Parameter != null)
                   .Select(x => x.Path).ToList());
        }
Ejemplo n.º 8
0
        private void convertCompound(Compound compound)
        {
            if (compound == null)
            {
                return;
            }

            var templateCompound = _compoundFactory.Create().WithName(compound.Name);
            var solubilityTable  = templateCompound.Parameter(CoreConstants.Parameters.SOLUBILITY_TABLE);

            compound.Add(_cloner.Clone(solubilityTable));

            var solubilityGroup = compound.ParameterAlternativeGroup(CoreConstants.Groups.COMPOUND_SOLUBILITY);

            solubilityGroup.AllAlternatives.Each(x => x.Add(_cloner.Clone(solubilityTable)));

            var templateParameterCache = _containerTask.CacheAllChildrenSatisfying <IParameter>(templateCompound, x => !x.IsDefault);
            var compoundParameterCache = _containerTask.CacheAllChildren <IParameter>(compound);

            foreach (var parameterPath in templateParameterCache.Keys)
            {
                setAsInput(compoundParameterCache[parameterPath]);
            }

            foreach (var templateAlternativeGroup in templateCompound.AllParameterAlternativeGroups())
            {
                var templateAlternative = templateAlternativeGroup.AllAlternatives.First();
                var compoundGroup       = compound.ParameterAlternativeGroup(templateAlternativeGroup.Name);
                foreach (var alternative in compoundGroup.AllAlternatives)
                {
                    updateIsInputStateByNameAndValue(alternative, templateAlternative);
                }
            }

            foreach (var process in compound.AllProcesses())
            {
                var templateProcess = _compoundProcessRepository.ProcessByName(process.InternalName);
                updateIsInputStateByNameAndValue(process, templateProcess);
            }

            _converted = true;
        }
Ejemplo n.º 9
0
        private IEnumerable <object> anatomyAndPhysiologyFor(Individual individual)
        {
            var report        = new List <object>();
            var allParameters = _containerTask.CacheAllChildrenSatisfying <IParameter>(individual, valueShouldBeExportedForAnatomy);

            if (!allParameters.Any())
            {
                report.Add(PKSimConstants.UI.Default);
                return(report);
            }

            var dataTable = new DataTable {
                TableName = PKSimConstants.UI.AnatomyAndPhysiology
            };

            dataTable.AddColumn(PKSimConstants.UI.Parameter);
            dataTable.AddColumn(PKSimConstants.UI.Value);
            dataTable.AddColumn(PKSimConstants.UI.DefaultValue);

            foreach (var parameter in allParameters)
            {
                var row = dataTable.NewRow();
                row[PKSimConstants.UI.Parameter]    = _fullPathDisplayResolver.FullPathFor(parameter);
                row[PKSimConstants.UI.Value]        = ParameterMessages.DisplayValueFor(parameter);
                row[PKSimConstants.UI.DefaultValue] = ParameterMessages.DisplayValueFor(parameter, parameter.DefaultValue.GetValueOrDefault(parameter.Value));

                dataTable.Rows.Add(row);
            }

            var table     = new Table(dataTable.DefaultView, new Text(dataTable.TableName));
            var reference = new Reference(table);
            var text      = new Text(PKSimConstants.UI.AnatomyAndPhysiologyText, reference);

            report.Add(text);
            report.Add(table);
            return(report);
        }
Ejemplo n.º 10
0
 private PathCache <IParameter> getAllCreateIndividualParametersFrom(Individual individual)
 {
     return(_containerTask.CacheAllChildrenSatisfying <IParameter>(individual, p => p.IsChangedByCreateIndividual));
 }
        public IndividualProperties MapFrom(Individual individual)
        {
            var pathCache = _containerTask.CacheAllChildrenSatisfying <IParameter>(individual, p => p.IsChangedByCreateIndividual);

            return(MapFrom(individual, pathCache));
        }
 private PathCache <IQuantity> allQuantitiesFrom(IMoBiSimulation simulation, bool includeAmounts)
 {
     return(_containerTask.CacheAllChildrenSatisfying <IQuantity>(simulation.Model.Root, x => QuantityIsSelectable(x, includeAmounts)));
 }
Ejemplo n.º 13
0
 public PathCache <TEntity> EntitiesFrom <TEntity>(IContainer container, Func <TEntity, bool> predicate) where TEntity : class, IEntity
 {
     return(_containerTask.CacheAllChildrenSatisfying(container, predicate));
 }