Пример #1
0
        protected override void Context()
        {
            _objectPathFactory  = new ObjectPathFactory(new AliasCreator());
            _buildConfiguration = A.Fake <IBuildConfiguration>();
            _validFormula       = new ExplicitFormula("5*PAR1");
            _validFormula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom("ROOT", "VALID", "PARA1").WithAlias("PAR1"));
            _invalidFormula = new ExplicitFormula("toto");
            _invalidFormula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom("ROOT", "INVALID", "PARA5").WithAlias("PAR1"));
            _rootContainer  = new Container().WithName("ROOT");
            _validContainer = new Container().WithName("VALID");
            _validContainer.Add(new Parameter().WithName("PARA1").WithFormula(new ConstantFormula(1)));
            _validContainer.Add(new Parameter().WithName("PARA2").WithFormula(_validFormula));
            _validContainer.Add(new Reaction().WithName("REACTION").WithFormula(_validFormula));
            _validContainer.Add(new Transport().WithName("TRANSPORT").WithFormula(_validFormula));
            _invalidContainer = new Container().WithName("INVALID");

            _invalidContainer.Add(new Parameter().WithName("PARA1").WithFormula(new ConstantFormula(1)));
            _invalidContainer.Add(new Parameter().WithName("PARA2").WithFormula(_invalidFormula));
            _invalidContainer.Add(new Reaction().WithName("REACTION").WithFormula(_invalidFormula));
            _invalidContainer.Add(new Transport().WithName("TRANSPORT").WithFormula(_invalidFormula));

            _rootContainer.Add(_validContainer);
            _rootContainer.Add(_invalidContainer);
            _objectTypeResolver = A.Fake <IObjectTypeResolver>();
        }
Пример #2
0
        /// <summary>
        ///     Checks if a object path for the given objectName is already existant and creates a new one if not.
        /// </summary>
        private string getObjectPathName(string parentContainer, string objectName)
        {
            if (objectPathExistent(objectName))
            {
                return(objectName);
            }

            var alias = createAliasFrom(objectName);

            _objectPaths.Add(_objectPathFactory.CreateFormulaUsablePathFrom(parentContainer, objectName).WithAlias(alias));
            return(alias);
        }
Пример #3
0
        /// <summary>
        ///     Checks if a object path for the given objectName is already existant and creates a new one if not.
        /// </summary>
        private string getObjectPathName(string parentContainer, string objectName, bool useConcentration = false)
        {
            if (objectPathExistent(objectName))
            {
                return(objectName);
            }

            var alias      = createAliasFrom(objectName);
            var usablePath = useConcentration ? _objectPathFactory.CreateFormulaUsablePathFrom(parentContainer, objectName, Constants.Parameters.CONCENTRATION) : _objectPathFactory.CreateFormulaUsablePathFrom(parentContainer, objectName);

            _objectPaths.Add(usablePath.WithAlias(alias));
            return(alias);
        }
Пример #4
0
        public string AddParentVolumeReferenceToFormula(IFormula formula)
        {
            string volumeAlias = _aliasCreator.CreateAliasFrom(Constants.VOLUME_ALIAS, formula.ObjectPaths.Select(p => p.Alias));

            //possible reference
            var volumeReferencePath = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, Constants.Parameters.VOLUME)
                                      .WithAlias(volumeAlias)
                                      .WithDimension(_dimensionFactory.Dimension(Constants.Dimension.VOLUME));

            //do we have one already?
            var volumeReference = formula.ObjectPaths.FirstOrDefault(x => Equals(x.PathAsString, volumeReferencePath.PathAsString));

            //was not defined yet
            if (volumeReference == null)
            {
                formula.AddObjectPath(volumeReferencePath);
            }
            else
            {
                volumeAlias = volumeReference.Alias;
            }

            //return the used alias
            return(volumeAlias);
        }
Пример #5
0
        private KeyPathMap calculationKeyFor(DataColumn dataColumn)
        {
            if (dataColumn == null)
            {
                return(new KeyPathMap());
            }

            var quantityInfo = dataColumn.QuantityInfo;
            var dataInfo     = dataColumn.DataInfo;

            if (quantityInfo == null || dataInfo == null)
            {
                return(new KeyPathMap(path: dataColumn.Name));
            }

            switch (dataInfo.Origin)
            {
            case ColumnOrigins.Undefined:
            case ColumnOrigins.Observation:
            case ColumnOrigins.ObservationAuxiliary:
                return(new KeyPathMap(path: _objectPathFactory.CreateFormulaUsablePathFrom(dataInfo.Source, dataColumn.Name).ToString()));

            case ColumnOrigins.BaseGrid:
                return(new KeyPathMap(path: quantityInfo.PathAsString));

            case ColumnOrigins.Calculation:
            case ColumnOrigins.CalculationAuxiliary:
                return(calculationKeyFor(quantityInfo));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #6
0
        /// <summary>
        ///    Creates the path from parameter dummy.
        /// </summary>
        /// <param name="objectBaseDTO">The dummy parameter dto.</param>
        /// <param name="shouldCreateAbsolutePaths">if set to <c>true</c>  creates absolute paths otherwise creates reltive paths.</param>
        /// <param name="refObject">
        ///    The reference object the user chosen (may the concrete object that uses the reference or a
        ///    existing parent of it).
        /// </param>
        /// <param name="editedObject"></param>
        /// <returns> The path that could be uses in the model to reference the object</returns>
        public virtual ReferenceDTO CreatePathFromParameterDummy(IObjectBaseDTO objectBaseDTO, bool shouldCreateAbsolutePaths, IEntity refObject, IUsingFormula editedObject)
        {
            if (IsMoleculeReference(objectBaseDTO))
            {
                return(createMoleculeReference());
            }

            var          dtoDummyParameter = (DummyParameterDTO)objectBaseDTO;
            var          parameterToUse    = _context.Get <IParameter>(dtoDummyParameter.ParameterToUse.Id);
            ReferenceDTO dtoReference;

            if (parameterToUse.IsAtMolecule())
            {
                dtoReference = new ReferenceDTO();
                IObjectPath tmpPath;
                //global molecule parameters we always reference absolute
                if (shouldCreateAbsolutePaths || !parameterToUse.BuildMode.Equals(ParameterBuildMode.Local))
                {
                    tmpPath = _objectPathFactory.CreateAbsoluteObjectPath(dtoDummyParameter.Parent);
                }
                else
                {
                    if (refObject != dtoDummyParameter.Parent)
                    {
                        tmpPath = _objectPathFactory.CreateRelativeObjectPath(refObject, dtoDummyParameter.Parent);
                    }
                    else
                    {
                        tmpPath = new ObjectPath();
                    }

                    tmpPath = AdjustReferences(parameterToUse, tmpPath);
                }
                dtoReference.Path = _objectPathFactory.CreateFormulaUsablePathFrom(tmpPath)
                                    .WithAlias(_aliasCreator.CreateAliasFrom(parameterToUse.Name))
                                    .WithDimension(parameterToUse.Dimension);
                dtoReference.Path.Add(parameterToUse.Name);
            }
            else
            {
                dtoReference = CreatePathsFromEntity(parameterToUse, shouldCreateAbsolutePaths, refObject, editedObject);
            }
            dtoReference.Path.Replace(Constants.MOLECULE_PROPERTIES, dtoDummyParameter.ModelParentName);
            dtoReference.BuildMode = parameterToUse.BuildMode;
            return(dtoReference);
        }
Пример #7
0
        public IFormulaUsablePath MapFrom(FlatRateObjectPath flatRateObjectPath)
        {
            var rateObjectContainerPath = _objectPathMapper.MapFrom(flatRateObjectPath);

            return(_objectPathFactory.CreateFormulaUsablePathFrom(rateObjectContainerPath.ToArray())
                   .WithAlias(flatRateObjectPath.Alias)
                   .WithDimension(_dimensionRepository.DimensionByName(flatRateObjectPath.Dimension)));
        }
Пример #8
0
        public IFormula DrugMassFormulaFor(IFormulaCache formulaCache)
        {
            if (formulaCache.ExistsByName(Constants.Parameters.DRUG_MASS))
            {
                return(formulaCache.FindByName(Constants.Parameters.DRUG_MASS));
            }

            var startFormula = _objectBaseFactory.Create <ExplicitFormula>()
                               .WithFormulaString(Constants.Parameters.DRUG_MASS)
                               .WithDimension(_dimensionRepository.Amount)
                               .WithName(Constants.Parameters.DRUG_MASS);

            var pathToDrugMass = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, CoreConstants.ContainerName.ProtocolSchemaItem, Constants.Parameters.DRUG_MASS)
                                 .WithAlias(Constants.Parameters.DRUG_MASS)
                                 .WithDimension(_dimensionRepository.Amount);

            startFormula.AddObjectPath(pathToDrugMass);
            formulaCache.Add(startFormula);
            return(startFormula);
        }
        public IFormulaUsablePath GetSelection()
        {
            _view.Display();
            if (_view.Canceled)
            {
                return(null);
            }
            var selectedPath = getSelectedPath();

            return(_objectPathFactory.CreateFormulaUsablePathFrom(selectedPath).WithAlias(selectedPath.Last()));
        }
Пример #10
0
        public IFormula ConcentrationFormulaFor(IFormulaCache formulaCache)
        {
            if (formulaCache.ExistsByName(Constants.CONCENTRATION_FORMULA))
            {
                return(formulaCache.FindByName(Constants.CONCENTRATION_FORMULA));
            }

            var formula = _objectBaseFactory.Create <ExplicitFormula>()
                          .WithName(Constants.CONCENTRATION_FORMULA)
                          .WithFormulaString("V>0 ? M/V : 0");

            formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER)
                                  .WithAlias("M")
                                  .WithDimension(_dimensionFactory.Dimension(Constants.Dimension.MOLAR_AMOUNT)));

            formula.AddObjectPath(createVolumeReferencePath(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, Constants.Parameters.VOLUME));

            formulaCache.Add(formula);
            formula.Dimension = _dimensionFactory.Dimension(Constants.Dimension.MOLAR_CONCENTRATION);
            return(formula);
        }
        private IFormulaUsablePath objectPathFor(IFormulaUsable referencedObject, IFormulaUsablePath originalObjectPath)
        {
            if (referencedObject == null)
            {
                return(originalObjectPath);
            }

            var consolidatedPath = _entityPathResolver.ObjectPathFor(referencedObject);

            return(_objectPathFactory.CreateFormulaUsablePathFrom(consolidatedPath)
                   .WithAlias(originalObjectPath.Alias)
                   .WithDimension(originalObjectPath.Dimension));
        }
        private IFormula R1Formula(IFormulaCache formulaCache)
        {
            var formula = formulaCache.FirstOrDefault(x => string.Equals(x.Name, "R1"));

            if (formula != null)
            {
                return(formula);
            }

            formula = _objectBaseFactory.Create <ExplicitFormula>().WithFormulaString("A+B").WithName("R1");
            formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "A", Constants.Parameters.CONCENTRATION)
                                  .WithAlias("A")
                                  .WithDimension(_concentrationDimension));

            formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "B", Constants.Parameters.CONCENTRATION)
                                  .WithAlias("B")
                                  .WithDimension(_concentrationDimension));

            formula.WithDimension(_concentrationPerTimeDimension);
            formulaCache.Add(formula);

            return(formula);
        }
        private IFormula particleDrugMassFormula(IFormulaCache formulaCache)
        {
            if (formulaCache.ExistsByName(CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS))
            {
                return(formulaCache.FindByName(CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS));
            }


            var pathToDrugMass = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS)
                                 .WithAlias("ParticleBinDrugMass")
                                 .WithDimension(_dimensionRepository.Amount);

            var startFormula = _objectBaseFactory.Create <ExplicitFormula>()
                               .WithFormulaString(pathToDrugMass.Alias)
                               .WithDimension(_dimensionRepository.Amount)
                               .WithName(CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS);


            startFormula.AddObjectPath(pathToDrugMass);
            formulaCache.Add(startFormula);
            return(startFormula);
        }
Пример #14
0
 private IFormulaUsablePath formulatUsablePathFrom(IObjectPath objectPath, IDimension dimension)
 {
     return(_objectPathFactory.CreateFormulaUsablePathFrom(objectPath).WithDimension(dimension));
 }
 private IFormulaUsablePath kiPath(string kiParameter, Compound inhibitor, InteractionProcess process, string kiAlias)
 {
     return(_objectPathFactory.CreateFormulaUsablePathFrom(inhibitor.Name, process.Name, kiParameter)
            .WithAlias(kiAlias)
            .WithDimension(_dimensionRepository.MolarConcentration));
 }
Пример #16
0
 private IFormulaUsablePath createZoneAmoutPath(string compartment, string zone, string alias)
 {
     return(_objectPathFactory.CreateFormulaUsablePathFrom(Constants.ORGANISM, CoreConstants.Organ.Liver, zone, compartment, ObjectPathKeywords.MOLECULE)
            .WithAlias(alias)
            .WithDimension(_dimensionRepository.Amount));
 }
Пример #17
0
 private IFormulaUsablePath pathInParentContainerFor(IParameter parameter, string alias)
 {
     return(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, parameter.Name)
            .WithAlias(alias)
            .WithDimension(parameter.Dimension));
 }