Title: | An Extensible Approach to Flux Balance Analysis |
---|---|
Description: | 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 <doi:10.1038/nbt.1614>. |
Authors: | Max Conway [aut, cre] |
Maintainer: | Max Conway <[email protected]> |
License: | GPL-3 |
Version: | 0.6.0 |
Built: | 2025-02-09 03:45:07 UTC |
Source: | https://github.com/maxconway/fbar |
Decompose a metabolite table into the metabolite stub itself and the compartment it is in
decompose_metabolites( met_table, compartment_regex = "(\\[[a-zA-Z0-9]+]$)|(_[a-zA-Z]$)" )
decompose_metabolites( met_table, compartment_regex = "(\\[[a-zA-Z0-9]+]$)|(_[a-zA-Z]$)" )
met_table |
A metabolite table, with one column, |
compartment_regex |
Regular expression to identify compartments in model |
a metabolite table with the columns chemical
and compartment
data(ecoli_core) mod <- reactiontbl_to_expanded(ecoli_core) decompose_metabolites(mod$mets) recompose_metabolites(decompose_metabolites(mod$mets))
data(ecoli_core) mod <- reactiontbl_to_expanded(ecoli_core) decompose_metabolites(mod$mets) recompose_metabolites(decompose_metabolites(mod$mets))
A small E. coli model, created from a number of sources.
ecoli_core
ecoli_core
A data frame with 95 rows and 7 columns:
an abbreviated reaction name, acts as the reaction id
lower bound on the reaction rate
upper bound on the reaction rate
identifies a reaction (or reactions) for which the maximum possible rate should be found
reaction equation
full reaction name
A boolean combination of genes which control the reaction
an indicator of reaction function
http://bigg.ucsd.edu, Reconstruction and Use of Microbial Metabolic Networks: the Core Escherichia coli Metabolic Model as an Educational Guide, A comprehensive genome-scale reconstruction of Escherichia coli metabolism–2011.
This function is deprecated. ROI.plugin.glpk
is recommended instead.
expanded_to_glpk(reactions_expanded)
expanded_to_glpk(reactions_expanded)
reactions_expanded |
A list of data frames as output by |
This parses the long format produced by reactiontbl_to_expanded
to a glpk model.
To install the Rglpk package in Linux, run sudo apt-get install libglpk-dev
in a terminal, and then run install.packages('Rglpk')
in R.
The reaction_table
must have columns:
abbreviation
,
equation
,
uppbnd
,
lowbnd
, and
obj_coef
.
A list suitable for input to Rglpk
Other parsing_and_conversion:
expanded_to_ROI()
,
expanded_to_gurobi()
,
reactiontbl_to_expanded()
,
reactiontbl_to_gurobi()
This function is deprecated. github.com/Fl0Sch/ROI.plugin.gurobi
is recommended instead.
expanded_to_gurobi(reactions_expanded)
expanded_to_gurobi(reactions_expanded)
reactions_expanded |
A list of data frames as output by |
Used as the second half of reactiontbl_to_gurobi
, this parses the long format produced by reactiontbl_to_expanded
to a Gurobi model
For installation instructions for Gurobi, refer to the Gurobi website: https://www.gurobi.com/.
The reaction_table
must have columns:
abbreviation
,
equation
,
uppbnd
,
lowbnd
, and
obj_coef
.
A list suitable for input to Gurobi.
Other parsing_and_conversion:
expanded_to_ROI()
,
expanded_to_glpk()
,
reactiontbl_to_expanded()
,
reactiontbl_to_gurobi()
Useful for saving a new or edited model
expanded_to_reactiontbl(expanded)
expanded_to_reactiontbl(expanded)
expanded |
A list of data frames:
|
A data frame describing the metabolic model.
This parses the long format produced by reactiontbl_to_expanded
to an ROI model.
expanded_to_ROI(reactions_expanded)
expanded_to_ROI(reactions_expanded)
reactions_expanded |
A list of data frames as output by |
To solve models using ROI, you will need a solver plugin for ROI. Probably the easiest one to install is ROI.plugin.glpk.
To install this in Linux, run sudo apt-get install libglpk-dev
in a terminal, and then run install.packages('ROI.plugin.glpk')
in R.
The reaction_table
must have columns:
abbreviation
,
equation
,
uppbnd
,
lowbnd
, and
obj_coef
.
A list suitable for input to ROI.
Other parsing_and_conversion:
expanded_to_glpk()
,
expanded_to_gurobi()
,
reactiontbl_to_expanded()
,
reactiontbl_to_gurobi()
## Not run: data(ecoli_core) library(dplyr) try(library(ROI.plugin.ecos)) # make a solver available to ROI roi_model <- ecoli_core %>% reactiontbl_to_expanded %>% expanded_to_ROI if(length(ROI::ROI_applicable_solvers(roi_model))>=1){ roi_result <- ROI::ROI_solve(roi_model) ecoli_core_with_flux <- ecoli_core %>% mutate(flux = roi_result[['solution']]) } ## End(Not run)
## Not run: data(ecoli_core) library(dplyr) try(library(ROI.plugin.ecos)) # make a solver available to ROI roi_model <- ecoli_core %>% reactiontbl_to_expanded %>% expanded_to_ROI if(length(ROI::ROI_applicable_solvers(roi_model))>=1){ roi_result <- ROI::ROI_solve(roi_model) ecoli_core_with_flux <- ecoli_core %>% mutate(flux = roi_result[['solution']]) } ## End(Not run)
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 use 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.
For a list of functions in the package, see vignette('Introduction','fbar')
This function calculates fluxes folds
times with shuffled versions of the metabolic model.
This is designed to detect and quantify underdetermined fluxes.
find_flux_variability_df(reaction_table, folds = 10, do_minimization = TRUE)
find_flux_variability_df(reaction_table, folds = 10, do_minimization = TRUE)
reaction_table |
a data frame representing the metabolic model |
folds |
number of times to calculate fluxes |
do_minimization |
toggle to uniformly minimize all non-objective fluxes after finding the objective |
This function uses ROI, so to solve models, you will need a solver plugin for ROI. Probably the easiest one to install is ROI.plugin.glpk.
To install this in Linux, run sudo apt-get install libglpk-dev
in a terminal, and then run install.packages('ROI.plugin.glpk')
in R.
reaction_table with two added columns: sd (the standard deviation of fluxes found) and flux (a typical flux) from this distribution
Given a metabolic model as a data frame, return a new data frame with fluxes
find_fluxes_df(reaction_table, do_minimization = FALSE)
find_fluxes_df(reaction_table, do_minimization = FALSE)
reaction_table |
a data frame representing the metabolic model |
do_minimization |
toggle to uniformly minimize all non-objective fluxes after finding the objective |
This function uses ROI, so to solve models, you will need a solver plugin for ROI. Probably the easiest one to install is ROI.plugin.glpk.
To install this in Linux, run sudo apt-get install libglpk-dev
in a terminal, and then run install.packages('ROI.plugin.glpk')
in R.
The input data frame with a new numeric column, "flux
".
find_fluxes_vector
## Not run: data(ecoli_core) ecoli_core_with_flux <- find_fluxes_df(ecoli_core) ## End(Not run)
## Not run: data(ecoli_core) ecoli_core_with_flux <- find_fluxes_df(ecoli_core) ## End(Not run)
A convenience function that uses gene_eval
and a custom function to apply new upper and lower bounds.
gene_associate( reaction_table, gene_table, expression_flux_function = function(x) { (1 + log(x)/stats::sd(x)^2)^sign(x - 1) } )
gene_associate( reaction_table, gene_table, expression_flux_function = function(x) { (1 + log(x)/stats::sd(x)^2)^sign(x - 1) } )
reaction_table |
A data frame describing the metabolic model. |
gene_table |
A data frame showing gene presence |
expression_flux_function |
a function to convert from gene set expression to flux |
the reaction_table, with a new column, present, and altered upper and lower bounds
This function relies on gene_eval
, which uses eval
to evaluate gene expression sets.
This gives flexibility, but means that malicious code in the gene_sets
argument could get evaluated.
gene_sets
is evaluated in a restricted environment, but there might be a way around this, so you might want to check for anything suspicious in this argument manually.
For more information, read the code.
gene_eval
data(iJO1366) library(dplyr) gene_table = tibble(name = iJO1366$geneAssociation %>% stringr::str_split('and|or|\\s|\\(|\\)') %>% purrr::flatten_chr() %>% unique, presence = 1) %>% filter(name != '', !is.na(name)) gene_associate(reaction_table = iJO1366 %>% mutate(geneAssociation = geneAssociation %>% stringr::str_replace_all('and', '&') %>% stringr::str_replace_all('or', '|') ), gene_table = gene_table )
data(iJO1366) library(dplyr) gene_table = tibble(name = iJO1366$geneAssociation %>% stringr::str_split('and|or|\\s|\\(|\\)') %>% purrr::flatten_chr() %>% unique, presence = 1) %>% filter(name != '', !is.na(name)) gene_associate(reaction_table = iJO1366 %>% mutate(geneAssociation = geneAssociation %>% stringr::str_replace_all('and', '&') %>% stringr::str_replace_all('or', '|') ), gene_table = gene_table )
Function to estimate the expression levels of gene sets
gene_eval(gene_sets, genes, presences)
gene_eval(gene_sets, genes, presences)
gene_sets |
A list of gene set strings: names of genes punctuated with |
genes |
A list of gene names |
presences |
A list of gene presences, the same length as |
a vector the same length as gene_sets
, with the the calculated combined gene expression levels.
This function evaluates the gene sets in the context of the gene presences.
It can take booleans, or numbers, in which case it associates &
with finding the minimum, and |
with finding the maximum.
This function uses eval
to evaluate gene expression sets.
This gives flexibility, but means that malicious code in the gene_sets
argument could get evaluated.
gene_sets
is evaluated in a restricted environment, but there might be a way around this, so you might want to check for anything suspicious in this argument manually.
For more information, read the code.
gene_associate
Download a model from a BiGG json file
get_BiGG(address)
get_BiGG(address)
address |
An address to download from |
A model in expanded format
A full size E. coli model.
iJO1366
iJO1366
A data frame with 2,583 rows and 10 columns:
an abbreviated reaction name, acts as the reaction id
lower bound on the reaction rate
upper bound on the reaction rate
identifies a reaction (or reactions) for which the maximum possible rate should be found
reaction equation
full reaction name
A boolean combination of genes which control the reaction
an indicator of reaction function
http://bigg.ucsd.edu, A comprehensive genome-scale reconstruction of Escherichia coli metabolism–2011.
A subset of exchange reactions annotated to indicate typical availability
nutrient_types
nutrient_types
A data frame with 25 rows and 2 columns:
an exchange reaction id
the nutrient availability, one of 'micro', 'macro' or 'substrate'
Internal function: Expand half reaction equations into a long form
parse_met_list(mets)
parse_met_list(mets)
mets |
Character vector of halves of reaction equations. |
a date_frame
with columns:
the stoichiometric coefficient
the metabolite
The long format can also be suitable for manipulating equations.
reactiontbl_to_expanded(reaction_table, regex_arrow = "<?[-=]+>")
reactiontbl_to_expanded(reaction_table, regex_arrow = "<?[-=]+>")
reaction_table |
A data frame describing the metabolic model. |
regex_arrow |
Regular expression for the arrow splitting sides of the reaction equation. |
The reaction_table
must have columns:
abbreviation
,
equation
,
uppbnd
,
lowbnd
, and
obj_coef
.
A list of data frames:
rxns
, which has one row per reaction,
mets
, which has one row for each metabolite, and
stoich
, which has one row for each time a metabolite appears in a reaction.
Other parsing_and_conversion:
expanded_to_ROI()
,
expanded_to_glpk()
,
expanded_to_gurobi()
,
reactiontbl_to_gurobi()
## Not run: data(ecoli_core) library(dplyr) try(library(ROI.plugin.ecos)) # make a solver available to ROI roi_model <- ecoli_core %>% reactiontbl_to_expanded %>% expanded_to_ROI if(length(ROI::ROI_applicable_solvers(roi_model))>=1){ roi_result <- ROI::ROI_solve(roi_model) ecoli_core_with_flux <- ecoli_core %>% mutate(flux = roi_result[['solution']]) } ## End(Not run)
## Not run: data(ecoli_core) library(dplyr) try(library(ROI.plugin.ecos)) # make a solver available to ROI roi_model <- ecoli_core %>% reactiontbl_to_expanded %>% expanded_to_ROI if(length(ROI::ROI_applicable_solvers(roi_model))>=1){ roi_result <- ROI::ROI_solve(roi_model) ecoli_core_with_flux <- ecoli_core %>% mutate(flux = roi_result[['solution']]) } ## End(Not run)
This function is deprecated. github.com/Fl0Sch/ROI.plugin.gurobi
is recommended instead.
reactiontbl_to_gurobi(reaction_table, regex_arrow = "<?[-=]+>")
reactiontbl_to_gurobi(reaction_table, regex_arrow = "<?[-=]+>")
reaction_table |
A data frame describing the metabolic model. |
regex_arrow |
Regular expression for the arrow splitting sides of the reaction equation. |
Parses a reaction table to give a list in Gurobi's input format.
This function is a shorthand for reactiontbl_to_expanded
followed by expanded_to_gurobi
.
The reaction_table
must have columns:
abbreviation
,
equation
,
uppbnd
,
lowbnd
, and
obj_coef
.
A list suitable for input to Gurobi.
Other parsing_and_conversion:
expanded_to_ROI()
,
expanded_to_glpk()
,
expanded_to_gurobi()
,
reactiontbl_to_expanded()
Merge metabolite stub and compartment to form an id
recompose_metabolites( expanded_metabolites, before_signifier = "_", after_signifier = "" )
recompose_metabolites( expanded_metabolites, before_signifier = "_", after_signifier = "" )
expanded_metabolites |
a metabolite table as created by |
before_signifier |
a string that is inserted before the compartment identifier |
after_signifier |
a string that is inserted after the compartment identifier |
A merged metabolite table with one column, met
data(ecoli_core) mod <- reactiontbl_to_expanded(ecoli_core) decompose_metabolites(mod$mets) recompose_metabolites(decompose_metabolites(mod$mets))
data(ecoli_core) mod <- reactiontbl_to_expanded(ecoli_core) decompose_metabolites(mod$mets) recompose_metabolites(decompose_metabolites(mod$mets))
Internal function: Splitting reaction equation into substrate and product
split_on_arrow(equations, regex_arrow = "<?[-=]+>")
split_on_arrow(equations, regex_arrow = "<?[-=]+>")
equations |
Character vector of reaction equations. |
regex_arrow |
Regular expression for the arrow splitting sides of the reaction equation. |
a data_frame
, with columns:
boolean, is reaction reversible
the left hand side of the reaction string
the right hand side of the reaction string
Validate an expanded model
validate_expanded(reactions_expanded)
validate_expanded(reactions_expanded)
reactions_expanded |
the expanded model to check |
TRUE