Exemple #1
0
    protected override DNABit produceDNABit()
    {
        LinkedList <BioBrick> deviceBricks = new LinkedList <BioBrick>();

        string[] bricks = new string[] { promoterName, rbsName, geneName, terminatorName };

        foreach (string brickName in bricks)
        {
            BioBrick brick = AvailableBioBricksManager.get().getBioBrickFromAll(brickName);
            if (brick != null)
            {
                deviceBricks.AddLast(brick);
            }
            else
            {
                Logger.Log("PickableDeviceRef4Bricks::produceDNABit failed to add brick with name " + brickName + "!", Logger.Level.WARN);
            }
        }

        if (ExpressionModule.isBioBricksSequenceValid(deviceBricks))
        {
            ExpressionModule deviceModule = new ExpressionModule(deviceName, deviceBricks);
            LinkedList <ExpressionModule> deviceModules = new LinkedList <ExpressionModule>();
            deviceModules.AddLast(deviceModule);
            Device result = Device.buildDevice(deviceName, deviceModules);
            return(result);
        }
        else
        {
            Logger.Log("PickableDeviceRef4Bricks::produceDNABit failed to produce DNABit - BioBrick sequence is incorrect: list=" + Logger.ToString <BioBrick>(deviceBricks), Logger.Level.WARN);
            return(null);
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // utilities

    private Device getDeviceFromBricks(LinkedList <BioBrick> bricks)
    {
        Logger.Log("CraftZoneManager::getDeviceFromBricks(" + Logger.ToString <BioBrick>(bricks) + ")", Logger.Level.TRACE);

        if (!ExpressionModule.isBioBricksSequenceValid(bricks))
        {
            Logger.Log("CraftZoneManager::getDeviceFromBricks invalid biobricks sequence", Logger.Level.TRACE);
            return(null);
        }

        ExpressionModule module = new ExpressionModule("test", bricks);
        LinkedList <ExpressionModule> modules = new LinkedList <ExpressionModule>();

        modules.AddLast(module);

        Device device = Device.buildDevice(modules);

        if (device != null)
        {
            Logger.Log("CraftZoneManager::getDeviceFromBricks produced " + device, Logger.Level.TRACE);
        }
        else
        {
            Logger.Log("CraftZoneManager::getDeviceFromBricks device==null with bricks=" + Logger.ToString <BioBrick>(bricks)
                       , Logger.Level.WARN);
        }
        return(device);
    }
Exemple #3
0
    private PromoterProperties getPromoterReaction(ExpressionModule em, int id)
    {
        Logger.Log("Device::getPromoterReaction(" + em.ToString() + ", " + id + ")", Logger.Level.TRACE);
        PromoterProperties prom = new PromoterProperties();

        prom.energyCost = _energyPerBasePair * em.getSize();
        //promoter only
        //prom.energyCost = _energyPerBasePair*em.getBioBricks().First.Value.getSize();

        LinkedList <BioBrick> bricks = em.getBioBricks();

        //TODO fix this: create good properties' name
        prom.name = _internalName + id;
        PromoterBrick p = bricks.First.Value as PromoterBrick;

        prom.formula = p.getFormula();
        prom.beta    = p.getBeta();
        bricks.RemoveFirst();

        prom.products = getProductsFromBiobricks(bricks);

        TerminatorBrick tb = bricks.First.Value as TerminatorBrick;

        prom.terminatorFactor = tb.getTerminatorFactor();
        bricks.RemoveFirst();

        if (bricks.Count != 0)
        {
            Logger.Log("Device::getPromoterReaction Warning: bricks.Count =" + bricks.Count, Logger.Level.TRACE);
        }
        return(prom);
    }
 public ExpressionModule(ExpressionModule m)
 {
     _name = m._name;
     _bioBricks = new LinkedList<BioBrick>();
     foreach (BioBrick b in m.getBioBricks())
       _bioBricks.AddLast(b);
 }
  protected override DNABit produceDNABit()
  {
    LinkedList<BioBrick> deviceBricks = new LinkedList<BioBrick>();
    string[] bricks = new string[]{promoterName, rbsName, geneName, terminatorName};

    foreach(string brickName in bricks)
    {
      BioBrick brick = AvailableBioBricksManager.get().getBioBrickFromAll(brickName);
      if(brick != null) {
        deviceBricks.AddLast(brick);
      } else {
        Logger.Log("PickableDeviceRef4Bricks::produceDNABit failed to add brick with name "+brickName+"!", Logger.Level.WARN);
      }
    }

        if(ExpressionModule.isBioBricksSequenceValid(deviceBricks))
        {
            ExpressionModule deviceModule = new ExpressionModule(deviceName, deviceBricks);
            LinkedList<ExpressionModule> deviceModules = new LinkedList<ExpressionModule>();
            deviceModules.AddLast(deviceModule);
            Device result = Device.buildDevice(deviceName, deviceModules);
            return result;
        } else {
            Logger.Log("PickableDeviceRef4Bricks::produceDNABit failed to produce DNABit - BioBrick sequence is incorrect: list="+Logger.ToString<BioBrick>(deviceBricks), Logger.Level.WARN);
            return null;
        }
  }
Exemple #6
0
    public static Device buildDevice(ExpressionModule em)
    {
        Logger.Log("Device::buildDevice(em) with em=" + em + ")", Logger.Level.INFO);
        LinkedList <ExpressionModule> modules = new LinkedList <ExpressionModule>();

        modules.AddLast(em);
        return(buildDevice(em.getInternalName(), modules));
    }
Exemple #7
0
    public static Device buildDevice(LinkedList <BioBrick> bricks)
    {
        Logger.Log("Device::buildDevice(bricks) with bricks=" + bricks, Logger.Level.INFO);

        ExpressionModule em = new ExpressionModule(bricks);

        return(buildDevice(em));
    }
   protected override DNABit produceDNABit()
 {
   PromoterBrick prom = new PromoterBrick("PromY2", 75f, "[0.01,2]Y");
   RBSBrick rbs = new RBSBrick("RBS3", 3.0f);
   GeneBrick gene = new GeneBrick("MOV", "MOV");
   TerminatorBrick term = new TerminatorBrick("T1", 1.0f);
   LinkedList<BioBrick> bricks = new LinkedList<BioBrick>(new List<BioBrick>(){prom, rbs, gene, term});
   ExpressionModule module = new ExpressionModule("expr", bricks);
   return Device.buildDevice("DEV", new LinkedList<ExpressionModule>(new List<ExpressionModule>(){module}));
 }
 //copy constructor
 public ExpressionModule(ExpressionModule m)
 {
     Logger.Log("ExpressionModule::ExpressionModule(" + m + ")", Logger.Level.DEBUG);
     _name      = m._name;
     _bioBricks = new LinkedList <BioBrick>();
     foreach (BioBrick b in m.getBioBricks())
     {
         _bioBricks.AddLast(b.copy());
     }
 }
Exemple #10
0
        public void ParseTest1()
        {
            ExpressionModule ex;

            ex = new ExpressionModule("(50)");
            Assert.AreEqual(ex.Parse(), 50);
            ex = new ExpressionModule("(+50)");
            Assert.AreEqual(ex.Parse(), 50);
            ex = new ExpressionModule("(-50)");
            Assert.AreEqual(ex.Parse(), -50);
        }
  protected override DNABit produceDNABit()
  {
    PromoterBrick prom = new PromoterBrick(promoterName, promoterBeta, promoterFormula);
    RBSBrick rbs = new RBSBrick(rbsName, rbsFactor);
    GeneBrick gene = new GeneBrick(geneName, geneProteinName);
    TerminatorBrick term = new TerminatorBrick(terminatorName, terminatorFactor);

    LinkedList<BioBrick> bricks = new LinkedList<BioBrick>(new List<BioBrick>(){prom, rbs, gene, term});
    ExpressionModule module = new ExpressionModule(expressionModuleName, bricks);
        
        Device result = Device.buildDevice(deviceName, new LinkedList<ExpressionModule>(new List<ExpressionModule>(){module}));
        return result;
  }
Exemple #12
0
        public void ParseTest2()
        {
            ExpressionModule ex;

            ex = new ExpressionModule("2+3");
            Assert.AreEqual(ex.Parse(), 5);
            ex = new ExpressionModule("3*3+3");
            Assert.AreEqual(ex.Parse(), 12);
            ex = new ExpressionModule("(2*2)+2");
            Assert.AreEqual(ex.Parse(), 6);
            ex = new ExpressionModule("(2+2)*2");
            Assert.AreEqual(ex.Parse(), 8);
        }
Exemple #13
0
        public void ParseTest3()
        {
            ExpressionModule ex;

            ex = new ExpressionModule("2+-3");
            Assert.AreEqual(ex.Parse(), -1);
            ex = new ExpressionModule("3*3--3");
            Assert.AreEqual(ex.Parse(), 12);
            ex = new ExpressionModule("(2*-2)+2");
            Assert.AreEqual(ex.Parse(), -2);
            ex = new ExpressionModule("-(2+2)*2");
            Assert.AreEqual(ex.Parse(), -8);
        }
Exemple #14
0
        private void SolveButton_OnClick(object sender, RoutedEventArgs e)
        {
            ExpressionModule expr = new ExpressionModule(InputTextBox.Text);

            try
            {
                AnswerText.Text = "Ответ: " + expr.Parse();
            }
            catch (Exception exception)
            {
                AnswerText.Text = String.Format("Ошибка {0}:\n{1}", exception.GetType(), exception.Message);
            }
        }
    protected override DNABit produceDNABit()
    {
        PromoterBrick         prom   = new PromoterBrick("PromY2", 75f, "[0.01,2]Y");
        RBSBrick              rbs    = new RBSBrick("RBS3", 3.0f);
        GeneBrick             gene   = new GeneBrick("MOV", "MOV");
        TerminatorBrick       term   = new TerminatorBrick("T1", 1.0f);
        LinkedList <BioBrick> bricks = new LinkedList <BioBrick>(new List <BioBrick>()
        {
            prom, rbs, gene, term
        });
        ExpressionModule module = new ExpressionModule("expr", bricks);

        return(Device.buildDevice("DEV", new LinkedList <ExpressionModule>(new List <ExpressionModule>()
        {
            module
        })));
    }
    public bool hasSameBricks(ExpressionModule module)
    {
        if (module._bioBricks.Count != _bioBricks.Count)
        {
            return(false);
        }

        IEnumerator <BioBrick> enumerator1 = module._bioBricks.GetEnumerator();
        IEnumerator <BioBrick> enumerator2 = _bioBricks.GetEnumerator();

        while (enumerator1.MoveNext() && enumerator2.MoveNext())
        {
            if (!enumerator1.Current.Equals(enumerator2.Current))
            {
                return(false);
            }
        }
        return(true);
    }
    protected override DNABit produceDNABit()
    {
        PromoterBrick   prom = new PromoterBrick(promoterName, promoterBeta, promoterFormula);
        RBSBrick        rbs  = new RBSBrick(rbsName, rbsFactor);
        GeneBrick       gene = new GeneBrick(geneName, geneProteinName);
        TerminatorBrick term = new TerminatorBrick(terminatorName, terminatorFactor);

        LinkedList <BioBrick> bricks = new LinkedList <BioBrick>(new List <BioBrick>()
        {
            prom, rbs, gene, term
        });
        ExpressionModule module = new ExpressionModule(expressionModuleName, bricks);

        Device result = Device.buildDevice(deviceName, new LinkedList <ExpressionModule>(new List <ExpressionModule>()
        {
            module
        }));

        return(result);
    }
Exemple #18
0
    public PromoterProprieties getPromoterReaction(ExpressionModule em, int id)
    {
        PromoterProprieties prom = new PromoterProprieties();
        LinkedList<BioBrick> bricks = em.getBioBricks();

        prom.name = _name + id;
        PromoterBrick p = bricks.First.Value as PromoterBrick;
        prom.formula = p.getFormula();
        prom.beta = p.getBeta();
        bricks.RemoveFirst();

        prom.products = getProductsFromBiobricks(bricks);

        TerminatorBrick tb = bricks.First.Value as TerminatorBrick;
        prom.terminatorFactor = tb.getTerminatorFactor();
        bricks.RemoveFirst();

        prom.energyCost = getSize();
        return prom;
    }
Exemple #19
0
  private PromoterProperties getPromoterReaction(ExpressionModule em, int id)
  {
    Logger.Log("Device::getPromoterReaction("+em.ToString()+", "+id+")", Logger.Level.TRACE);
    PromoterProperties prom = new PromoterProperties();

    prom.energyCost = _energyPerBasePair*em.getSize();
    //promoter only
    //prom.energyCost = _energyPerBasePair*em.getBioBricks().First.Value.getSize();

    LinkedList<BioBrick> bricks = em.getBioBricks();

        //TODO fix this: create good properties' name
    prom.name = _internalName + id;
    PromoterBrick p = bricks.First.Value as PromoterBrick;
    prom.formula = p.getFormula();
    prom.beta = p.getBeta();
    bricks.RemoveFirst();

    prom.products = getProductsFromBiobricks(bricks);

    TerminatorBrick tb = bricks.First.Value as TerminatorBrick;
    prom.terminatorFactor = tb.getTerminatorFactor();
    bricks.RemoveFirst();

    if(bricks.Count != 0) {
      Logger.Log("Device::getPromoterReaction Warning: bricks.Count ="+bricks.Count, Logger.Level.TRACE);
    }
    return prom;
  }
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  // utilities

    private Device getDeviceFromBricks(LinkedList<BioBrick> bricks){
        Logger.Log("CraftZoneManager::getDeviceFromBricks("+Logger.ToString<BioBrick>(bricks)+")", Logger.Level.TRACE);

        if(!ExpressionModule.isBioBricksSequenceValid(bricks))
        {
            Logger.Log("CraftZoneManager::getDeviceFromBricks invalid biobricks sequence", Logger.Level.TRACE);
            return null;
        }

        ExpressionModule module = new ExpressionModule("test", bricks);
        LinkedList<ExpressionModule> modules = new LinkedList<ExpressionModule>();
        modules.AddLast(module);

        Device device = Device.buildDevice(modules);
        if(device != null)
        {
            Logger.Log("CraftZoneManager::getDeviceFromBricks produced "+device, Logger.Level.TRACE);
        }
        else
        {
            Logger.Log ("CraftZoneManager::getDeviceFromBricks device==null with bricks="+Logger.ToString<BioBrick>(bricks)
                        , Logger.Level.WARN);
        }
        return device;
    }
   //copy constructor
   public ExpressionModule(ExpressionModule m)
   {
       Logger.Log("ExpressionModule::ExpressionModule("+m+")", Logger.Level.DEBUG);
       _name = m._name;
       _bioBricks = new LinkedList<BioBrick>();
       foreach (BioBrick b in m.getBioBricks())
   {
     _bioBricks.AddLast(b.copy());
   }
 }
Exemple #22
0
    public static Device buildDevice(LinkedList<BioBrick> bricks)
    {
        Logger.Log("Device::buildDevice(bricks) with bricks="+bricks, Logger.Level.INFO);

        ExpressionModule em = new ExpressionModule(bricks);
        return buildDevice(em);
    }
    public bool hasSameBricks(ExpressionModule module) {

        if(module._bioBricks.Count != _bioBricks.Count) {
            return false;
        }

        IEnumerator<BioBrick> enumerator1 = module._bioBricks.GetEnumerator();
        IEnumerator<BioBrick> enumerator2 = _bioBricks.GetEnumerator();

        while(enumerator1.MoveNext() && enumerator2.MoveNext()) {
            if(!enumerator1.Current.Equals(enumerator2.Current)) {
                return false;
            }
        }
        return true;
    }
Exemple #24
0
 public static Device buildDevice(ExpressionModule em)
 {
     Logger.Log("Device::buildDevice(em) with em="+em+")", Logger.Level.INFO);
     LinkedList<ExpressionModule> modules = new LinkedList<ExpressionModule>();
     modules.AddLast(em);
     return buildDevice(em.getInternalName(), modules);
 }
Exemple #25
0
    private static bool checkModuleValidity(ExpressionModule module)
    {
        if (module == null)
          return false;

        LinkedList<BioBrick> bricks = new LinkedList<BioBrick>(module.getBioBricks());
        if (bricks == null)
          return false;
        if (bricks.Count == 0 || bricks.First.Value == null)
          return false;
        if (checkPromoter(bricks.First.Value) == false)
          return false;
        bricks.RemoveFirst();

        if (checkOperon(bricks) == false)
          return false;

        if (bricks.Count == 0 || bricks.First.Value != null || checkTerminator(bricks.First.Value) == false)
          return false;
        bricks.RemoveFirst();
        if (bricks.Count != 0)
          return false;
        return true;
    }
Exemple #26
0
    public LinkedList <Device> loadDevicesFromFile(string filePath)
    {
        Logger.Log("DeviceLoader::loadDevicesFromFile(" + filePath + ")", Logger.Level.INFO);

        LinkedList <Device> resultDevices = new LinkedList <Device>();

        XmlDocument xmlDoc = Tools.getXmlDocument(filePath);

        XmlNodeList deviceList = xmlDoc.GetElementsByTagName(BioBricksXMLTags.DEVICE);

        reinitVars();

        foreach (XmlNode deviceNode in deviceList)
        {
            try
            {
                deviceName = deviceNode.Attributes[BioBricksXMLTags.ID].Value;
            }
            catch (NullReferenceException exc)
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile bad xml, missing field \"id\"\n" + exc, Logger.Level.WARN);
                continue;
            }
            catch (Exception exc)
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile failed, got exc=" + exc, Logger.Level.WARN);
                continue;
            }

            Logger.Log("DeviceLoader::loadDevicesFromFile got id=" + deviceName
                       , Logger.Level.TRACE);


            bool processSuccess = true;

            if (checkString(deviceName))
            {
                // processes longer grammars that use explicit brick nodes names
                if (0 != deviceNode.ChildNodes.Count)
                {
                    foreach (XmlNode attr in deviceNode)
                    {
                        if (attr.Name == BioBricksXMLTags.BIOBRICK)
                        {
                            //find brick in existing bricks
                            string brickName = attr.Attributes[BioBricksXMLTags.ID].Value;
                            if (!processBrick(brickName, filePath))
                            {
                                // processes even longer grammar that uses explicit brick description
                                // because the brick wasn't found neither in 'available' nor 'all' biobricks lists
                                brick = bLoader.loadBioBrick(attr);
                                if (null != brick)
                                {
                                    AvailableBioBricksManager.get().addAvailableBioBrick(brick);
                                    deviceBricks.AddLast(brick);
                                }
                                else
                                {
                                    processSuccess = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Logger.Log("DeviceLoader::loadDevicesFromFile unknown attr " + attr.Name, Logger.Level.WARN);
                        }
                    }
                }
                else
                {
                    // processes shortened grammar that uses only device name
                    foreach (string brickName in deviceName.Split(':'))
                    {
                        if (!processBrick(brickName, filePath))
                        {
                            processSuccess = false;
                            break;
                        }
                    }
                }

                if (processSuccess)
                {
                    ExpressionModule deviceModule = new ExpressionModule(deviceName, deviceBricks);
                    LinkedList <ExpressionModule> deviceModules = new LinkedList <ExpressionModule>();
                    deviceModules.AddLast(deviceModule);
                    device = Device.buildDevice(deviceName, deviceModules);
                    if (device != null)
                    {
                        resultDevices.AddLast(device);
                    }
                }
            }
            else
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile Error : missing attribute id in Device node", Logger.Level.WARN);
            }
            reinitVars();
        }
        return(resultDevices);
    }
Exemple #27
0
    public LinkedList<Device> loadDevicesFromFile(string filePath)
    {
        Logger.Log("DeviceLoader::loadDevicesFromFile(" + filePath + ")", Logger.Level.INFO);

        LinkedList<Device> resultDevices = new LinkedList<Device>();

        XmlDocument xmlDoc = Tools.getXmlDocument(filePath);

        XmlNodeList deviceList = xmlDoc.GetElementsByTagName(BioBricksXMLTags.DEVICE);

        reinitVars();

        foreach (XmlNode deviceNode in deviceList)
        {
            try
            {
                deviceName = deviceNode.Attributes[BioBricksXMLTags.ID].Value;
            }
            catch (NullReferenceException exc)
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile bad xml, missing field \"id\"\n" + exc, Logger.Level.WARN);
                continue;
            }
            catch (Exception exc)
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile failed, got exc=" + exc, Logger.Level.WARN);
                continue;
            }

            Logger.Log("DeviceLoader::loadDevicesFromFile got id=" + deviceName
              , Logger.Level.TRACE);


            bool processSuccess = true;

            if (checkString(deviceName))
            {
                // processes longer grammars that use explicit brick nodes names
                if (0 != deviceNode.ChildNodes.Count)
                {
                    foreach (XmlNode attr in deviceNode)
                    {
                        if (attr.Name == BioBricksXMLTags.BIOBRICK)
                        {
                            //find brick in existing bricks
                            string brickName = attr.Attributes[BioBricksXMLTags.ID].Value;
                            if (!processBrick(brickName, filePath))
                            {
                                // processes even longer grammar that uses explicit brick description
                                // because the brick wasn't found neither in 'available' nor 'all' biobricks lists
                                brick = bLoader.loadBioBrick(attr);
                                if (null != brick)
                                {
                                    AvailableBioBricksManager.get().addAvailableBioBrick(brick);
                                    deviceBricks.AddLast(brick);
                                }
                                else
                                {
                                    processSuccess = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Logger.Log("DeviceLoader::loadDevicesFromFile unknown attr " + attr.Name, Logger.Level.WARN);
                        }
                    }
                }
                else
                {
                    // processes shortened grammar that uses only device name
                    foreach (string brickName in deviceName.Split(':'))
                    {
                        if (!processBrick(brickName, filePath))
                        {
                            processSuccess = false;
                            break;
                        }
                    }
                }

                if (processSuccess)
                {
                    ExpressionModule deviceModule = new ExpressionModule(deviceName, deviceBricks);
                    LinkedList<ExpressionModule> deviceModules = new LinkedList<ExpressionModule>();
                    deviceModules.AddLast(deviceModule);
                    device = Device.buildDevice(deviceName, deviceModules);
                    if (device != null)
                    {
                        resultDevices.AddLast(device);
                    }
                }
            }
            else
            {
                Logger.Log("DeviceLoader::loadDevicesFromFile Error : missing attribute id in Device node", Logger.Level.WARN);
            }
            reinitVars();
        }
        return resultDevices;
    }