An Extensible Approach to Flux Balance Analysis

A toolkit for Flux Balance Analysis and related metabolic modeling techniques. Functions are provided for: parsing models in tabular format, converting parsed metabolic models to input formats for common linear programming solvers, and evaluating and applying gene-protein-reaction mappings. In addition, there are wrappers to parse a model, select a solver, find the metabolic fluxes, and return the results applied to the original model. Compared to other packages in this field, this package puts a much heavier focus on providing reusable components that can be used in the design of new implementation of new techniques, in particular those that involve large parameter sweeps. For a background on the theory, see What is Flux Balance Analysis .

Travis-CI Build Status

fbar is a simple, easy to use Flux Balance Analysis package with a tidy data approach. Just data_frames and the occasional list, no new classes to learn. The focus is on simplicity and speed. Models are expected as a flat table, and results can be simply appended to the table. This makes this package very suitable for useage in pipelines with pre- and post- processing of models and results, so that it works well as a backbone for customized methods. Loading, parsing and evaluating a model takes around 0.1s, which, together with the straightforward data structures used, makes this library very suitable for large parameter sweeps.

A Simple Example

This example calculates the fluxes for the model ecoli_core. Ecoli_core starts out as a data frame, and is returned as the same data frame, with fluxes appended.

try({ # this will fail if no appropriate solver is available.
  ecoli_core_with_flux <- find_fluxes_df(ecoli_core)

A Complicated Example

This example finds the fluxes in ecoli_core, just like the previous case. However, this has more detail to show how the package works.

roi_model <- ecoli_core %>%
  reactiontbl_to_expanded %>%
# If you don't have an appropriate solver, see the section on installing 
# one later in this document.
  roi_result <- ROI_solve(roi_model)
  ecoli_core_with_flux <- ecoli_core %>%
    mutate(flux = roi_result[['solution']])

This example expands the single data frame model into an intermediate form, the collapses it back to a gurobi model and evaluates it. Then it adds the result as a column, named flux. This longer style is useful because it allows access to the intermediate form. This just consists of three data frames: metabolites, stoichiometry, and reactions. This makes it easy to alter and combine models.


fbar's functions can be considered in three groups: convenience wrappers which perform a common workflow all in one go, parsing and conversion functions that form the core of the package and provide extensibility, and functions for gene set processing which allow models to be parameterized by genetic information.

Convenience wrappers

These functions wrap common workflows. They parse and evaluate models all in one go.

  • find_fluxes_df - Given a metabolic model as a data frame, return a new data frame with fluxes. For simple FBA, this is what you want.
  • find_flux_varability_df - Given a metabolic model as a data frame, return a new data frame with fluxes and variability.

Parsing and conversion

These functions convert metabolic models between different formats.

  • reactiontbl_to_expanded - Convert a reaction table to an expanded, intermediate, format.
  • expanded_to_gurobi, expanded_to_glpk and expanded_to_ROI - Convert a metabolic model in expanded format to the input format for a linear programming library.
  • reactiontbl_to_gurobi - Convert a reaction table data frame to gurobi format. This is shorthand for reactiontbl_to_expanded followed by expanded_to_gurobi.

Gene set processing

These functions process gene protein reaction mappings.

  • gene_eval - Evaluate gene sets in the context of particular gene presence levels.
  • gene_associate - Apply gene presence levels to a metabolic model.

Notes and FAQs


Install this package:


Install a linear programming solver:

This package requires a linear programming solver. There are a number of options for this (see below), but the easiest way to get started is to install ROI.plugin.ecos (one of the suggested packages).


Comparison with other packages

The most famous package for constraint based methods is probably COBRA, a Matlab package. If you prefer Matlab to R, you'll probably want to try that before fbar.

The existing R packages for Flux Balance Analysis include sybil and abcdeFBA. Compared to these packages, fbar is smaller and does less. The aim of fbar is to be more suitable for use as a building block in bioinformatics pipelines. Whereas sybil and to a lesser extent abcdeFBA intend to act as tools with a function for each analysis you might want to do, fbar intends to supply just enough functionality that you can easily construct your analysis with only standard data frame operations.

Linear programming solvers

fbar uses ROI by default, which gives access to a number of solvers via plugins. It also supports Rglpk and Gurobi directly. Gurobi is substantially faster than other solvers in my experience, so it is recommended if you can get it (it is commercial, but has a free academic licence).

Bugs and feature requests

If you find problems with the package, or there's anything that it doesn't do which you think it should, please submit them to In particular, let me know about optimizers and formats which you'd like supported, or if you have a workflow which might make sense for inclusion as a default convenience function.


fbar 0.5.2

  • Fix to getBiGG function
  • Fix to vignette

fbar 0.4.4

  • New function for retrieving models from BiGG
  • Changes to model data files
  • New data file to help specify exchange reactions
  • Changed some function argument defaults

fbar 0.3.4

  • Test updates and tidying to work with new version of ROI
  • New tests
  • Spelling corrections
  • Moving to assuming availability of ecos solver. All other solvers still supported

fbar 0.3.3

  • Spelling corrections

fbar 0.3.2

  • Minor updates for Cran release

fbar 0.3.1

  • Created website using pkgdown

fbar 0.3.0

  • Moved to new NSE framework

fbar 0.2.2

  • Deprecated expanded_to_gurobi, expanded_to_glpk and reactiontbl_to_gurobi. ROI will now be the only backend.

fbar 0.2.1

  • Updated and corrected some test code
  • Added test and fix for situation where metabolite is used multiple times in one reaction string
  • Small updates to vignettes and readme

fbar 0.2.0

  • Added new functions for metabolite parsing
  • Added more documentation

fbar 0.1.23

  • Added DONTRUN to some examples which take too long on some platforms

fbar 0.1.19

  • New vignette

fbar 0.1.18

  • variety of bug fixes

fbar 0.1.17

  • Started moving to using ROI.plugin.ecos for examples and tests, since it has no dependencies
  • New function to convert from an expanded model back to a reaction table
  • Fixed a bug in the total flux minimization code of find_fluxes_df

fbar 0.1.16

  • Changes to tests to reduce chatter further

fbar 0.1.15

  • Description changes to remove notes

fbar 0.1.14

  • Changed the title
  • Changed the description
  • Typo fixed

fbar 0.1.13

  • Checks and filters in tests, vigentte and examples to remove implicit dependency on ROI.plugin.glpk.
  • Other pdates and improvements to documentation and examples.
  • Updated tests for cleaner output

fbar 0.1.12

  • Tweaks and updates for CRAN submission

fbar 0.1.9

  • Started using travis for integration

fbar 0.1.8

  • Test updates

fbar 0.1.1

  • Changed optimization framework - can now use one of a choice of optimizers
  • Lots more documentation
  • Name changes and refactoring

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.