Ejemplo n.º 1
0
    /*!
     * \brief Load all the properties from multiple files
     * \param files All the files
     * \return A list of all the properties
     */
    public LinkedList <ActiveTransportProperties> getActiveTransportPropertiesFromFiles(IEnumerable <string> files)
    {
        Logger.Log("ActiveTransport::getActiveTransportPropertiesFromFiles("
                   + Logger.EnumerableToString <string>(files)
                   + ") starts"
                   , Logger.Level.DEBUG);

        LinkedList <ActiveTransportProperties> propsList = new LinkedList <ActiveTransportProperties>();
        LinkedList <ActiveTransportProperties> newPropList;

        foreach (string file in files)
        {
            newPropList = loadObjectsFromFile <ActiveTransportProperties>(file, "activeTransports");
            if (null != newPropList)
            {
                LinkedListExtensions.AppendRange <ActiveTransportProperties>(propsList, newPropList);
            }
        }

        Logger.Log("ActiveTransport::getActiveTransportPropertiesFromFiles("
                   + Logger.EnumerableToString <string>(files)
                   + ") returns " + Logger.ToString <ActiveTransportProperties>(propsList)
                   , Logger.Level.DEBUG);

        return(propsList);
    }
Ejemplo n.º 2
0
    public bool addAvailableBioBrick(BioBrick brick, bool updateView = true)
    {
        Logger.Log("AvailableBioBricksManager::addAvailableBioBrick(" + brick + ")", Logger.Level.INFO);
        string bbName = brick.getName();

        if ((null != brick) &&
            (null == LinkedListExtensions.Find <BioBrick>(
                 _availableBioBricks
                 , b => b.getName() == bbName
                 , false
                 , " AvailableBioBricksManager::addAvailableBioBrick(" + brick + ", " + updateView + ")"
                 )
            ))
        // TODO deeper safety check
        // && !LinkedListExtensions.Find<BioBrick>(_availableBioBricks, b => b..Equals(brick), true, " AvailableBioBricksManager::addAvailableBioBrick("+brick+", "+updateView+")")
        {
            Logger.Log("AvailableBioBricksManager::addAvailableBioBrick(" + brick + ") will _availableBioBricks.AddLast(" + brick + ")", Logger.Level.INFO);

            _availableBioBricks.AddLast(brick);
            if (updateView)
            {
                updateDisplayedBioBricks();
            }
            return(true);
        }
        else
        {
            Logger.Log("AvailableBioBricksManager::addAvailableBioBrick(" + brick + ") fail", Logger.Level.INFO);
            return(false);
        }
    }
Ejemplo n.º 3
0
    //! Load the diffusion reactions from an array of files and a Medium list

    /*!
     *  \param files Array of files which contain information about diffusion reaction.
     *  \param mediums The list of all the mediums.
     *
     *  This function loads the diffusion reactions based on Fick model. It takes an Array of file paths
     *  and a list of Medium that should contain all the mediums of the simulation.
     *  This function creates the list of all the reactions between all Medium which exist and initialize their parameters to 0.
     *  Only the reactions explicitly defined in files are initialized to the values explicited in files.
     *  If a parameter of a fick reaction is not specified in files then this parameter will be equal to 0.
     */
    public void loadFicksReactionsFromFiles(string[] files, LinkedList <Medium> mediums)
    {
        Logger.Log("Fick::loadFicksReactionsFromFiles("
                   + Logger.EnumerableToString <string> (files)
                   + ") starts"
                   , Logger.Level.INFO);
        LinkedList <FickProperties> propsList = new LinkedList <FickProperties> ();
        LinkedList <FickProperties> newPropList;

        foreach (string file in files)
        {
            newPropList = loadObjectsFromFile <FickProperties> (file, "ficks");
            if (newPropList != null)
            {
                LinkedListExtensions.AppendRange <FickProperties> (propsList, newPropList);
            }
        }
        _reactions = FickReaction.getFickReactionsFromMediumList(mediums);
        finalizeFickReactionFromProps(propsList, _reactions);

        Logger.Log("Fick::loadFicksReactionsFromFiles("
                   + Logger.EnumerableToString <string> (files)
                   + ") starts"
                   , Logger.Level.INFO);
    }
Ejemplo n.º 4
0
    //! This function is called at each frame
    public void Update()
    {
        if (_paused)
        {
            Logger.Log("ReactionEngine::Update paused", Logger.Level.TRACE);
        }
        else
        {
            _fick.react();
            if (enableShufflingMediumOrder)
            {
                LinkedListExtensions.Shuffle <Medium>(_mediums);
            }

            foreach (Medium medium in _mediums)
            {
                medium.Update();
            }

            Logger.Log("ReactionEngine::Update() update of mediums done", Logger.Level.TRACE);
            if (!enableSequential)
            {
                foreach (Medium medium in _mediums)
                {
                    medium.updateMoleculesConcentrations();
                }
                Logger.Log("ReactionEngine::Update() update of mol cc in mediums done", Logger.Level.TRACE);
            }
        }
    }
Ejemplo n.º 5
0
        public void FindFromLast_InvalidInput_Zero(int k, int n)
        {
            var list = CreateList(n);

            var actual = LinkedListExtensions.FindFromLast(list, k);

            Assert.AreEqual(0, actual);
        }
Ejemplo n.º 6
0
        public void FindFromLast_ValidInput_ExpectedResult(int k, int n)
        {
            var list = CreateList(n);

            var actual = LinkedListExtensions.FindFromLast(list, k);

            Assert.AreEqual(n - k, actual);
        }
Ejemplo n.º 7
0
        public void RemoveDups_OneEntry_Same()
        {
            var actual   = CreateOneEntry();
            var expected = CreateOneEntry();

            LinkedListExtensions.DeleteDups(ref actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.Next, actual.Next);
        }
Ejemplo n.º 8
0
        public void RemoveDups_TwoEntries_OneRemoved()
        {
            var actual   = CreateTwoEntries();
            var expected = CreateTwoEntries();

            LinkedListExtensions.DeleteDups(ref actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(null, actual.Next);
        }
Ejemplo n.º 9
0
    private void updateDisplayedBioBricks()
    {
        Logger.Log("AvailableBioBricksManager::updateDisplayedBioBricks", Logger.Level.DEBUG);

        LinkedList <BioBrick> availablePromoters = new LinkedList <BioBrick>();

        LinkedListExtensions.AppendRange <BioBrick>(availablePromoters, getAvailableBioBricksOfType(BioBrick.Type.PROMOTER));
        LinkedList <BioBrick> availableRBS = new LinkedList <BioBrick>();

        LinkedListExtensions.AppendRange <BioBrick>(availableRBS, getAvailableBioBricksOfType(BioBrick.Type.RBS));
        LinkedList <BioBrick> availableGenes = new LinkedList <BioBrick>();

        LinkedListExtensions.AppendRange <BioBrick>(availableGenes, getAvailableBioBricksOfType(BioBrick.Type.GENE));
        LinkedList <BioBrick> availableTerminators = new LinkedList <BioBrick>();

        LinkedListExtensions.AppendRange <BioBrick>(availableTerminators, getAvailableBioBricksOfType(BioBrick.Type.TERMINATOR));

        _displayableAvailablePromoters = getDisplayableAvailableBioBricks(
            availablePromoters
            , getDisplayableAvailableBioBrick
            );
        _displayableAvailableRBS = getDisplayableAvailableBioBricks(
            availableRBS
            , getDisplayableAvailableBioBrick
            );
        _displayableAvailableGenes = getDisplayableAvailableBioBricks(
            availableGenes
            , getDisplayableAvailableBioBrick
            );
        _displayableAvailableTerminators = getDisplayableAvailableBioBricks(
            availableTerminators
            , getDisplayableAvailableBioBrick
            );

        Logger.Log("AvailableBioBricksManager::updateDisplayedBioBricks"
                   + "\n\navailablePromoters=" + Logger.ToString <BioBrick>(availablePromoters)
                   + ",\n\navailableRBS=" + Logger.ToString <BioBrick>(availableRBS)
                   + ",\n\navailableGenes=" + Logger.ToString <BioBrick>(availableGenes)
                   + ",\n\navailableTerminators=" + Logger.ToString <BioBrick>(availableTerminators)

                   + ",\n\n_displayableAvailablePromoters=" + Logger.ToString <AvailableDisplayedBioBrick>(_displayableAvailablePromoters)
                   + ",\n\n_displayableAvailableRBS=" + Logger.ToString <AvailableDisplayedBioBrick>(_displayableAvailableRBS)
                   + ",\n\n_displayableAvailableGenes=" + Logger.ToString <AvailableDisplayedBioBrick>(_displayableAvailableGenes)
                   + ",\n\n_displayableAvailableTerminators=" + Logger.ToString <AvailableDisplayedBioBrick>(_displayableAvailableTerminators)
                   , Logger.Level.TRACE);

        displayPromoters();
    }
Ejemplo n.º 10
0
        public void RemoveDups_SevenEntries_TwoRemoved()
        {
            var actual   = CreateSevenEntries();
            var expected = CreateSevenEntriesAnswer();

            LinkedListExtensions.DeleteDups(ref actual);

            while (expected != null)
            {
                Assert.AreEqual(expected.Value, actual.Value);
                expected = expected.Next;
                actual   = actual.Next;
            }

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
    public ArrayList getMoleculesFromMedium(int id)
    {
        //"warn" parameter is true to indicate that there is no such Medium
        //as the one needed to get molecules
        Medium medium = LinkedListExtensions.Find <Medium>(
            _mediums
            , m => m.getId() == id
            , true
            , " RE::getMoleculesFromMedium(" + id + ")");

        if (medium != null)
        {
            return(medium.getMolecules());
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 12
0
    public BioBrick getBioBrickFromAll(string brickName)
    {
        Logger.Log("AvailableBioBricksManager::getBioBrickFromAll", Logger.Level.DEBUG);

        BioBrick brick = LinkedListExtensions.Find <BioBrick>(
            getAllBioBricks()
            , b => (b.getName() == brickName)
            , false
            , "AvailableBioBricksManager::getBioBrickFromAll(" + brickName + ")"
            );

        if (brick != null)
        {
            Logger.Log("AvailableBioBricksManager::getBioBrickFromAll found " + brick, Logger.Level.TRACE);
            return(brick);
        }
        else
        {
            Logger.Log("AvailableBioBricksManager::getBioBrickFromAll failed to find brick with name " + brickName + "!", Logger.Level.WARN);
            return(null);
        }
    }
Ejemplo n.º 13
0
    // Warning: inputFiles is an array of names of files inside 'biobrickFilesPathPrefix'
    private void loadBioBricks(string[] inputFiles, LinkedList <BioBrick> destination)
    {
        Logger.Log("AvailableBioBricksManager::loadBioBricks", Logger.Level.INFO);
        //load biobricks from xml
        BioBrickLoader bLoader = new BioBrickLoader();

        //_availableBioBricks   = new LinkedList<BioBrick>();
        string files = "";

        foreach (string file in inputFiles)
        {
            string fullPath = biobrickFilesPathPrefix + file;
            Logger.Log("AvailableBioBricksManager::loadBioBricks loads biobrick file " + fullPath, Logger.Level.DEBUG);
            LinkedList <BioBrick> bb = bLoader.loadBioBricksFromFile(fullPath);
            Logger.Log("AvailableBioBricksManager::loadBioBricks appended bb=" + bb.Count.ToString() + " from file " + fullPath, Logger.Level.DEBUG);
            LinkedListExtensions.AppendRange <BioBrick>(destination, bb);
            if (!string.IsNullOrEmpty(files))
            {
                files += ", ";
            }
            files += fullPath;
        }
        Logger.Log("AvailableBioBricksManager::loadBioBricks loaded " + files + " so that destination=" + destination.Count, Logger.Level.DEBUG);
    }
Ejemplo n.º 14
0
    /* !
     * \brief Checks that two reactions have the same IReaction field values
     * except for medium
     * \param reaction The reaction that will be compared to 'this'.
     */
    protected virtual bool PartialEquals(IReaction reaction)
    {
        //TODO check this

        /*
         * if(!hasValidData() || !reaction.hasValidData())
         * {
         * Logger.Log("IReaction::PartialEquals invalid reaction"
         *         , Logger.Level.ERROR);
         * return false;
         * }
         */

        bool res =
            LinkedListExtensions.Equals(_products, reaction._products) &&
            (_isActive == reaction._isActive) &&
            (_reactionSpeed == reaction._reactionSpeed) &&
            (_energyCost == reaction._energyCost) &&
            (enableSequential == reaction.enableSequential) &&
            (enableEnergy == reaction.enableEnergy)
        ;

        return(res);
    }
Ejemplo n.º 15
0
    // Searches for a brick from its name in available BioBricks
    //  If it succeeds, adds brick to deviceBricks and returns true
    //  If it fails, searches for it in all the known BioBricks
    //      If it succeeds, adds brick to available BioBricks list and does previous success treatment
    //      If it fails, returns false
    private bool processBrick(string brickName, string filePath = "")
    {
        Logger.Log("DeviceLoader::loadDevicesFromFile brick name " + brickName, Logger.Level.TRACE);
        //"warn" parameter is true to indicate that there is no such BioBrick
        //as the one mentioned in the xml file of the device
        brick = LinkedListExtensions.Find <BioBrick>(_availableBioBricks
                                                     , b => (b.getName() == brickName)
                                                     , true
                                                     , " DeviceLoader::loadDevicesFromFile(" + filePath + ")"
                                                     );

        if (brick == null)
        {
            brick = LinkedListExtensions.Find <BioBrick>(_allBioBricks
                                                         , b => (b.getName() == brickName)
                                                         , true
                                                         , " DeviceLoader::loadDevicesFromFile(" + filePath + ")"
                                                         );
            if (brick != null)
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile successfully added brick " + brick, Logger.Level.TRACE);
                AvailableBioBricksManager.get().addAvailableBioBrick(brick);
            }
        }
        if (brick != null)
        {
            Logger.Log("DeviceLoader::loadDevicesFromFile successfully added brick " + brick, Logger.Level.TRACE);
            deviceBricks.AddLast(brick);
            return(true);
        }
        else
        {
            Logger.Log("DeviceLoader::loadDevicesFromFile failed to add brick with name " + brickName + "!", Logger.Level.WARN);
            return(false);
        }
    }
Ejemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        int previousListedCount = _displayedListMoleculesCount;
        int previousTotalCount  = _displayedMolecules.Count;

        resetMoleculeList();

        ArrayList molecules = _reactionEngine.getMoleculesFromMedium(mediumId);

        foreach (System.Object molecule in molecules)
        {
            Molecule castMolecule  = (Molecule)molecule;
            string   realName      = castMolecule.getRealName();
            string   codeName      = castMolecule.getName();
            float    concentration = castMolecule.getConcentration();
            if (displayAll || (0 != concentration))
            {
                DisplayedMolecule found = LinkedListExtensions.Find(
                    _displayedMolecules
                    , m => m.getCodeName() == codeName
                    , false
                    , " GraphMoleculeList::Update()"
                    );
                if (null != found)
                {
                    found.update(concentration);
                }
                else
                //molecule is not displayed yet
                {
                    DisplayedMolecule created = new DisplayedMolecule(codeName, realName, concentration, DisplayedMolecule.DisplayType.MOLECULELIST);

                    //search if molecule should be displayed in a Device/molecule component
                    List <EquipedDisplayedDeviceWithMolecules> containers = _equipedDevices.FindAll(eddwm => eddwm.device.getFirstGeneProteinName() == codeName);
                    if (containers.Count != 0)
                    {
                        created.setDisplayType(DisplayedMolecule.DisplayType.DEVICEMOLECULELIST);
                        foreach (EquipedDisplayedDeviceWithMolecules container in containers)
                        {
                            container.addDisplayedMolecule(created);
                        }
                    }
                    else
                    {
                        _displayedListMoleculesCount++;
                    }
                    //anyway add it to molecule list
                    _displayedMolecules.AddLast(created);
                }
            }
        }

        removeUnusedMolecules();

        if (_displayedMolecules.Count != previousTotalCount ||
            previousListedCount != _displayedListMoleculesCount)
        {
            //rearrange devices
            positionDeviceAndMoleculeComponents();
        }

        string namesToDisplay  = "";
        string valuesToDisplay = "";

        foreach (DisplayedMolecule molecule in _displayedMolecules)
        {
            if (molecule.getDisplayType() == DisplayedMolecule.DisplayType.MOLECULELIST)
            {
                namesToDisplay  += molecule.getRealName() + ":\n";
                valuesToDisplay += molecule.getVal() + "\n";
            }
        }
        if (!string.IsNullOrEmpty(namesToDisplay))
        {
            namesToDisplay.Remove(namesToDisplay.Length - 1, 1);
            valuesToDisplay.Remove(valuesToDisplay.Length - 1, 1);
        }
        namesLabel.text  = namesToDisplay;
        valuesLabel.text = valuesToDisplay;

        /*
         * if(null != topLabels)
         * {
         * topLabelsShift = Vector3.up * topLabels.relativeSize.y * topLabels.transform.localScale.y;
         * namesLabel.transform.localPosition = topLabels.transform.localPosition + topLabelsShift;
         * }
         */

        setUnfoldingListBackgroundScale();
    }
Ejemplo n.º 17
0
    //! This function is called at the initialisation of the simulation (like a Constructor)
    void Awake()
    {
        _instance = this;

        FileLoader fileLoader = new FileLoader();

        _reactionsSets = new LinkedList <ReactionSet>();
        _moleculesSets = new LinkedList <MoleculeSet>();
        _mediums       = new LinkedList <Medium>();


        //TODO there is only one file in _moleculesFiles and in _reactionsFiles
        foreach (string file in _reactionsFiles)
        {
            LinkedList <ReactionSet> lr = fileLoader.loadObjectsFromFile <ReactionSet>(file, "reactions");
            if (null != lr)
            {
                LinkedListExtensions.AppendRange <ReactionSet>(_reactionsSets, lr);
            }
        }
        foreach (string file in _moleculesFiles)
        {
            Logger.Log("ReactionEngine::Awake() loading molecules from file", Logger.Level.DEBUG);

            LinkedList <MoleculeSet> lm = fileLoader.loadObjectsFromFile <MoleculeSet>(file, "molecules");
            if (null != lm)
            {
                LinkedListExtensions.AppendRange <MoleculeSet>(_moleculesSets, lm);
            }

            Logger.Log("ReactionEngine::Awake() loading molecules from file done"
                       + ": _moleculesSets=" + Logger.ToString <MoleculeSet>(_moleculesSets)
                       , Logger.Level.DEBUG);
        }

        foreach (string file in _mediumsFiles)
        {
            LinkedList <Medium> lmed = fileLoader.loadObjectsFromFile <Medium>(file, "Medium");
            if (null != lmed)
            {
                LinkedListExtensions.AppendRange <Medium>(_mediums, lmed);
            }
        }

        foreach (Medium medium in _mediums)
        {
            medium.Init(_reactionsSets, _moleculesSets);
            medium.enableSequential(enableSequential);
            medium.enableNoise(enableNoise);
            medium.enableEnergy(enableEnergy);
            medium.enableShufflingReactionOrder = enableShufflingReactionOrder;
        }

        Logger.Log("ReactionEngine::Awake() FickReactions starting", Logger.Level.INFO);

        _fick = new Fick();
        _fick.loadFicksReactionsFromFiles(_fickFiles, _mediums);

        Logger.Log("ReactionEngine::Awake() activeTransport starting", Logger.Level.INFO);

        _activeTransport = new ActiveTransport();
        _activeTransport.loadActiveTransportReactionsFromFiles(_activeTransportFiles, _mediums);

        Logger.Log("ReactionEngine::Awake() done", Logger.Level.INFO);
    }
Ejemplo n.º 18
0
 private LinkedList <BioBrick> getAvailableBioBricksOfType(BioBrick.Type type)
 {
     Logger.Log("AvailableBioBricksManager::getAvailableBioBricksOfType(" + type + ")", Logger.Level.TRACE);
     return(LinkedListExtensions.Filter <BioBrick>(_availableBioBricks, b => (b.getType() == type)));
 }
Ejemplo n.º 19
0
    /*!
     * \brief Execute everything about simulation into the Medium
     */
    public void Update()
    {
        if (enableShufflingReactionOrder)
        {
            LinkedListExtensions.Shuffle <IReaction>(_reactions);
        }

        foreach (IReaction reaction in _reactions)
        {
            if (Logger.isLevel(Logger.Level.TRACE))
            {
                PromoterReaction promoter = reaction as PromoterReaction;
                if (promoter != null)
                {
                    Logger.Log("Medium::Update reaction.react(" + _molecules + ") with reaction=" + reaction, Logger.Level.TRACE);
                }
            }
            reaction.react(_molecules);
        }

        applyVariation();

        if (_enableNoise)
        {
            float noise;

            foreach (Molecule m in _molecules)
            {
                noise = _numberGenerator.getNumber();
                if (_enableSequential)
                {
                    m.addConcentration(noise);
                }
                else
                {
                    m.addNewConcentration(noise);
                }
            }
        }

        //TODO improve check that it's the medium of the hero bacterium Cellia
        //TODO refactor interactions out of medium
        if (_name == "Cellia")
        {
            manageMoleculeConcentrationWithKey("AMPI");

            if (GameStateController.isAdminMode)
            {
                //TODO manage this differently
                manageMoleculeConcentrationWithKey("AMPR");
                manageMoleculeConcentrationWithKey("ATC");
                manageMoleculeConcentrationWithKey("FLUO1");
                manageMoleculeConcentrationWithKey("FLUO2");
                manageMoleculeConcentrationWithKey("IPTG");
                manageMoleculeConcentrationWithKey("MOV");
                manageMoleculeConcentrationWithKey("REPR1");
                manageMoleculeConcentrationWithKey("REPR2");
                manageMoleculeConcentrationWithKey("REPR3");
                manageMoleculeConcentrationWithKey("REPR4");
            }
        }
    }
Ejemplo n.º 20
0
        public void FindFromLast_Null_Zero()
        {
            var actual = LinkedListExtensions.FindFromLast <int>(null, 2);

            Assert.AreEqual(0, actual);
        }