public IBuildingBlock GetBuildingBlockFor(IObjectBase objectBase, IBuildingBlock buildingBlock)
        {
            try
            {
                var formula = objectBase as IFormula;

                if (formula != null)
                {
                    return(buildingBlockForFormula(formula, buildingBlock));
                }

                _entity = objectBase as IEntity;
                var allBuildingBlocks = _buildingBlockRepository.All();

                if (_entity == null)
                {
                    throw new ArgumentException(AppConstants.Exceptions.BuildingBlockNotFoundFor(objectBase));
                }

                //looking for the first building block containing the root container or the entity itself if null
                _entity = _entity.RootContainer ?? _entity;
                _found  = false;
                return(allBuildingBlocks.FirstOrDefault(containsEntity));
            }
            finally
            {
                _entity = null;
            }
        }
Exemple #2
0
        public void CreateBuildingBlock()
        {
            var buildingBlockTask = _container.Resolve <IBuildingBlockTask <TBuildingBlock> >();

            buildingBlockTask.AddToProject();
            Edit(_buildingBlockRepository.All <TBuildingBlock>().LastOrDefault());
        }
Exemple #3
0
        private void addPredefinedMoleculeValues(MetaDataCategory moleculeCategory)
        {
            addUndefinedValueTo(moleculeCategory);

            foreach (var existingCompound in _buildingBlockRepository.All <Compound>())
            {
                addInfoToCategory(moleculeCategory, existingCompound);
            }
        }
        public void UpdateMolWeightIn(DataRepository observedData)
        {
            var moleculeName = moleculeNameFrom(observedData);
            var compound     = _buildingBlockRepository.All <Compound>().FindByName(moleculeName);

            updateMolWeight(observedData, compound);
        }
Exemple #5
0
 protected override void Context()
 {
     _allBuildingBlocks       = new List <IPKSimBuildingBlock>();
     _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
     A.CallTo(() => _buildingBlockRepository.All()).Returns(_allBuildingBlocks);
     sut = new FormulationMappingDTOToFormulationMappingMapper(_buildingBlockRepository);
 }
        public ObservedDataFolderContextMenu(
            ITreeNode <RootNodeType> treeNode,
            IMenuBarItemRepository repository,
            IBuildingBlockRepository buildingBlockRepository,
            IBuildingBlockExplorerPresenter presenter,
            IUserSettings userSettings)
        {
            var allCompounds = buildingBlockRepository.All <Compound>().ToList();

            //create sub menu containing all compounds
            var addObservedDataFor = CreateSubMenu.WithCaption(PKSimConstants.MenuNames.AddObservedDataFor)
                                     .WithIcon(ApplicationIcons.ObservedDataForMolecule);


            foreach (var compound in allCompounds)
            {
                addObservedDataFor.AddItem(CreateMenuButton.WithCaption(compound.Name)
                                           .WithCommandFor <AddObservedDataForCompoundUICommand, Compound>(compound));
            }

            _view.AddMenuItem(repository[MenuBarItemIds.AddObservedData]);
            if (allCompounds.Any())
            {
                _view.AddMenuItem(addObservedDataFor);
            }

            if (treeNode.HasChildren)
            {
                _view.AddMenuItem(ObservedDataClassificationCommonContextMenuItems.ColorGroupObservedData(userSettings));
            }


            _view.AddMenuItem(CreateMenuButton.WithCaption(PKSimConstants.MenuNames.LoadFromTemplate)
                              .WithCommand <LoadObservedDataFromTemplateUICommand>()
                              .WithIcon(ApplicationIcons.LoadFromTemplate)
                              .AsGroupStarter());

            _view.AddMenuItem(CreateMenuButton.WithCaption(PKSimConstants.MenuNames.AsDeveloperOnly("Load from Snapshot"))
                              .WithCommand <LoadObservedDataFromSnapshotUICommand>()
                              .WithIcon(ApplicationIcons.SnapshotImport)
                              .ForDeveloper());


            if (treeNode.AllLeafNodes.OfType <ObservedDataNode>().Any())
            {
                _view.AddMenuItem(ObservedDataClassificationCommonContextMenuItems.EditMultipleMetaData(treeNode).AsGroupStarter());
            }


            _view.AddMenuItem(ClassificationCommonContextMenuItems.CreateClassificationUnderMenu(treeNode, presenter));

            var groupMenu = createGroupingSubMenu(treeNode, presenter);

            if (groupMenu.AllItems().Any())
            {
                _view.AddMenuItem(groupMenu);
            }

            _view.AddMenuItem(createDeleteSubMenu(treeNode, presenter));
        }
Exemple #7
0
 private void refreshExpressionProfilesForMolecule()
 {
     _allExpressionProfilesForMoleculeType = _buildingBlockRepository.All <ExpressionProfile>(canSelect);
     _view.RefreshList();
     //Pre selection
     _expressionProfileSelectionDTO.ExpressionProfile = _allExpressionProfilesForMoleculeType.FirstOrDefault();
 }
        protected override void Context()
        {
            _view = A.Fake <IExpressionProfileSelectionView>();
            _moleculePropertiesMapper = A.Fake <IMoleculePropertiesMapper>();
            _buildingBlockRepository  = A.Fake <IBuildingBlockRepository>();
            _expressionProfileTask    = A.Fake <IExpressionProfileTask>();


            sut = new ExpressionProfileSelectionPresenter(_view, _moleculePropertiesMapper, _buildingBlockRepository, _expressionProfileTask);

            A.CallTo(() => _view.BindTo(A <ExpressionProfileSelectionDTO> ._))
            .Invokes(x => _dto = x.GetArgument <ExpressionProfileSelectionDTO>(0));

            _individual         = DomainHelperForSpecs.CreateIndividual(speciesName: "Human");
            _expressionProfile1 = DomainHelperForSpecs.CreateExpressionProfile <IndividualEnzyme>(speciesName: "Human");
            _expressionProfile2 = DomainHelperForSpecs.CreateExpressionProfile <IndividualEnzyme>(speciesName: "Human");
            _expressionProfile3 = DomainHelperForSpecs.CreateExpressionProfile <IndividualTransporter>(speciesName: "Human");
            _expressionProfile4 = DomainHelperForSpecs.CreateExpressionProfile <IndividualEnzyme>(speciesName: "Dog");
            _expressionProfile5 = DomainHelperForSpecs.CreateExpressionProfile <IndividualEnzyme>(speciesName: "Human");

            _allExpressionProfiles = new List <ExpressionProfile> {
                _expressionProfile1, _expressionProfile2
            };

            A.CallTo(() => _buildingBlockRepository.All(A <Func <ExpressionProfile, bool> > ._))
            .Invokes(x => _predicate = x.GetArgument <Func <ExpressionProfile, bool> >(0))
            .Returns(_allExpressionProfiles);

            _individual.AddExpressionProfile(_expressionProfile5);
        }
        private void bindToCompounds(IReadOnlyList <Compound> usedCompounds)
        {
            _compoundSelectionDTOs.Clear();
            var availableCompounds = _buildingBlockRepository.All <Compound>().Union(usedCompounds).OrderBy(x => x.Name).ToList();

            availableCompounds.Each(c => _compoundSelectionDTOs.Add(mapFrom(c, isSelected: shouldSelectCompoundByDefault(c, usedCompounds, availableCompounds))));
        }
 private IEnumerable <string> allPossibleMetabolites()
 {
     return(_buildingBlockRepository.All <Compound>()
            .Where(x => !Equals(_process.ParentCompound, x))
            .OrderBy(x => x.Name)
            .Select(x => x.Name));
 }
        private MetaDataCategory compoundNameCategory(Compound compound, bool canEditName)
        {
            var nameCategory = new MetaDataCategory
            {
                Name                = ObservedData.MOLECULE,
                DisplayName         = PKSimConstants.UI.Molecule,
                Description         = PKSimConstants.UI.MoleculeNameDescription,
                MetaDataType        = typeof(string),
                IsListOfValuesFixed = !canEditName,
                IsMandatory         = true,
            };

            foreach (var existingCompound in _buildingBlockRepository.All <Compound>())
            {
                nameCategory.ListOfValues.Add(existingCompound.Name, existingCompound.Name);
            }

            if (canEditName)
            {
                nameCategory.ListOfValues.Add(PKSimConstants.UI.Undefined, PKSimConstants.UI.Undefined);
            }

            if (compound != null)
            {
                nameCategory.DefaultValue = compound.Name;
            }

            return(nameCategory);
        }
Exemple #12
0
 protected override void Context()
 {
     _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
     sut = new BuildingBlockRetriever(_buildingBlockRepository);
     _allBuildingBlocks = new List <IBuildingBlock>();
     A.CallTo(() => _buildingBlockRepository.All()).Returns(_allBuildingBlocks);
 }
Exemple #13
0
 private IReadOnlyList <Compound> retrieveAllMetabolitesFor(Compound compound)
 {
     _buildingBlockTask.Load(compound);
     return(compound.AllProcesses <EnzymaticProcess>()
            .Select(x => x.MetaboliteName).Distinct()
            .Select(metaboliteName => _buildingBlockRepository.All <Compound>().FindByName(metaboliteName))
            .Where(x => x != null).ToList());
 }
        private bool simulationsAreUsingAlternative(ParameterAlternative alternative)
        {
            var allCompoundGroupSelectionForAlternativeGroup = _buildingBlockRepository.All <Simulation>()
                                                               .SelectMany(x => x.CompoundPropertiesList)
                                                               .SelectMany(x => x.CompoundGroupSelections
                                                                           .Where(groupSel => string.Equals(groupSel.GroupName, alternative.GroupName))
                                                                           );

            return(allCompoundGroupSelectionForAlternativeGroup.Any(x => string.Equals(x.AlternativeName, alternative.Name)));
        }
        public ObserverSetMappingDTO MapFrom(ObserverSetMapping observerSetMapping, Simulation simulation)
        {
            var observerSetMappingDTO = new ObserverSetMappingDTO(observerSetMapping);

            var usedTemplateObserverSet = simulation.UsedBuildingBlockByTemplateId(observerSetMapping.TemplateObserverSetId);
            //simulation was already using an event based on template. Retrieved the building block used
            var templateObserverSet = _buildingBlockInSimulationManager.TemplateBuildingBlockUsedBy <ObserverSet>(usedTemplateObserverSet) ??
                                      _buildingBlockRepository.All <ObserverSet>().FindById(observerSetMapping.TemplateObserverSetId);

            observerSetMappingDTO.ObserverSet = templateObserverSet;
            return(observerSetMappingDTO);
        }
        protected override void Context()
        {
            _executionContext        = A.Fake <IExecutionContext>();
            _entityPathResolver      = A.Fake <IEntityPathResolver>();
            _individualTask          = A.Fake <IIndividualTask>();
            _containerTask           = new ContainerTaskForSpecs();
            _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();

            sut = new IndividualExtractor(_executionContext, _entityPathResolver, _individualTask, _containerTask, _buildingBlockRepository);

            _templateIndividual1 = new Individual();
            A.CallTo(() => _buildingBlockRepository.All <Individual>()).Returns(new[] { _templateIndividual1 });
        }
Exemple #17
0
        protected BuildingBlockFolderContextMenu(IMenuBarItemRepository repository, IBuildingBlockRepository buildingBlockRepository, params MenuBarItemId[] staticMenus)
        {
            staticMenus.Each(menu => _view.AddMenuItem(repository[menu]));

            _view.AddMenuItem(GenericMenu.LoadBuildingBlockFromSnapshot <TBuildingBlock>());

            var allBuildingBlocks = buildingBlockRepository.All <TBuildingBlock>();

            if (!allBuildingBlocks.Any())
            {
                return;
            }
        }
Exemple #18
0
        protected BuildingBlockFolderContextMenu(IMenuBarItemRepository repository, IBuildingBlockRepository buildingBlockRepository, params MenuBarItemId[] staticMenus)
        {
            staticMenus.Each(menu => _view.AddMenuItem(repository[menu]));

            var allBuildingBlocks = buildingBlockRepository.All <TBuildingBlock>();

            if (!allBuildingBlocks.Any())
            {
                return;
            }

            _view.AddMenuItem(GenericMenu.ExportCollectionToPDFMenuFor <TBuildingBlock>().AsGroupStarter());
        }
Exemple #19
0
 protected override void Context()
 {
     _eventPublisher          = A.Fake <IEventPublisher>();
     _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
     _simulation1             = new IndividualSimulation();
     _simulation2             = new IndividualSimulation();
     _simulation3             = new IndividualSimulation();
     A.CallTo(() => _buildingBlockRepository.All <Simulation>()).Returns(new[] { _simulation1, _simulation2, _simulation3 });
     _id = "tralala";
     _templateBuildingBlock = A.Fake <IPKSimBuildingBlock>().WithId(_id);
     _usedBuildingBlock     = new UsedBuildingBlock(_templateBuildingBlock.Id, _templateBuildingBlock.BuildingBlockType);
     A.CallTo(() => _buildingBlockRepository.ById(_templateBuildingBlock.Id)).Returns(_templateBuildingBlock);
     sut = new BuildingBlockInProjectManager(_buildingBlockRepository, _eventPublisher);
 }
Exemple #20
0
        protected override void Context()
        {
            _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
            _buildingBockRetriever   = A.Fake <IBuildingBlockRetriever>();
            _observedDataRepository  = A.Fake <IObservedDataRepository>();
            sut = new ParameterChangeUpdater(_buildingBockRetriever, _observedDataRepository, _buildingBlockRepository);

            _compounds = new List <Compound>();
            A.CallTo(() => _buildingBlockRepository.All <Compound>()).Returns(_compounds);
            _observedDataList = new List <DataRepository>();
            A.CallTo(() => _observedDataRepository.All()).Returns(_observedDataList);

            _compound = A.Fake <Compound>().WithName("C");
            A.CallTo(() => _compound.MolWeight).Returns(200);
        }
        protected override void Context()
        {
            _view = A.Fake <ISimulationSelectionForComparisonView>();
            _buildingBlockRepository        = A.Fake <IBuildingBlockRepository>();
            _lazyLoadTask                   = A.Fake <ILazyLoadTask>();
            _populationSimulationComparison = new PopulationSimulationComparison();
            sut = new SimulationSelectionForComparisonPresenter(_view, _buildingBlockRepository, _lazyLoadTask);

            A.CallTo(() => _view.BindTo(A <SimulationComparisonSelectionDTO> ._))
            .Invokes(x => _dto = x.GetArgument <SimulationComparisonSelectionDTO>(0));

            _sim1 = new PopulationSimulation().WithId("1").WithName("Sim1");
            _sim2 = new PopulationSimulation().WithId("2").WithName("Sim2");
            A.CallTo(() => _buildingBlockRepository.All <PopulationSimulation>()).Returns(new[] { _sim1, _sim2 });
        }
Exemple #22
0
        private bool simulationsAreUsingAlternativeContaining(IParameter parameter)
        {
            var alternative = parameter.ParentContainer as ParameterAlternative;

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

            var allCompoundGroupSelectionForAlternativeGroup = _buildingBlockRepository.All <Simulation>()
                                                               .SelectMany(x => x.CompoundPropertiesList)
                                                               .SelectMany(x => x.CompoundGroupSelections.Where(groupSel => string.Equals(groupSel.GroupName, alternative.GroupName)));

            return(allCompoundGroupSelectionForAlternativeGroup.Any(x => string.Equals(x.AlternativeName, alternative.Name)));
        }
 protected override void Context()
 {
     _buildingBlockDTOFactory = A.Fake <IObjectBaseDTOFactory>();
     _subPresenterManager     = SubPresenterHelper.Create <IPopulationItemPresenter>();
     _propertiesMapper        = A.Fake <IBuildingBlockPropertiesMapper>();
     _view = A.Fake <ICreateRandomPopulationView>();
     _popSettingsPresenter          = _subPresenterManager.CreateFake(RamdomPopulationItems.Settings);
     _popAdvancedParameterPresenter = _subPresenterManager.CreateFake(RamdomPopulationItems.AdvancedParameters);
     _popDistributionPresenter      = _subPresenterManager.CreateFake(RamdomPopulationItems.ParameterDistribution);
     _buildingBlockRepository       = A.Fake <IBuildingBlockRepository>();
     _dialogCreator  = A.Fake <IDialogCreator>();
     _allIndividuals = new List <Individual>();
     A.CallTo(() => _buildingBlockRepository.All <Individual>()).Returns(_allIndividuals);
     sut = new CreateRandomPopulationPresenter(_view, _subPresenterManager, _dialogCreator, _propertiesMapper, _buildingBlockDTOFactory, _buildingBlockRepository);
     sut.Initialize();
 }
Exemple #24
0
        public IEventMapping MapFrom(EventMappingDTO eventMappingDTO, PKSim.Core.Model.Simulation simulation)
        {
            var templateEventId = eventMappingDTO.Event.Id;
            var templateEvent   = _buildingBlockRepository.All().FindById(templateEventId);

            //in that case, event is a simulation event, we need to retrieve the template event
            if (templateEvent == null)
            {
                var usedEvent = simulation.UsedBuildingBlockById(templateEventId);
                templateEventId = usedEvent.TemplateId;
            }

            var eventMapping = eventMappingDTO.EventMapping;

            eventMapping.TemplateEventId = templateEventId;
            return(eventMapping);
        }
Exemple #25
0
        public EventMappingDTO MapFrom(IEventMapping eventMapping, PKSim.Core.Model.Simulation simulation)
        {
            var eventMappingDTO = new EventMappingDTO(eventMapping);

            eventMappingDTO.StartTimeParameter = _parameterDTOMapper.MapFrom(eventMapping.StartTime, eventMappingDTO, x => x.StartTime, x => x.StartTimeParameter);

            var templateEvent = _buildingBlockRepository.All <PKSim.Core.Model.PKSimEvent>().FindById(eventMapping.TemplateEventId);
            var usedEvent     = simulation.UsedBuildingBlockByTemplateId(eventMapping.TemplateEventId);

            //simulation was already using an event based on template. Retrieved the building block used
            if (usedEvent != null)
            {
                templateEvent = _buildingBlockInSimulationManager.TemplateBuildingBlockUsedBy <PKSim.Core.Model.PKSimEvent>(usedEvent);
            }

            eventMappingDTO.Event = templateEvent;
            return(eventMappingDTO);
        }
Exemple #26
0
        protected override void Context()
        {
            _compoundTask                     = A.Fake <ICompoundTask>();
            _view                             = A.Fake <ISimulationCompoundsSelectionView>();
            _buildingBlockRepository          = A.Fake <IBuildingBlockRepository>();
            _buildingBlockInSimulationManager = A.Fake <IBuildingBlockInSimulationManager>();
            _buildingBlockSelectionDisplayer  = A.Fake <IBuildingBlockSelectionDisplayer>();


            A.CallTo(() => _buildingBlockRepository.All <Compound>()).Returns(_allCompoundTemplates);
            A.CallTo(() => _view.BindTo(A <NotifyList <CompoundSelectionDTO> > ._))
            .Invokes(x => _compoundDTOList = x.GetArgument <NotifyList <CompoundSelectionDTO> >(0));

            sut = new SimulationCompoundsSelectionPresenter(_view, _buildingBlockRepository, _buildingBlockInSimulationManager, _compoundTask, _buildingBlockSelectionDisplayer);

            sut.Initialize();

            CompoundSelectionDTOFor(_compound1).Selected = true;
        }
Exemple #27
0
        public FormulationMapping MapFrom(FormulationMappingDTO formulationMappingDTO, Simulation simulation)
        {
            var templateFormulationId = formulationMappingDTO.Formulation.Id;
            var templateFormulation   = _buildingBlockRepository.All().FindById(templateFormulationId);

            //in that case, formulation is a simulation formulation, we need to retrieve the template formulation
            if (templateFormulation == null)
            {
                var usedFormulation = simulation.UsedBuildingBlockById(templateFormulationId);
                templateFormulationId = usedFormulation.TemplateId;
            }

            return(new FormulationMapping
            {
                TemplateFormulationId = templateFormulationId,
                FormulationKey = formulationMappingDTO.FormulationKey,
                Formulation = formulationMappingDTO.Formulation
            });
        }
Exemple #28
0
        protected override void Context()
        {
            _individualList = new List <Individual>();
            _individualBuildingBlockTask = A.Fake <IBuildingBlockTask <Individual> >();
            _container = A.Fake <IContainer>();
            A.CallTo(() => _container.Resolve <IBuildingBlockTask <Individual> >()).Returns(_individualBuildingBlockTask);
            _view = A.Fake <IBuildingBlockSelectionView>();
            _objectTypeResolver   = A.Fake <IObjectTypeResolver>();
            _individualRepository = A.Fake <IBuildingBlockRepository>();
            A.CallTo(() => _individualRepository.All <Individual>()).Returns(_individualList);
            _buildingBlockType = "Tralal";
            A.CallTo(() => _objectTypeResolver.TypeFor <Individual>()).Returns(_buildingBlockType);
            _toolTipCreator         = A.Fake <IToolTipPartCreator>();
            _buildingBlockSelection = A.Fake <IBuildingBlockSelectionDisplayer>();
            _objectBaseFactory      = A.Fake <IObjectBaseFactory>();
            _emptySelection         = new Individual().WithId("TOTO");
            A.CallTo(() => _objectBaseFactory.Create <Individual>()).Returns(_emptySelection);

            sut = new BuildingBlockSelectionPresenter <Individual>(_view, _objectTypeResolver, _individualRepository, _container, _objectBaseFactory, _buildingBlockSelection);
        }
Exemple #29
0
        protected override void Context()
        {
            _context = A.Fake <IMoBiContext>();
            _view    = A.Fake <IBuildingBlockSelectionView>();
            _buildingBlockRepository = A.Fake <IBuildingBlockRepository>();
            _interactionTask         = A.Fake <IInteractionTasksForBuildingBlock <IMoBiReactionBuildingBlock> >();
            sut = new BuildingBlockSelectionPresenter <IMoBiReactionBuildingBlock>(_view, _buildingBlockRepository, _interactionTask, _context);

            _buildingBlockInfo       = new ReactionBuildingBlockInfo();
            _templateBuildingBlock1  = A.Fake <IMoBiReactionBuildingBlock>().WithName("BB1");
            _templateBuildingBlock2  = A.Fake <IMoBiReactionBuildingBlock>().WithName("BB2");
            _simulationBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithName("BBSIM");
            _allBuildingBlocks       = new List <IMoBiReactionBuildingBlock> {
                _templateBuildingBlock1, _templateBuildingBlock2
            };
            A.CallTo(() => _buildingBlockRepository.All <IMoBiReactionBuildingBlock>()).Returns(_allBuildingBlocks);

            A.CallTo(() => _view.BindTo(A <BuildingBlockSelectionDTO> ._))
            .Invokes(x => _buildingBlockSelectionDTO = x.GetArgument <BuildingBlockSelectionDTO>(0));
        }
Exemple #30
0
        private List <IBuildingBlock> getAllAvailableBuildingBlocks <TBuildingBlock>() where TBuildingBlock : class, IBuildingBlock
        {
            var allAvailableBuildingBlocks = new List <IBuildingBlock>(_buildingBlockRepository.All <TBuildingBlock>());

            return(allAvailableBuildingBlocks);
        }