private void setDefaultOntogeny(IndividualMolecule molecule, TSimulationSubject simulationSubject, string moleculeName)
        {
            var ontogeny = _ontogenyRepository.AllFor(simulationSubject.Species.Name).FindByName(moleculeName);

            if (ontogeny == null)
            {
                return;
            }
            _ontogenyTask.SetOntogenyForMolecule(molecule, ontogeny, simulationSubject);
        }
 public NormalizeRelativeExpressionCommand(IndividualMolecule molecule, ISimulationSubject simulationSubject, IExecutionContext context)
 {
     _molecule          = molecule;
     _simulationSubject = simulationSubject;
     CommandType        = PKSimConstants.Command.CommandTypeEdit;
     ObjectType         = context.TypeFor(molecule);
     _moleculeId        = molecule.Id;
     //This command is necessary to insure consistency but does not need to be seen
     Visible = false;
 }
Esempio n. 3
0
        public RemoveMoleculeFromPopulationCommand(IndividualMolecule molecule, Population population, IExecutionContext context)
        {
            _molecule       = molecule;
            _population     = population;
            BuildingBlockId = population.Id;

            CommandType = PKSimConstants.Command.CommandTypeDelete;
            ObjectType  = context.TypeFor(molecule);
            Description = PKSimConstants.Command.RemoveEntityFromContainer(ObjectType, molecule.Name, context.TypeFor(population), population.Name);
            context.UpdateBuildingBlockPropertiesInCommand(this, population);
        }
Esempio n. 4
0
        private void setDefaultSettingsForTransporter(IndividualMolecule molecule, TSimulationSubject simulationSubject, string moleculeName)
        {
            var transporter = molecule as IndividualTransporter;

            if (transporter == null)
            {
                return;
            }

            _transportContainerUpdater.SetDefaultSettingsForTransporter(transporter, simulationSubject.Species.Name, moleculeName);
        }
Esempio n. 5
0
        public void RemoveMolecule(IndividualMolecule molecule)
        {
            var viewResult = _dialogCreator.MessageBoxYesNo(PKSimConstants.UI.ReallyDeleteProtein(_entityTask.TypeFor(molecule), molecule.Name));

            if (viewResult == ViewResult.No)
            {
                return;
            }

            AddCommand(_moleculeExpressionTask.RemoveMoleculeFrom(molecule, _simulationSubject));
        }
        public IEnumerable <IContainer> AllContainersFor(Organism organism, IndividualMolecule molecule)
        {
            var allContainers           = AllOrganismContainers(organism).ToList();
            var allContainersForProtein = new List <IContainer>();

            foreach (var expressionContainer in molecule.AllExpressionsContainers())
            {
                allContainersForProtein.AddRange(allContainersFor(organism, molecule, allContainers, expressionContainer));
            }
            return(allContainersForProtein.Distinct());
        }
Esempio n. 7
0
        private void setDefaultOntogeny(IndividualMolecule molecule, Individual individual, string moleculeName)
        {
            var ontogeny = _ontogenyRepository.AllFor(individual.Species.Name).FindByName(moleculeName);

            if (ontogeny == null)
            {
                return;
            }

            _ontogenyTask.SetOntogenyForMolecule(molecule, ontogeny, individual);
        }
Esempio n. 8
0
        private void synchronizeExpressionProfiles(IndividualMolecule sourceMolecule, ISimulationSubject sourceSimulationSubject, IndividualMolecule targetMolecule, ISimulationSubject targetSimulationSubject, bool updateParameterOriginId)
        {
            //Global settings for molecule
            updateGlobalMoleculeSettings(sourceMolecule, targetMolecule, targetSimulationSubject);

            //All molecule parameters
            updateMoleculeParameters(sourceMolecule, sourceSimulationSubject, targetMolecule, targetSimulationSubject, updateParameterOriginId);

            //Molecule containers
            updateTransporterDirections(sourceMolecule, sourceSimulationSubject, targetMolecule, targetSimulationSubject);
        }
        public EditIndividualMoleculeExpressionInSimulationSubjectFromQueryCommand(IndividualMolecule molecule, QueryExpressionResults queryExpressionResults, ISimulationSubject simulationSubject)
        {
            _molecule = molecule;
            _queryExpressionResults = queryExpressionResults;
            _simulationSubject      = simulationSubject;
            CommandType             = PKSimConstants.Command.CommandTypeEdit;
            var containerName = string.IsNullOrEmpty(simulationSubject.Name) ? CoreConstants.ContainerName.NameTemplate : simulationSubject.Name;

            Description         = PKSimConstants.Command.AddEntityToContainer(ObjectType, molecule.Name, PKSimConstants.ObjectTypes.Individual, containerName);
            ExtendedDescription = queryExpressionResults.Description;
        }
Esempio n. 10
0
 private static void validateZoneValues(IndividualMolecule molecule)
 {
     CoreConstants.Compartment.LiverZones.Each(z =>
     {
         var expressionContainer = molecule.ExpressionContainer(z);
         expressionContainer.OrganPath.PathAsString.ShouldBeEqualTo(new[] { Constants.ORGANISM, CoreConstants.Organ.Liver, z }.ToPathString());
         expressionContainer.RelativeExpression.ShouldBeEqualTo(10);
         expressionContainer.RelativeExpressionNorm.ShouldBeEqualTo(1);
         expressionContainer.ContainerName = z;
     });
 }
Esempio n. 11
0
        public RemoveMoleculeFromIndividualCommand(IndividualMolecule molecule, Individual individual, IExecutionContext context)
        {
            _molecule       = molecule;
            _individual     = individual;
            BuildingBlockId = individual.Id;

            CommandType = PKSimConstants.Command.CommandTypeDelete;
            ObjectType  = context.TypeFor(molecule);
            Description = PKSimConstants.Command.RemoveEntityFromContainer(ObjectType, molecule.Name, context.TypeFor(individual), individual.Name);
            context.UpdateBuildingBlockPropertiesInCommand(this, individual);
        }
Esempio n. 12
0
 private ICommand addMoleculeToPopulation(IndividualMolecule molecule, Population population, ICommand <IExecutionContext> baseCommand)
 {
     return(macroCommandFrom(population,
                             baseCommand,
                             new[]
     {
         baseCommand.Run(_executionContext),
         _moleculeParameterVariabilityCreator.AddMoleculeVariability(molecule, population, usePredefinedMeanVariability: true)
     }
                             ));
 }
        protected override void Context()
        {
            _individual                    = new Individual();
            _individual.OriginData         = new OriginData();
            _individual.OriginData.Species = new Species().WithName("Human");
            _ontogeny = new DatabaseOntogeny {
                Name = "toto"
            };
            _molecule = new IndividualEnzyme {
                Name = "CYP3A4"
            };
            _executionContext                  = A.Fake <IExecutionContext>();
            _proteinExpressionPresenter        = A.Fake <IProteinExpressionsPresenter>();
            _simpleMoleculePresenter           = A.Fake <ISimpleMoleculePresenter>();
            _querySettingsMapper               = A.Fake <IMoleculeToQueryExpressionSettingsMapper>();
            _applicationController             = A.Fake <IApplicationController>();
            _individualMoleculeFactoryResolver = A.Fake <IIndividualMoleculeFactoryResolver>();
            _transportContainerUpdater         = A.Fake <ITransportContainerUpdater>();
            _containerTask = A.Fake <IContainerTask>();
            _moleculeParameterRepository    = A.Fake <IMoleculeParameterRepository>();
            _proteinExpressionDbPathManager = A.Fake <IProteinExpressionsDatabasePathManager>();
            A.CallTo(() => _applicationController.Start <IProteinExpressionsPresenter>()).Returns(_proteinExpressionPresenter);
            A.CallTo(() => _applicationController.Start <ISimpleMoleculePresenter>()).Returns(_simpleMoleculePresenter);
            _ontogenyRepository = A.Fake <IOntogenyRepository>();
            var proteinFactory = A.Fake <IIndividualMoleculeFactory>();

            _moleculeContainer1 = new MoleculeExpressionContainer().WithName("C1");
            _moleculeContainer1.Add(DomainHelperForSpecs.ConstantParameterWithValue(5).WithName(CoreConstants.Parameter.RelExp));
            _moleculeContainer1.Add(DomainHelperForSpecs.ConstantParameterWithValue(1).WithName(CoreConstants.Parameter.RelExpNorm));
            _moleculeContainer2 = new MoleculeExpressionContainer().WithName("C2");
            _moleculeContainer2.Add(DomainHelperForSpecs.ConstantParameterWithValue(5).WithName(CoreConstants.Parameter.RelExp));
            _moleculeContainer2.Add(DomainHelperForSpecs.ConstantParameterWithValue(1).WithName(CoreConstants.Parameter.RelExpNorm));
            A.CallTo(() => _individualMoleculeFactoryResolver.FactoryFor <IndividualProtein>()).Returns(proteinFactory);
            A.CallTo(() => proteinFactory.CreateFor(_individual)).Returns(_molecule);
            _molecule.Add(_moleculeContainer1);
            _molecule.Add(_moleculeContainer2);
            _molecule.Add(DomainHelperForSpecs.ConstantParameterWithValue(10).WithName(CoreConstants.Parameter.REFERENCE_CONCENTRATION));
            _molecule.Add(DomainHelperForSpecs.ConstantParameterWithValue(20).WithName(CoreConstants.Parameter.HALF_LIFE_LIVER));
            _molecule.Add(DomainHelperForSpecs.ConstantParameterWithValue(30).WithName(CoreConstants.Parameter.HALF_LIFE_INTESTINE));

            A.CallTo(() => _ontogenyRepository.AllFor(_individual.Species.Name)).Returns(new[] { _ontogeny, new DatabaseOntogeny {
                                                                                                     Name = "tralala"
                                                                                                 }, });
            A.CallTo(() => _executionContext.Resolve <IOntogenyRepository>()).Returns(_ontogenyRepository);

            _subjectExpressionTask = new IndividualExpressionTask(_executionContext);

            _ontogenyTask = A.Fake <IOntogenyTask <Individual> >();
            sut           = new MoleculeExpressionTask <Individual>(_applicationController, _executionContext,
                                                                    _individualMoleculeFactoryResolver, _querySettingsMapper,
                                                                    _containerTask, _proteinExpressionDbPathManager,
                                                                    _ontogenyRepository, _transportContainerUpdater, _moleculeParameterRepository, _subjectExpressionTask, _ontogenyTask);
        }
        public MoleculePropertiesDTO MapFrom(IndividualMolecule molecule)
        {
            var dto = new MoleculePropertiesDTO(molecule)
            {
                MoleculeType = _objectTypeResolver.TypeFor(molecule)
            };

            dto.ReferenceConcentrationParameter = _parameterMapper.MapFrom(molecule.ReferenceConcentration, dto, x => x.ReferenceConcentration, x => x.ReferenceConcentrationParameter);
            dto.HalfLifeLiverParameter          = _parameterMapper.MapFrom(molecule.HalfLifeLiver, dto, x => x.HalfLifeLiver, x => x.HalfLifeLiverParameter);
            dto.HalfLifeIntestineParameter      = _parameterMapper.MapFrom(molecule.HalfLifeIntestine, dto, x => x.HalfLifeIntestine, x => x.HalfLifeIntestineParameter);
            return(dto);
        }
        private void setParameterValuesForStandardContainer(IndividualMolecule molecule, IContainer expressionContainer)
        {
            var containerName  = relativeExpressionContainerNameFrom(molecule, expressionContainer);
            var relExpNormPath = relExpNormPathFor(molecule, expressionContainer);
            var relExpPath     = relExpPathFor(molecule, expressionContainer);

            trySetValue(relExpNormPath, molecule.GetRelativeExpressionNormParameterFor(containerName));
            trySetValue(relExpPath, molecule.GetRelativeExpressionParameterFor(containerName));
            var relExpOut = relExpOutPathFor(molecule, expressionContainer);

            trySetFormula(relExpOut, CoreConstants.Rate.RelExpOutFromNorm);
        }
Esempio n. 16
0
 protected override void Context()
 {
     base.Context();
     _allParameters.Clear();
     _allParameters.Add(_para1);
     _individual         = new Individual().WithName("toto");
     _individualMolecule = new IndividualEnzyme();
     _para1.Name         = CoreConstants.Parameters.REFERENCE_CONCENTRATION;
     _individualMolecule.Add(_para1);
     _individualMolecule.Name = "CYP3A4";
     _individual.AddMolecule(_individualMolecule);
 }
Esempio n. 17
0
 protected override void Context()
 {
     base.Context();
     _molecule   = new IndividualEnzyme();
     _population = new RandomPopulation {
         Settings = new RandomPopulationSettings {
             BaseIndividual = new Individual()
         }
     };
     _addVariabilityCommand = A.Fake <IPKSimCommand>();
     A.CallTo(_moleculeParameterVariabilityCreator).WithReturnType <ICommand>().Returns(_addVariabilityCommand);
 }
      private ICommand addParameterVariability(IndividualMolecule individualMolecule, IParameter parameter, Population population, bool usePredefinedMeanVariability)
      {
         var predefinedVariability = _moleculeParameterRepository.ParameterFor(individualMolecule.Name, parameter.Name);
         if (predefinedVariability == null)
            return new PKSimEmptyCommand();

         var advancedParameter = _advancedParameterFactory.Create(parameter, predefinedVariability.Formula.DistributionType());
         advancedParameter.DistributedParameter.MeanParameter.Value = usePredefinedMeanVariability ? predefinedVariability.MeanParameter.Value : parameter.Value;
         advancedParameter.DistributedParameter.DeviationParameter.Value = predefinedVariability.DeviationParameter.Value;

         return _advancedParametersTask.AddAdvancedParameter(advancedParameter, population);
      }
 protected override void Context()
 {
     base.Context();
     _clonedProtein = A.Fake <IndividualMolecule>();
     A.CallTo(() => _clonedProtein.AllExpressionsContainers()).Returns(_molecule.AllExpressionsContainers());
     _individual.AddMolecule(_molecule);
     _querySettings = A.Fake <QueryExpressionSettings>();
     _queryResults  = A.Fake <QueryExpressionResults>();
     A.CallTo(() => _executionContext.Clone(_molecule)).Returns(_clonedProtein);
     A.CallTo(() => _querySettingsMapper.MapFrom(_molecule)).Returns(_querySettings);
     A.CallTo(() => _proteinExpressionPresenter.Start()).Returns(true);
     A.CallTo(() => _proteinExpressionPresenter.GetQueryResults()).Returns(_queryResults);
 }
        protected override void Context()
        {
            _molecule = new IndividualEnzyme
            {
                DomainHelperForSpecs.ConstantParameterWithValue(0).WithName(CoreConstants.Parameters.ONTOGENY_FACTOR),
                DomainHelperForSpecs.ConstantParameterWithValue(0).WithName(CoreConstants.Parameters.ONTOGENY_FACTOR_GI)
            };

            _ontogeny           = new DatabaseOntogeny();
            _ontogenyRepository = A.Fake <IOntogenyRepository>();
            _entityPathResolver = new EntityPathResolverForSpecs();
            sut = new MoleculeOntogenyVariabilityUpdater(_ontogenyRepository, _entityPathResolver);
        }
Esempio n. 21
0
        public ICommand RemoveMoleculeFrom(IndividualMolecule molecule, Population population)
        {
            var removeMoleculeCommand = new RemoveMoleculeFromPopulationCommand(molecule, population, _executionContext);
            var command = macroCommandFrom(population,
                                           removeMoleculeCommand,
                                           new[]
            {
                removeAdvancedParametersForMolecule(molecule, population),
                removeMoleculeCommand.Run(_executionContext)
            }
                                           );

            return(command);
        }
Esempio n. 22
0
        private void convertIndividualProtein(IndividualMolecule moleculeToConvert, IndividualMolecule newMolecule, Individual individual)
        {
            var proteinToConvert = moleculeToConvert as IndividualProtein;
            var newProtein       = newMolecule as IndividualProtein;

            if (proteinToConvert == null || newProtein == null)
            {
                return;
            }

            //Set set it first to none to ensure that it is set properly after reading from the snapshot file
            newProtein.Localization = Localization.None;
            _moleculeExpressionTask.SetExpressionLocalizationFor(newProtein, proteinToConvert.Localization, individual);
        }
Esempio n. 23
0
        private void addMolecule(IndividualMolecule individualMolecule)
        {
            var molecule = _moleculeBuilderFactory.Create(individualMolecule.MoleculeType, _moleculeBuildingBlock.FormulaCache)
                           .WithName(individualMolecule.Name)
                           .WithIcon(individualMolecule.Icon);

            addMoleculeToBuildingBlock(molecule, null);

            //Update protein builder parameters with the parameter ids
            _parameterSetUpdater.UpdateValuesByName(individualMolecule, molecule.Parameters);

            //Update the building block ids
            _parameterIdUpdater.UpdateBuildingBlockId(molecule.Parameters, _individual);
        }
Esempio n. 24
0
        private void updateDatabaseQueryStringToLiverZones(IndividualMolecule molecule)
        {
            var dataset = new DataSet();

            var rootElement = XElement.Load(new StringReader(molecule.QueryConfiguration));
            var expressionDataSetElement = rootElement.Element(CoreConstants.Serialization.ExpressionDataSet);

            if (expressionDataSetElement == null)
            {
                return;
            }

            dataset.ReadFromXmlString(expressionDataSetElement.Value);

            var mappingTable = dataset.Tables[DatabaseConfiguration.TableNames.MAPPING_DATA];

            if (mappingTable == null)
            {
                return;
            }

            var periporalRows = new List <DataRow>();

            //We find the old mapping for the organ liver
            foreach (DataRow row in mappingTable.Rows)
            {
                if (row[DatabaseConfiguration.MappingColumns.COL_CONTAINER].ToString() == CoreConstants.Organ.Liver)
                {
                    //store a new row for Periportal that will be added in the mapping
                    var periportalRow = mappingTable.NewRow();
                    periportalRow[DatabaseConfiguration.MappingColumns.COL_CONTAINER] = CoreConstants.Compartment.Periportal;
                    periportalRow[DatabaseConfiguration.MappingColumns.COL_TISSUE]    = row[DatabaseConfiguration.MappingColumns.COL_TISSUE];

                    //this becomes now pericentral
                    row[DatabaseConfiguration.MappingColumns.COL_CONTAINER] = CoreConstants.Compartment.Pericentral;

                    periporalRows.Add(periportalRow);
                }
            }

            //add after the first iteration to avoid enumerating and changing the enumeration at the same time
            foreach (var row in periporalRows)
            {
                mappingTable.Rows.Add(row);
            }

            expressionDataSetElement.Value = dataset.SaveToXmlString();
            molecule.QueryConfiguration    = rootElement.ToString(SaveOptions.DisableFormatting);
        }
        protected SetOntogenyInMoleculeCommand(IndividualMolecule molecule, Ontogeny newOntogeny, TSimulationSubject simulationSubject, IExecutionContext context)
        {
            _molecule          = molecule;
            _oldOntogeny       = molecule.Ontogeny ?? new NullOntogeny();
            _newOntogeny       = newOntogeny ?? new NullOntogeny();
            _moleculeId        = molecule.Id;
            _simulationSubject = simulationSubject;
            BuildingBlockId    = simulationSubject.Id;
            ObjectType         = context.TypeFor(molecule);
            CommandType        = PKSimConstants.Command.CommandTypeEdit;
            var subjectName = string.IsNullOrEmpty(_simulationSubject.Name) ? CoreConstants.ContainerName.NameTemplate : _simulationSubject.Name;

            Description = PKSimConstants.Command.SetOntogenyInProteinDescription(subjectName, molecule.Name, _oldOntogeny.Name, _newOntogeny.Name);
            context.UpdateBuildinBlockProperties(this, simulationSubject);
        }
 public ICommand AddMoleculeVariability(IndividualMolecule molecule, Population population, bool usePredefinedMeanVariability)
 {
    var macroCommand = new PKSimMacroCommand(new[]
    {
       addParameterVariability(molecule, molecule.ReferenceConcentration, population, usePredefinedMeanVariability),
       addParameterVariability(molecule, molecule.HalfLifeLiver, population, usePredefinedMeanVariability),
       addParameterVariability(molecule, molecule.HalfLifeIntestine, population, usePredefinedMeanVariability)
    })
    {
       CommandType = PKSimConstants.Command.CommandTypeAdd,
       ObjectType = PKSimConstants.ObjectTypes.Population,
       Description = PKSimConstants.Command.AddDefaultVariabilityToPopulation(population.Name)
    };
    _executionContext.UpdateBuildingBlockPropertiesInCommand(macroCommand, population);
    return macroCommand;
 }
Esempio n. 27
0
 public override void GlobalContext()
 {
     base.GlobalContext();
     _withIdRepository    = IoC.Resolve <IWithIdRepository>();
     _simulation          = new IndividualSimulation().WithId("Sim");
     _simulation.IsLoaded = true;
     _withIdRepository.Register(_simulation);
     _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("Ind", PKSimBuildingBlockType.Individual)
     {
         BuildingBlock = DomainHelperForSpecs.CreateIndividual()
     });
     _transporter = new IndividualTransporter().WithName("Trans");
     _enzyme      = new IndividualEnzyme().WithName("Enz");
     _simulation.Individual.AddMolecule(_transporter);
     _simulation.Individual.AddMolecule(_enzyme);
 }
        public void UpdateMoleculeOntogeny(IndividualMolecule molecule, Ontogeny ontogeny, ISimulationSubject simulationSubject)
        {
            switch (simulationSubject)
            {
            case Individual individual:
                UpdateMoleculeOntogeny(molecule, ontogeny, individual);
                break;

            case Population population:
                UpdateMoleculeOntogeny(molecule, ontogeny, population);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(simulationSubject));
            }
        }
        public override void Execute(IExecutionContext context)
        {
            ObjectType = context.TypeFor(_molecule);
            var containerName = string.IsNullOrEmpty(_simulationSubject.Name) ? CoreConstants.ContainerName.NameTemplate : _simulationSubject.Name;

            Description = PKSimConstants.Command.AddEntityToContainer(ObjectType, _molecule.Name, context.TypeFor(_simulationSubject), containerName);


            var allExpressionParameters = _simulationSubject.AllExpressionParametersFor(_molecule);

            //Then update only the expression values that have changed
            foreach (var expressionResult in _queryExpressionResults.ExpressionResults)
            {
                var expressionParameter = allExpressionParameters[expressionResult.ContainerName];
                if (expressionParameter.Value == expressionResult.RelativeExpression)
                {
                    continue;
                }

                Add(new SetExpressionProfileValueCommand(expressionParameter, expressionResult.RelativeExpression, updateSimulationSubjects: false));
            }

            Add(new NormalizeRelativeExpressionCommand(_molecule, _simulationSubject, context));


            //update properties from first command
            this.UpdatePropertiesFrom(All().FirstOrDefault());

            //Execute the command first to update all relative expressions
            base.Execute(context);

            //special treatment for protein where we have to update localization after the fact
            if (_molecule is IndividualProtein protein)
            {
                updateLocalizationForProtein(protein, context);
            }

            // update depending object
            var updateTask = context.Resolve <IExpressionProfileUpdater>();

            updateTask.SynchronizeAllSimulationSubjectsWithExpressionProfile(_simulationSubject);

            //clear references
            _molecule = null;
            _queryExpressionResults = null;
            _simulationSubject      = null;
        }
Esempio n. 30
0
        private void updateMoleculePropertiesToMolecule(IndividualMolecule molecule, SnapshotExpressionProfile snapshot, ModelIndividual individual, SnapshotContext snapshotContext)
        {
            switch (molecule)
            {
            case IndividualProtein protein:
                var localization = retrieveLocalizationFrom(snapshot, snapshotContext);
                //Set set it first to none to ensure that it is set properly after reading from the snapshot file
                protein.Localization = Localization.None;
                _moleculeExpressionTask.SetExpressionLocalizationFor(protein, localization, individual);

                break;

            case IndividualTransporter transporter:
                _moleculeExpressionTask.SetTransporterTypeFor(transporter, ModelValueFor(snapshot.TransportType));
                break;
            }
        }