示例#1
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Need one argument, the SBML file to solve");
                Environment.Exit(-1);
            }

            string sbmlContent = File.ReadAllText(args[0]);
            FluxBalance fluxBalance = new FluxBalance();

            fluxBalance.LoadSBML(sbmlContent);

            fluxBalance.Constraints = new List<LPsolveConstraint>(new LPsolveConstraint[] {
                new LPsolveConstraint("J1", lpsolve_constr_types.EQ, 10.0),
                new LPsolveConstraint("J5", lpsolve_constr_types.EQ, 6.0),
                new LPsolveConstraint("J3", lpsolve_constr_types.GE, 1.0)
            });

            fluxBalance.Objectives = new List<LPsolveObjective>(new LPsolveObjective[] {
                new LPsolveObjective("J9", 0.5),
                new LPsolveObjective("J8", 0.75)
            });

            LPsolveSolution result = fluxBalance.Solve();

            result.WriteTo(Console.Out);

            Console.WriteLine("(any key to continue)");
            Console.ReadKey();
        }
示例#2
0
        private static string ConvertSBML(string sbmlContent)
        {
            FluxBalance fluxBalance = new FluxBalance();
            fluxBalance.Mode = FBA_Mode.maximize;

            // read SBML
            NOM.loadSBML(sbmlContent);

            // fix boundary flags
            var model = NOM.SbmlModel;
            for (int i = 0; i < model.getNumSpecies(); i++)
            {
                Species species = model.getSpecies(i);
                if (species.getId().EndsWith("_b"))
                    species.setBoundaryCondition(true);
            }

            // find objective
            for (int i = 0; i < model.getNumReactions(); i++)
            {
                Reaction reaction = model.getReaction(i);
                if (reaction.isSetKineticLaw())
                {
                    KineticLaw law = reaction.getKineticLaw();
                    var parameter = law.getParameter("OBJECTIVE_COEFFICIENT");
                    if (parameter == null || parameter.getValue() != 1.0)
                        continue;
                    fluxBalance.Objectives.Add(new LPsolveObjective(reaction.getId(), 1.0));
                    reaction.unsetKineticLaw();
                }
            }

            // build constraints
            for (int i = 0; i < model.getNumReactions(); i++)
            {
                Reaction reaction = model.getReaction(i);
                if (reaction.isSetKineticLaw())
                {
                    KineticLaw law = reaction.getKineticLaw();
                    var lowerBound = law.getParameter("LOWER_BOUND");
                    var upperBound = law.getParameter("UPPER_BOUND");

                    if (lowerBound == null || upperBound == null) continue;

                    fluxBalance.Constraints.Add(new LPsolveConstraint(reaction.getId(), lpsolve_constr_types.LE, lowerBound.getValue()));
                    fluxBalance.Constraints.Add(new LPsolveConstraint(reaction.getId(), lpsolve_constr_types.GE, upperBound.getValue()));

                    reaction.unsetKineticLaw();
                }
            }

            string newSBML = libsbml.writeSBMLToString(NOM.SbmlDocument);

            fluxBalance.SBML = newSBML;

            return fluxBalance.WriteSBML();
        }
示例#3
0
        public void loadSBML(string sbmlContent)
        {
            SBML = Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(sbmlContent));

            reactionTextTable = new Hashtable();

            _FluxBalance = new FluxBalance(SBML);

            if (_FluxBalance.Warnings.Count > 0)
            {
              MessageBox.Show(this,
                  _FluxBalance.Warnings[0],
                  "Warnings occured...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (_FluxBalance.IsEmpty)
            {
                MessageBox.Show(this,
                    "The model you have loaded has an empty Stoichiometry Matrix. As such the model is not suited for Flux Balance Analysis. Please ensure that you loaded a model that uses SBML non-boundary species and reactions.",
                    "Model not suitable", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            bool doLayout = true;
            if (_FluxBalance.SpeciesNames.Count > 100 || _FluxBalance.ReactionNames.Count > 100)
            {
                if (MessageBox.Show(this,
                    string.Format(
                        "The model you have loaded has {0} species and {1} reactions. Would you still like to generate an image for it? The image is unlikely to provide much information.",
                        _FluxBalance.SpeciesNames.Count, _FluxBalance.ReactionNames.Count),
                    "Generate Layout?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    doLayout = false;
            }

            if (doLayout)
                InitializeLayout(SBML, _FluxBalance);

            if (SBMLLayout.Instance.hasLayout())
            {
                splitContainer2.Panel1Collapsed = false;
                SetImage();
            }
            else
            {
                splitContainer2.Panel1Collapsed = true;
            }

            controlSetup1.InitializeFromReactionNames(_FluxBalance.ReactionNames);

            controlSetup1.Maximize = _FluxBalance.Mode == FBA_Mode.maximize;
            controlSetup1.Minimize = _FluxBalance.Mode == FBA_Mode.minimize;

            controlSetup1.Constraints = _FluxBalance.Constraints;
            controlSetup1.Objectives = _FluxBalance.Objectives;
        }
示例#4
0
        private void InitializeLayout(string sbmlContent, FluxBalance fluxBalance)
        {
            // load Layout
            SBMLLayout.Instance.loadSBML(sbmlContent);

            if (!SBMLLayout.Instance.hasLayout())
            {
                GenerateLayout();
                return;
            }

            reactionTextTable = new Hashtable();

            int reactionCount = 0;
            // foreach reaction add a reaction label
            foreach (ReactionGlyph reactionGlyph in SBMLLayout.Instance.CurrentLayout.ReactionGlyphs)
            {
                var dimension = new[] {100.0, 100.0};
                double[] position = GetPosition(reactionGlyph);
                position[0] = position[0] - 50;

                string currentLabel = reactionGlyph.Name;

                Text text2 = CreateTextLabel(currentLabel);
                text2.Stroke = "FFFFFF";
                text2.FontSize = "22";
                text2.TextAnchor = "middle";

                Text text = CreateTextLabel(currentLabel);
                text.TextAnchor = "middle";

                var style = new LocalStyle();
                style.Group.Children.Add(text2);
                style.Group.Children.Add(text);
                style.IdList = "fb_label_" + reactionCount;

                SBMLLayout.Instance.CurrentLayout.EmlDefault.Styles.Add(style);

                SBMLLayout.Instance.addTextGlyph("fb_label_" + reactionCount, currentLabel, currentLabel, position,
                    dimension);

                TextGlyph textGlyph = SBMLLayout.Instance.CurrentLayout.findTextGlyphById("fb_label_" + reactionCount);

                reactionTextTable[currentLabel] = new TempLabel(textGlyph, text, style);

                reactionCount++;
            }
        }