Exemple #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);
        }
Exemple #2
0
        protected override void Context()
        {
            base.Context();
            _individualPropertiesCache = A.Fake <IndividualPropertiesCache>();
            _patchCache = new PathCacheForSpecs <IParameter>();
            var individualParameter = A.Fake <IParameter>();

            A.CallTo(() => individualParameter.IsChangedByCreateIndividual).Returns(true);
            _patchCache.Add("Path1", individualParameter);

            var advancedParameter = A.Fake <IParameter>();

            A.CallTo(() => advancedParameter.IsChangedByCreateIndividual).Returns(false);
            advancedParameter.CanBeVariedInPopulation = true;
            _patchCache.Add("PathAdvanced", advancedParameter);

            A.CallTo(() => _individualPropertiesCache.AllParameterPaths()).Returns(new[] { "Path1", "Path2", "PathAdvanced" });
            A.CallTo(() => _individualPropertiesCache.ParameterValuesFor("Path1")).Returns(_value1);
            A.CallTo(() => _individualPropertiesCache.ParameterValuesFor("Path2")).Returns(_value2);
            A.CallTo(() => _individualPropertiesCache.ParameterValuesFor("PathAdvanced")).Returns(_value3);
            _populationSimulation = A.Fake <PopulationSimulation>();
            _parameterValueCache  = A.Fake <ParameterValuesCache>();
            A.CallTo(() => _populationSimulation.ParameterValuesCache).Returns(_parameterValueCache);
            _mobiPopulation = A.Fake <MoBiPopulation>();
            A.CallTo(_simulationFactory).WithReturnType <PopulationSimulation>().Returns(_populationSimulation);
            A.CallTo(() => _objectBaseFactory.Create <MoBiPopulation>()).Returns(_mobiPopulation);
            A.CallTo(() => _individualPropertiesCacheImporter.ImportFrom(_populationFile, A <IImportLogger> ._)).Returns(_individualPropertiesCache);
            A.CallTo(() => _parameterRetriever.ParametersFrom(_populationSimulation)).Returns(_patchCache);

            _advancedParameterContainer = new AdvancedParameter();
            A.CallTo(() => _advancedParameterFactory.Create(advancedParameter, DistributionTypes.Unknown)).Returns(_advancedParameterContainer);
        }
Exemple #3
0
        private IndividualPropertiesCache createIndividualPropertiesFromCSV(CsvReader csv, string[] headers)
        {
            var individualPropertiesCache = new IndividualPropertiesCache();

            //first create a cache of all possible values
            var covariateCache    = new Cache <string, List <string> >();
            var parameterValues   = new Cache <string, List <double> >();
            int fieldCount        = csv.FieldCount;
            int indexIndividualId = 0;

            for (int i = 0; i < headers.Length; i++)
            {
                var header = headers[i];
                if (string.Equals(header, Constants.Population.INDIVIDUAL_ID_COLUMN))
                {
                    indexIndividualId = i;
                    continue;
                }

                if (entryRepresentsParameter(header))
                {
                    parameterValues[header] = new List <double>();
                }
                else
                {
                    covariateCache[header] = new List <string>();
                }
            }

            while (csv.ReadNextRecord())
            {
                for (int i = 0; i < fieldCount; i++)
                {
                    if (i == indexIndividualId)
                    {
                        continue;
                    }

                    var header = headers[i];
                    if (parameterValues.Contains(header))
                    {
                        parameterValues[header].Add(csv.DoubleAt(i));
                    }
                    else
                    {
                        covariateCache[header].Add(csv[i]);
                    }
                }
            }

            //now fill the property cache
            addCovariates(individualPropertiesCache, covariateCache);

            foreach (var parameterValue in parameterValues.KeyValues)
            {
                individualPropertiesCache.SetValues(parameterValue.Key, parameterValue.Value);
            }

            return(individualPropertiesCache);
        }
Exemple #4
0
 private void ensureCovariatesAreDefined(IndividualPropertiesCache individualPropertiesCache)
 {
     //this should ensure that the covariates were defined for the population. If not, the file does not have the accurate structure
     if (!individualPropertiesCache.AllCovariates.Any())
     {
         throw new PKSimException(PKSimConstants.Error.GenderAndOrPopulationMissingFromFile);
     }
 }
Exemple #5
0
        private void addCovariates(IndividualPropertiesCache individualPropertiesCache, string parameterPath, IEnumerable <double> values)
        {
            if (string.Equals(parameterPath, CoreConstants.Parameters.RACE_INDEX))
            {
                individualPropertiesCache.AddPopulations(values.Select(index => _populationRepository.FindByIndex((int)index)).ToList());
            }

            else if (string.Equals(parameterPath, CoreConstants.Parameters.GENDER))
            {
                individualPropertiesCache.AddGenders(values.Select(index => _genderRepository.FindByIndex((int)index)).ToList());
            }
        }
Exemple #6
0
        protected override void Context()
        {
            base.Context();
            _individualPropertiesCache = new IndividualPropertiesCache();
            _parameterValues           = new ParameterValues("A|Path|With|Unit [l]");
            _individualPropertiesCache.Add(_parameterValues);
            A.CallTo(() => _individualCacheImporter.ImportFrom(_file1, A <IImportLogger> ._)).Returns(_individualPropertiesCache);


            var pathCache = A.Fake <PathCache <IParameter> >();

            A.CallTo(() => pathCache.Contains("A|Path|With|Unit")).Returns(true);
            A.CallTo(() => _containerTask.CacheAllChildren <IParameter>(_cloneIndividual)).Returns(pathCache);
        }
Exemple #7
0
 private void addCovariates(IndividualPropertiesCache individualPropertiesCache, Cache <string, List <string> > covariateCache)
 {
     foreach (var covariate in covariateCache.KeyValues)
     {
         if (covariate.Key.IsOneOf(CoreConstants.Parameters.RACE_INDEX, CoreConstants.Parameters.GENDER))
         {
             addCovariates(individualPropertiesCache, covariate.Key, covariate.Value.Select(x => double.Parse(x, NumberFormatInfo.InvariantInfo)));
         }
         else
         {
             individualPropertiesCache.AddConvariate(covariate.Key, covariate.Value);
         }
     }
 }
        private void removeUnits(IndividualPropertiesCache individualValues, ParameterValues parameterValue, PathCache <IParameter> allParameters)
        {
            var parameterPath = parameterValue.ParameterPath;

            if (allParameters.Contains(parameterPath))
            {
                return;
            }

            var pathWithUnitsRemoved = importedPathWithUnitsRemoved(parameterPath);

            if (allParameters.Contains(pathWithUnitsRemoved))
            {
                individualValues.RenamePath(parameterPath, pathWithUnitsRemoved);
                parameterValue.ParameterPath = pathWithUnitsRemoved;
            }
        }
Exemple #9
0
 protected override void Context()
 {
     base.Context();
     _originalValueCache = A.Fake <ParameterValuesCache>();
     _parameterCache     = A.Fake <PathCache <IParameter> >();
     _cov1               = new IndividualCovariates();
     _cov2               = new IndividualCovariates();
     _cov3               = new IndividualCovariates();
     _cov4               = new IndividualCovariates();
     _cacheToMerge       = A.Fake <ParameterValuesCache>();
     _originalCovariates = new List <IndividualCovariates> {
         _cov1, _cov2
     };
     _covariatesToMerge = new List <IndividualCovariates> {
         _cov3, _cov4
     };
     sut = new IndividualPropertiesCache(_originalValueCache, _originalCovariates);
     _individualPropertiesCacheToMerge = new IndividualPropertiesCache(_cacheToMerge, _covariatesToMerge);
 }
Exemple #10
0
        private void loadOldCSVFormat(IndividualPropertiesCache individualPropertiesCache, CsvReader csv)
        {
            int fieldCount = csv.FieldCount;

            while (csv.ReadNextRecord())
            {
                var parameterPath = csv[PARAMETER_PATH];
                var values        = getValuesFrom(csv, fieldCount);

                if (entryRepresentsParameter(parameterPath))
                {
                    ensureCovariatesAreDefined(individualPropertiesCache);
                    individualPropertiesCache.SetValues(parameterPath, values);
                }
                else
                {
                    addCovariates(individualPropertiesCache, parameterPath, values);
                }
            }
        }
Exemple #11
0
        protected override void 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);

            _popFile1 = A.Fake <IndividualPropertiesCache>();
            _popFile2 = A.Fake <IndividualPropertiesCache>();
            A.CallTo(() => _individualCacheImporter.ImportFrom(_file1, A <IImportLogger> ._)).Returns(_popFile1);
            A.CallTo(() => _individualCacheImporter.ImportFrom(_file2, A <IImportLogger> ._)).Returns(_popFile2);
        }
Exemple #12
0
        private IndividualPropertiesCache individualPropertiesCacheFrom(string fileFullPath, IImportLogger logger, char delimiter)
        {
            var individualPropertiesCache = new IndividualPropertiesCache();

            using (var reader = new CsvReaderDisposer(fileFullPath, delimiter))
            {
                var csv     = reader.Csv;
                var headers = csv.GetFieldHeaders();
                if (headers.Contains(Constants.Population.INDIVIDUAL_ID_COLUMN))
                {
                    loadNewCSVFormat(individualPropertiesCache, csv, headers);
                }
                else
                {
                    loadOldCSVFormat(individualPropertiesCache, csv);
                    logger.AddWarning(PKSimConstants.Warning.PopulationFileIsUsingOldFormatAndWontBeSupportedInTheNextVersion);
                }
            }

            return(individualPropertiesCache);
        }
Exemple #13
0
 protected override void Because()
 {
     _results = sut.ImportFrom(DomainHelperForSpecs.PopulationFilePathFor("corrupt1"), _logger);
 }
Exemple #14
0
 protected override void Because()
 {
     _results = sut.ImportFrom(DomainHelperForSpecs.PopulationFilePathFor("pop_10_semi_colon"), _logger);
 }
Exemple #15
0
 protected override void Because()
 {
     _results = sut.ImportFrom(_fileName, _logger);
 }
Exemple #16
0
 protected override void Because()
 {
     _results = sut.ImportFrom(DomainHelperForSpecs.PopulationFilePathFor("new_format_with_comment"), _logger);
 }
 private IndividualPropertiesCache withPathsContainingUnitsUpdated(IndividualPropertiesCache individualPropertiesCache, PathCache <IParameter> allParameters)
 {
     individualPropertiesCache.AllParameterValues.ToList().Each(parameterValue => { removeUnits(individualPropertiesCache, parameterValue, allParameters); });
     return(individualPropertiesCache);
 }
 protected override void Because()
 {
     _results = sut.ImportFrom(DomainHelperForSpecs.PopulationFilePathFor("pop_10_old_format"), _allParameters, _logger);
 }
 protected override void Because()
 {
     _results = sut.ImportFrom(DomainHelperForSpecs.PopulationFilePathFor("path_with_units"), _allParameters, _logger);
 }