Beispiel #1
0
        public IPKSimBuildingBlock CreateCloneFor(IPKSimBuildingBlock buildingBlockToClone)
        {
            //This should never fail
            var expressionProfile = buildingBlockToClone.DowncastTo <ExpressionProfile>();

            var(molecule, _) = expressionProfile;
            _dto             = _expressionProfileDTOMapper.MapFrom(expressionProfile);
            _view.Caption    = Captions.CloneObjectBase(PKSimConstants.ObjectTypes.ExpressionProfile, buildingBlockToClone.Name);

            _view.BindTo(_dto);
            _view.Display();

            if (_view.Canceled)
            {
                return(null);
            }

            //create a new expression profile using the same molecule name as the original so that we can update the values. Then we rename
            var newExpressionProfile = _expressionProfileFactory.Create(molecule.MoleculeType, _dto.Species.Name, molecule.Name);

            newExpressionProfile.Category = _dto.Category;

            //synchronize values
            _expressionProfileUpdater.SynchronizeExpressionProfileWithExpressionProfile(expressionProfile, newExpressionProfile);

            //rename using the new name
            _expressionProfileUpdater.UpdateMoleculeName(newExpressionProfile, _dto.MoleculeName);

            return(newExpressionProfile);
        }
        public IPKSimCommand Create <TMolecule>() where TMolecule : IndividualMolecule
        {
            //Just for edit
            ExpressionProfile = _expressionProfileFactory.Create <TMolecule>();
            _dto          = _expressionProfileDTOMapper.MapFrom(ExpressionProfile);
            _view.Caption = PKSimConstants.UI.CreateExpressionProfile;
            _view.BindTo(_dto);
            _view.Display();
            if (_view.Canceled)
            {
                return(new PKSimEmptyCommand());
            }

            //we create a new one with all new features
            ExpressionProfile          = _expressionProfileFactory.Create <TMolecule>(_dto.Species, _dto.MoleculeName);
            ExpressionProfile.Category = _dto.Category;

            _moleculeParameterTask.SetDefaultFor(ExpressionProfile);

            //Action
            return(new PKSimMacroCommand());
        }
Beispiel #3
0
        protected override void Context()
        {
            _view = A.Fake <ICreateExpressionProfileView>();
            _expressionProfileFactory   = A.Fake <IExpressionProfileFactory>();
            _expressionProfileDTOMapper = A.Fake <IExpressionProfileToExpressionProfileDTOMapper>();
            _moleculeParameterTask      = A.Fake <IMoleculeParameterTask>();
            _dialogCreator = A.Fake <IDialogCreator>();
            sut            = new CreateExpressionProfilePresenter(_view, _expressionProfileFactory, _expressionProfileDTOMapper, _moleculeParameterTask, _dialogCreator);

            _expressionProfile        = DomainHelperForSpecs.CreateExpressionProfile <IndividualEnzyme>();
            _updatedExpressionProfile = DomainHelperForSpecs.CreateExpressionProfile <IndividualEnzyme>();
            _expressionProfileDTO     = new ExpressionProfileDTO
            {
                Species      = new Species(),
                MoleculeName = "TOTO"
            };

            A.CallTo(() => _expressionProfileFactory.Create <IndividualEnzyme>()).Returns(_expressionProfile);

            A.CallTo(() => _expressionProfileDTOMapper.MapFrom(_expressionProfile)).Returns(_expressionProfileDTO);

            A.CallTo(() => _expressionProfileFactory.Create <IndividualEnzyme>(_expressionProfileDTO.Species, _expressionProfileDTO.MoleculeName))
            .Returns(_updatedExpressionProfile);
        }
Beispiel #4
0
        public override async Task <ModelExpressionProfile> MapToModel(SnapshotExpressionProfile snapshot, SnapshotContext snapshotContext)
        {
            var expressionProfile = _expressionProfileFactory.Create(snapshot.Type, snapshot.Species, snapshot.Molecule);

            expressionProfile.Description = snapshot.Description;
            expressionProfile.Category    = snapshot.Category;

            var(molecule, individual) = expressionProfile;
            //Update molecule properties first
            updateMoleculePropertiesToMolecule(molecule, snapshot, individual, snapshotContext);

            //Then override all parameters that were set
            await _parameterMapper.MapLocalizedParameters(snapshot.Parameters, individual, snapshotContext, !snapshotContext.IsV9FormatOrEarlier);

            var snapshotWithSubjectContext = new SnapshotContextWithSubject(individual, snapshotContext);
            var ontogeny = await _ontogenyMapper.MapToModel(snapshot.Ontogeny, snapshotWithSubjectContext);

            _ontogenyTask.SetOntogenyForMolecule(molecule, ontogeny, individual);

            var context = new ExpressionContainerMapperContext(snapshotContext)
            {
                Molecule                     = molecule,
                ExpressionParameters         = individual.AllExpressionParametersFor(molecule),
                MoleculeExpressionContainers = individual.AllMoleculeContainersFor(molecule),
            };
            await _expressionContainerMapper.MapToModels(snapshot.Expression, context);

            //We need to normalize relative expressions when loading from old format
            if (snapshotContext.IsV9FormatOrEarlier)
            {
                //Make sure we load the default parameters from db just in case we were dealing with a standard molecule
                _moleculeParameterTask.SetDefaultMoleculeParameters(molecule);

                //Global parameters were saved directly under the snapshot parameter
                await updateGlobalMoleculeParameters(snapshot, molecule, snapshotContext);

                NormalizeRelativeExpressionCommand.NormalizeExpressions(individual, molecule);
            }

            return(expressionProfile);
        }
Beispiel #5
0
        private void addExpressionProfilesUsedBySimulationSubjectToProject(ISimulationSubject simulationSubject)
        {
            var project = _projectRetriever.Current;

            foreach (var molecule in simulationSubject.AllMolecules())
            {
                var defaultExpressionProfileName = CoreConstants.ContainerName.ExpressionProfileName(molecule.Name, simulationSubject.Species, simulationSubject.Name);

                var expressionProfileName = _containerTask.CreateUniqueName(project.All <ExpressionProfile>(), defaultExpressionProfileName, canUseBaseName: true);
                var expressionProfile     = _expressionProfileFactory.Create(molecule.GetType(), simulationSubject.Species, molecule.Name);

                //Use a unique name in project
                expressionProfile.Name = expressionProfileName;
                _expressionProfileUpdater.SynchronizeExpressionProfileWithSimulationSubject(expressionProfile, simulationSubject);

                //Some parameters are probably marked as FixedValue event thought they have not changed (Formula=>constant) due to change in
                //definition of Fraction expressed basolateral going from a constant to a formula. We reset is fixed value and default state
                expressionProfile.Individual.AllMoleculeParametersFor(expressionProfile.Molecule)
                .Where(x => !x.Visible)
                .Where(x => x.IsFixedValue)
                .Each(x => x.IsFixedValue = false);

                expressionProfile.Individual.AllMoleculeParametersFor(expressionProfile.Molecule)
                .Where(x => !x.Editable)
                .Where(x => !x.IsDefault)
                .Each(x => x.IsDefault = true);

                //only add at the end once the expression profile has been updated
                simulationSubject.AddExpressionProfile(expressionProfile);
                project.AddBuildingBlock(expressionProfile);
                _registrationTask.Register(expressionProfile);
                _eventPublisher.PublishEvent(new BuildingBlockAddedEvent(expressionProfile, _projectRetriever.Current));
            }

            _converted = true;
        }