Example #1
0
        protected override async Task Context()
        {
            await base.Context();

            _project       = new PKSimProject();
            _newIndividual = new Individual
            {
                OriginData = new OriginData()
            };

            _newAgeRange = new ParameterRange {
                ParameterName = CoreConstants.Parameters.AGE
            };
            _newWeightRange = new ParameterRange {
                ParameterName = CoreConstants.Parameters.MEAN_WEIGHT
            };

            _snapshot = await sut.MapToSnapshot(_randomPopulationSettings);

            _snapshot.ProportionOfFemales = _proportionOfFemale;

            A.CallTo(() => _parameterRangeMapper.MapToModel(_snapshot.Age, A <ParameterRangeSnapshotContext> .That.Matches(x => x.ParameterRange == _newAgeRange))).Returns(_newAgeRange);
            A.CallTo(() => _parameterRangeMapper.MapToModel(_snapshot.Weight, A <ParameterRangeSnapshotContext> .That.Matches(x => x.ParameterRange == _newWeightRange))).Returns(_newWeightRange);
            A.CallTo(() => _individualMapper.MapToModel(_snapshotIndividual, _snapshotContext)).Returns(_newIndividual);

            _newDiseaseStateParameterRange = new ConstrainedParameterRange {
                ParameterName = _diseaseStateParameter.Name
            };

            _mappedSettings = new RandomPopulationSettings {
                BaseIndividual = _newIndividual
            };
            _mappedSettings.AddParameterRange(_newDiseaseStateParameterRange);
            A.CallTo(() => _populationSettingsMapper.MapFrom(_newIndividual)).Returns(_mappedSettings);
        }
        protected override Task Context()
        {
            _individualMapper         = A.Fake <IndividualMapper>();
            _parameterRangeMapper     = A.Fake <ParameterRangeMapper>();
            _genderRepository         = A.Fake <IGenderRepository>();
            _populationSettingsMapper = A.Fake <IIndividualToPopulationSettingsMapper>();
            sut = new RandomPopulationSettingsMapper(_parameterRangeMapper, _individualMapper, _populationSettingsMapper, _genderRepository);

            _ageParameterRange = new ConstrainedParameterRange {
                ParameterName = CoreConstants.Parameters.AGE
            };
            _weightParameterRange = new ParameterRange {
                ParameterName = CoreConstants.Parameters.MEAN_WEIGHT
            };

            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(null)).Returns((Snapshots.ParameterRange)null);
            _ageRangeSnapshot = new Snapshots.ParameterRange();
            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(_ageParameterRange)).Returns(_ageRangeSnapshot);

            _weightRangeSnapshot = new Snapshots.ParameterRange();
            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(_weightParameterRange)).Returns(_weightRangeSnapshot);


            _baseIndividual     = new Individual();
            _snapshotIndividual = new Snapshots.Individual();
            A.CallTo(() => _individualMapper.MapToSnapshot(_baseIndividual)).Returns(_snapshotIndividual);

            _randomPopulationSettings = new RandomPopulationSettings
            {
                NumberOfIndividuals = 10,
                BaseIndividual      = _baseIndividual
            };

            _randomPopulationSettings.AddParameterRange(_weightParameterRange);
            _randomPopulationSettings.AddParameterRange(_ageParameterRange);

            A.CallTo(() => _genderRepository.Female).Returns(new Gender {
                Id = "Female", Name = "Female"
            });
            A.CallTo(() => _genderRepository.Male).Returns(new Gender {
                Id = "Male", Name = "Male"
            });
            return(Task.FromResult(true));
        }
 protected override void Context()
 {
     base.Context();
     _individual = A.Fake <Individual>();
     A.CallTo(() => _individual.AvailableGenders()).Returns(new List <Gender> {
         _genderRepository.Male, _genderRepository.Female
     });
     _populationSettings                   = new RandomPopulationSettings();
     _batchPopSettings                     = new Batch.PopulationSettings();
     _batchPopSettings.Population          = "Population";
     _batchPopSettings.MinAge              = 25;
     _batchPopSettings.MaxAge              = 40;
     _batchPopSettings.MinGestationalAge   = 30;
     _batchPopSettings.MinHeight           = 10;
     _batchPopSettings.MaxHeight           = 20;
     _batchPopSettings.MinWeight           = double.NaN;
     _batchPopSettings.MaxWeight           = 40;
     _batchPopSettings.MinBMI              = 8;
     _batchPopSettings.MaxBMI              = double.NaN;
     _batchPopSettings.NumberOfIndividuals = 2589;
     _batchPopSettings.ProportionOfFemales = 40;
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.BMI
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.AGE
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.MEAN_HEIGHT
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.MEAN_WEIGHT
     });
     _populationSettings.AddGenderRatio(new GenderRatio {
         Gender = _genderRepository.Male
     });
     _populationSettings.AddGenderRatio(new GenderRatio {
         Gender = _genderRepository.Female
     });
     A.CallTo(() => _individualFactory.CreateStandardFor(A <OriginData> ._)).Returns(_individual);
     A.CallTo(() => _popSettingsMapper.MapFrom(_individual)).Returns(_populationSettings);
 }
Example #4
0
        protected override async Task Context()
        {
            await base.Context();

            _newIndividual = new Individual();
            _newAgeRange   = new ParameterRange {
                ParameterName = CoreConstants.Parameters.AGE
            };
            _newWeightRange = new ParameterRange {
                ParameterName = CoreConstants.Parameters.MEAN_WEIGHT
            };

            _snapshot = await sut.MapToSnapshot(_randomPopulationSettings);

            _snapshot.ProportionOfFemales = _proportionOfFemale;

            A.CallTo(() => _parameterRangeMapper.MapToModel(_snapshot.Age, A <ParameterRangeSnapshotContext> .That.Matches(x => x.ParameterRange == _newAgeRange))).Returns(_newAgeRange);
            A.CallTo(() => _parameterRangeMapper.MapToModel(_snapshot.Weight, A <ParameterRangeSnapshotContext> .That.Matches(x => x.ParameterRange == _newWeightRange))).Returns(_newWeightRange);
            A.CallTo(() => _individualMapper.MapToModel(_snapshotIndividual, _snapshotContext)).Returns(_newIndividual);

            _mappedSettings = new RandomPopulationSettings();
            A.CallTo(() => _populationSettingsMapper.MapFrom(_newIndividual)).Returns(_mappedSettings);
            _mappedSettings.AddParameterRange(_newAgeRange);
            _mappedSettings.AddParameterRange(_newWeightRange);

            _maleRatio = new GenderRatio
            {
                Gender = _genderRepository.Male,
                Ratio  = 50
            };

            _femaleRatio = new GenderRatio
            {
                Gender = _genderRepository.Female,
                Ratio  = 50
            };

            _mappedSettings.AddGenderRatio(_maleRatio);
            _mappedSettings.AddGenderRatio(_femaleRatio);

            _snapshot.DiseaseStateParameters = null;
        }
        public RandomPopulationSettings MapFrom(Individual individual)
        {
            //add age first
            var populationSettings = new RandomPopulationSettings();

            if (individual == null)
            {
                return(populationSettings);
            }

            var population = individual.OriginData.SpeciesPopulation;

            populationSettings.BaseIndividual      = individual;
            populationSettings.NumberOfIndividuals = CoreConstants.DEFAULT_NUMBER_OF_INDIVIDUALS_IN_POPULATION;
            int genderCount = individual.AvailableGenders().Count();

            foreach (var gender in individual.AvailableGenders())
            {
                populationSettings.AddGenderRatio(new GenderRatio {
                    Gender = gender, Ratio = 100 / genderCount
                });
            }

            if (population.IsAgeDependent)
            {
                var ageParameter = individual.Organism.Parameter(CoreConstants.Parameter.AGE);
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(ageParameter));
            }

            if (individual.IsPreterm)
            {
                var gestationalAgeParameter = individual.Organism.Parameter(CoreConstants.Parameter.GESTATIONAL_AGE);
                populationSettings.AddParameterRange(discretedParameterRangeFrom(gestationalAgeParameter, numericListOfValues(gestationalAgeParameter)));
            }

            if (population.IsHeightDependent)
            {
                var heightParameter = individual.Organism.Parameter(CoreConstants.Parameter.MEAN_HEIGHT);
                populationSettings.AddParameterRange(parameterRangeFrom(heightParameter));
            }

            var weightParameter = individual.Organism.Parameter(CoreConstants.Parameter.MEAN_WEIGHT);

            if (population.IsAgeDependent)
            {
                populationSettings.AddParameterRange(parameterRangeFrom(weightParameter));
            }
            else
            {
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(weightParameter));
            }

            if (population.IsHeightDependent)
            {
                var bmiParameter = individual.Organism.Parameter(CoreConstants.Parameter.BMI);
                populationSettings.AddParameterRange(parameterRangeFrom(bmiParameter));
            }
            return(populationSettings);
        }
        public RandomPopulationSettings MapFrom(Individual individual)
        {
            var populationSettings = new RandomPopulationSettings();

            if (individual == null)
            {
                return(populationSettings);
            }

            var population = individual.OriginData.Population;

            populationSettings.BaseIndividual      = individual;
            populationSettings.NumberOfIndividuals = CoreConstants.DEFAULT_NUMBER_OF_INDIVIDUALS_IN_POPULATION;

            var genderCount = individual.AvailableGenders.Count;

            foreach (var gender in individual.AvailableGenders)
            {
                populationSettings.AddGenderRatio(new GenderRatio {
                    Gender = gender, Ratio = 100 / genderCount
                });
            }

            var organism = individual.Organism;

            if (individual.IsAgeDependent)
            {
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(organism.Parameter(AGE)));
            }

            if (individual.IsPreterm)
            {
                var gestationalAgeParameter = organism.Parameter(GESTATIONAL_AGE);
                populationSettings.AddParameterRange(discreteParameterRangeFrom(gestationalAgeParameter, numericListOfValues(gestationalAgeParameter)));
            }

            var weightParameter = organism.Parameter(MEAN_WEIGHT);

            populationSettings.AddParameterRange(population.IsAgeDependent ? parameterRangeFrom(weightParameter) : constrainedParameterRangeFrom(weightParameter));

            if (population.IsHeightDependent)
            {
                populationSettings.AddParameterRange(parameterRangeFrom(organism.Parameter(MEAN_HEIGHT)));
                populationSettings.AddParameterRange(parameterRangeFrom(organism.Parameter(BMI)));
            }

            individual.OriginData.DiseaseStateParameters.Each(x =>
            {
                var parameter = individual.OriginData.DiseaseState.Parameter(x.Name);
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(parameter));
            });
            return(populationSettings);
        }
Example #7
0
        public RandomPopulationSettings MapFrom(PopulationSettingsDTO populationSettingsDTO)
        {
            var populationSettings = new RandomPopulationSettings();

            populationSettings.BaseIndividual      = _cloner.Clone(populationSettingsDTO.Individual);
            populationSettings.NumberOfIndividuals = populationSettingsDTO.NumberOfIndividuals.ConvertedTo <int>();

            //first add one gender with ration 100 for each available gender
            populationSettingsDTO.AvailableGenders().Each(g => populationSettings.AddGenderRatio(new GenderRatio {
                Gender = g, Ratio = 100
            }));

            //in case of multiple gender, adjust the ration according to the feamales proportion
            if (populationSettingsDTO.HasMultipleGenders)
            {
                populationSettings.GenderRatio(populationSettingsDTO.Female).Ratio = populationSettingsDTO.ProportionOfFemales;
                populationSettings.GenderRatio(populationSettingsDTO.Male).Ratio   = 100 - populationSettingsDTO.ProportionOfFemales;
            }

            populationSettingsDTO.Parameters.Each(p => populationSettings.AddParameterRange(p.ParameterRange));
            return(populationSettings);
        }
Example #8
0
        protected override Task Context()
        {
            _individualMapper         = A.Fake <IndividualMapper>();
            _parameterRangeMapper     = A.Fake <ParameterRangeMapper>();
            _genderRepository         = A.Fake <IGenderRepository>();
            _populationSettingsMapper = A.Fake <IIndividualToPopulationSettingsMapper>();
            _logger = A.Fake <IOSPSuiteLogger>();
            sut     = new RandomPopulationSettingsMapper(_parameterRangeMapper, _individualMapper, _populationSettingsMapper, _genderRepository, _logger);

            _ageParameterRange = new ConstrainedParameterRange {
                ParameterName = CoreConstants.Parameters.AGE
            };
            _weightParameterRange = new ParameterRange {
                ParameterName = CoreConstants.Parameters.MEAN_WEIGHT
            };

            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(null)).Returns((Snapshots.ParameterRange)null);
            _ageRangeSnapshot = new Snapshots.ParameterRange();
            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(_ageParameterRange)).Returns(_ageRangeSnapshot);

            _weightRangeSnapshot = new Snapshots.ParameterRange();
            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(_weightParameterRange)).Returns(_weightRangeSnapshot);


            _baseIndividual = new Individual
            {
                OriginData = new OriginData()
            };
            _diseaseStateParameter = new OriginDataParameter(10, "mg/kg", "DIS_STATE_PARAM");
            _baseIndividual.OriginData.AddDiseaseStateParameter(_diseaseStateParameter);

            _diseaseStateParameterRangeSnapshot = new Snapshots.ParameterRange();
            _diseaseStateParameterRange         = new ConstrainedParameterRange {
                ParameterName = _diseaseStateParameter.Name
            };
            A.CallTo(() => _parameterRangeMapper.MapToSnapshot(_diseaseStateParameterRange)).Returns(_diseaseStateParameterRangeSnapshot);


            _snapshotIndividual = new Snapshots.Individual();
            A.CallTo(() => _individualMapper.MapToSnapshot(_baseIndividual)).Returns(_snapshotIndividual);

            _randomPopulationSettings = new RandomPopulationSettings
            {
                NumberOfIndividuals = 10,
                BaseIndividual      = _baseIndividual
            };

            _randomPopulationSettings.AddParameterRange(_weightParameterRange);
            _randomPopulationSettings.AddParameterRange(_ageParameterRange);
            _randomPopulationSettings.AddParameterRange(_diseaseStateParameterRange);

            A.CallTo(() => _genderRepository.Female).Returns(new Gender {
                Id = "Female", Name = "Female"
            });
            A.CallTo(() => _genderRepository.Male).Returns(new Gender {
                Id = "Male", Name = "Male"
            });

            _project         = new PKSimProject();
            _snapshotContext = new SnapshotContext(_project, ProjectVersions.Current);
            return(Task.FromResult(true));
        }