Пример #1
0
        private void updateAlternativeSelection(CompoundGroupSelection snapshotCompoundGroupSelection, ModelCompoundProperties compoundProperties)
        {
            var compoundGroupSelection = compoundProperties.CompoundGroupSelections.Find(x => x.GroupName == snapshotCompoundGroupSelection.GroupName);

            if (compoundGroupSelection == null)
            {
                _logger.AddError(PKSimConstants.Error.CompoundGroupNotFoundFor(snapshotCompoundGroupSelection.GroupName, compoundProperties.Compound.Name));
                return;
            }

            var alternativeGroup = compoundProperties.Compound.ParameterAlternativeGroup(snapshotCompoundGroupSelection.GroupName);

            if (alternativeGroup == null)
            {
                _logger.AddError(PKSimConstants.Error.CompoundGroupNotFoundFor(snapshotCompoundGroupSelection.GroupName, compoundProperties.Compound.Name));
                return;
            }

            var alternative = alternativeGroup.AlternativeByName(snapshotCompoundGroupSelection.AlternativeName);

            if (alternative == null)
            {
                _logger.AddError(PKSimConstants.Error.CompoundAlternativeNotFoundFor(snapshotCompoundGroupSelection.AlternativeName, alternativeGroup.DefaultAlternative?.Name, snapshotCompoundGroupSelection.GroupName, compoundProperties.Compound.Name));
                return;
            }

            compoundGroupSelection.AlternativeName = snapshotCompoundGroupSelection.AlternativeName;
        }
Пример #2
0
        public CompoundProperties MapFrom(Compound compound)
        {
            var compoundProperties = new CompoundProperties {
                Compound = compound
            };

            foreach (var category in _categoryRepository.All())
            {
                var compoundCalculationMethod = compound.CalculationMethodFor(category) ?? category.DefaultItem;
                compoundProperties.AddCalculationMethod(compoundCalculationMethod);
            }

            //update default mapping for alternatives in compound
            foreach (var alternativeGroup in compound.AllParameterAlternativeGroups())
            {
                var compoundGroupSelection = new CompoundGroupSelection {
                    AlternativeName = alternativeGroup.DefaultAlternative.Name, GroupName = alternativeGroup.Name
                };
                compoundProperties.AddCompoundGroupSelection(compoundGroupSelection);
            }

            return(compoundProperties);
        }
Пример #3
0
        private IParameter getParameterForAlternative(Compound compound, CompoundProperties compoundProperties, CompoundGroupSelection alternativeSelection)
        {
            if (compound == null)
            {
                return(null);
            }

            var alternativeGroup = compound.ParameterAlternativeGroup(alternativeSelection.GroupName);

            if (alternativeGroup == null)
            {
                return(null);
            }

            var alternative = alternativeGroup.AlternativeByName(alternativeSelection.AlternativeName);

            if (alternative == null)
            {
                return(null);
            }

            var parameter = alternative.AllVisibleParameters().FirstOrDefault();

            if (parameter == null)
            {
                return(null);
            }

            if (!CoreConstants.Groups.GroupsWithCalculatedAlternative.Contains(alternativeSelection.GroupName))
            {
                return(parameter);
            }

            //this is a calculated alternative. We need to retrieve the value depending on the selected lipophilicity
            IEnumerable <IParameter> allParameters;

            if (alternativeGroup.Name == CoreConstants.Groups.COMPOUND_PERMEABILITY)
            {
                allParameters = _compoundAlternativeTask.PermeabilityValuesFor(compound);
            }
            else
            {
                allParameters = _compoundAlternativeTask.IntestinalPermeabilityValuesFor(compound);
            }

            var lipophilicityName = compoundProperties.CompoundGroupSelections
                                    .Where(x => x.GroupName == CoreConstants.Groups.COMPOUND_LIPOPHILICITY)
                                    .Select(x => x.AlternativeName).FirstOrDefault();

            return(allParameters.FirstOrDefault(x => x.IsNamed(lipophilicityName)));
        }
Пример #4
0
        protected override Task Context()
        {
            _calculationMethodCacheMapper = A.Fake <CalculationMethodCacheMapper>();
            _processMappingMapper         = A.Fake <ProcessMappingMapper>();
            _logger  = A.Fake <ILogger>();
            _project = new PKSimProject();
            _calculationMethodSnapshot = new CalculationMethodCache();
            sut = new CompoundPropertiesMapper(_calculationMethodCacheMapper, _processMappingMapper, _logger);

            _compoundGroupSelectionOneAlternative = new CompoundGroupSelection
            {
                AlternativeName = "ALT1",
                GroupName       = "ALTERNATIVE_GROUP_1"
            };

            _compoundGroupSelectionTwoAlternatives = new CompoundGroupSelection
            {
                AlternativeName = "ALT2",
                GroupName       = "ALTERNATIVE_GROUP_2"
            };

            _compound = new Compound
            {
                Name = "COMP",
            };

            _protocol = new SimpleProtocol
            {
                Name = "PROTOCOL"
            };

            _parameterAlternativeGroupWithOneAlternative = new ParameterAlternativeGroup {
                Name = _compoundGroupSelectionOneAlternative.GroupName
            };
            _parameterAlternativeGroupWithTwoAlternatives = new ParameterAlternativeGroup {
                Name = _compoundGroupSelectionTwoAlternatives.GroupName
            };

            _parameterAlternativeGroupWithTwoAlternatives.AddAlternative(new ParameterAlternative {
                Name = "ALT1"
            });
            _parameterAlternativeGroupWithTwoAlternatives.AddAlternative(new ParameterAlternative {
                Name = "ALT2"
            });

            _compound.AddParameterAlternativeGroup(_parameterAlternativeGroupWithOneAlternative);
            _compound.AddParameterAlternativeGroup(_parameterAlternativeGroupWithTwoAlternatives);

            _compoundProperties = new Model.CompoundProperties();

            _compoundProperties.AddCompoundGroupSelection(_compoundGroupSelectionOneAlternative);
            _compoundProperties.AddCompoundGroupSelection(_compoundGroupSelectionTwoAlternatives);
            _compoundProperties.Compound = _compound;
            _enzymaticProcess            = new EnzymaticProcess {
                Name = "EnzymaticProcess"
            };
            _anotherEnzymaticProcess = new EnzymaticProcess {
                Name = "AnotherEnzymaticProcess", MoleculeName = "CYP3A4"
            };
            _specificBindingProcess = new SpecificBindingPartialProcess {
                Name = "SpecificBinding"
            };
            _gfrTransportProcess = new SystemicProcess {
                Name = "Transport", SystemicProcessType = SystemicProcessTypes.GFR
            };
            _hepaticEnzymaticProcess = new SystemicProcess {
                Name = "Plasma Clearance", SystemicProcessType = SystemicProcessTypes.Hepatic
            };
            _compound.AddProcess(_enzymaticProcess);
            _compound.AddProcess(_specificBindingProcess);
            _compound.AddProcess(_gfrTransportProcess);
            _compound.AddProcess(_hepaticEnzymaticProcess);

            _enzymaticPartialProcessSelection = new EnzymaticProcessSelection {
                ProcessName = _enzymaticProcess.Name
            };
            _noEnzymaticSystemicProcessSelection = new SystemicProcessSelection {
                ProcessType = SystemicProcessTypes.Hepatic
            };
            _specificBindingPartialProcessSelection = new ProcessSelection {
                ProcessName = _specificBindingProcess.Name
            };
            _transportSystemicProcessSelection = new SystemicProcessSelection {
                ProcessName = _gfrTransportProcess.Name, ProcessType = _gfrTransportProcess.SystemicProcessType,
            };
            _noEnzymaticPartialProcessSelection = new EnzymaticProcessSelection {
                MoleculeName = _anotherEnzymaticProcess.MoleculeName
            };
            _compoundProperties.Processes.MetabolizationSelection.AddPartialProcessSelection(_enzymaticPartialProcessSelection);
            _compoundProperties.Processes.MetabolizationSelection.AddPartialProcessSelection(_noEnzymaticPartialProcessSelection);
            _compoundProperties.Processes.MetabolizationSelection.AddSystemicProcessSelection(_noEnzymaticSystemicProcessSelection);
            _compoundProperties.Processes.SpecificBindingSelection.AddPartialProcessSelection(_specificBindingPartialProcessSelection);
            _compoundProperties.Processes.TransportAndExcretionSelection.AddSystemicProcessSelection(_transportSystemicProcessSelection);

            _snapshotProcess1 = new CompoundProcessSelection {
                Name = _enzymaticPartialProcessSelection.ProcessName
            };
            _snapshotProcess2 = new CompoundProcessSelection {
                Name = _specificBindingPartialProcessSelection.ProcessName
            };
            _snapshotProcess3 = new CompoundProcessSelection {
                Name = _transportSystemicProcessSelection.ProcessName
            };
            _snapshotProcess4 = new CompoundProcessSelection {
                SystemicProcessType = _noEnzymaticSystemicProcessSelection.ProcessType.SystemicProcessTypeId.ToString()
            };
            _snapshotProcess5 = new CompoundProcessSelection {
                MoleculeName = _noEnzymaticPartialProcessSelection.MoleculeName
            };

            _formulation = new Formulation
            {
                Id = "123456"
            };
            _compoundProperties.ProtocolProperties.Protocol = _protocol;
            _compoundProperties.ProtocolProperties.AddFormulationMapping(new FormulationMapping
            {
                FormulationKey        = "F1",
                TemplateFormulationId = _formulation.Id
            });

            _project.AddBuildingBlock(_formulation);
            A.CallTo(() => _calculationMethodCacheMapper.MapToSnapshot(_compoundProperties.CalculationMethodCache)).Returns(_calculationMethodSnapshot);
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_enzymaticPartialProcessSelection)).Returns(_snapshotProcess1);
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_specificBindingPartialProcessSelection)).Returns(_snapshotProcess2);
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_transportSystemicProcessSelection)).Returns(_snapshotProcess3);
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_noEnzymaticSystemicProcessSelection)).Returns(_snapshotProcess4);
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_noEnzymaticPartialProcessSelection)).Returns(_snapshotProcess5);

            A.CallTo(() => _processMappingMapper.MapToModel(_snapshotProcess1, _enzymaticProcess)).Returns(_enzymaticPartialProcessSelection);
            A.CallTo(() => _processMappingMapper.MapToModel(_snapshotProcess2, _specificBindingProcess)).Returns(_specificBindingPartialProcessSelection);
            A.CallTo(() => _processMappingMapper.MapToModel(_snapshotProcess3, _gfrTransportProcess)).Returns(_transportSystemicProcessSelection);
            A.CallTo(() => _processMappingMapper.MapToModel(_snapshotProcess4, A <NotSelectedSystemicProcess> ._)).Returns(_noEnzymaticSystemicProcessSelection);
            A.CallTo(() => _processMappingMapper.MapToModel(_snapshotProcess5, A <EnzymaticProcess> ._)).Returns(_noEnzymaticPartialProcessSelection);

            return(_completed);
        }