CONTRIBUTORS: Written: Regan ODONGO, Edited: Tunahan ÇAKIR

Procedure for using Gurobi solver in R for FBA

R programming uses different file formats as is explained next. Also, this section will describe only the data acquisition to FBA using Gurobi solver steps. All the other steps should be followed as previously described.

In R, data can be loaded and saved as follows:

  • Load the Excel file using stoichMat<- readxl::read_excel(‘filename.xlsx’), assuming the file is named ‘filename.xlsx’. NOTE: R is dependent on packages so remember to load this package using library(readxl) before attempting to import the excel file.

  • Next, use saveRDS(stoichMat,file=‘stoichMat.RDS’) to save the matrix as a .RDS file object.

  • This .RDS file can be introduced into the working space memory of R using the ‘readRDS’ function, e.g. readRDS(‘stoichMat.RDS).

Note that. RData is an alternative to .RDS. However, .RDS is more suitable for storing single variables like in the current case.

Using Gurobi in R

First and foremost, Gurobi in R requires installation and loading to the current working memory of two main packages; ‘gurobi’ and ‘slam’ as follows:

        install.packages(‘c:/gurobi800/win64/R/gurobi_8.0-0.zip’, repos = NULL)

        install.packages(‘slam’, repos = ‘https://cloud.r-project.org’)

        library(gurobi)

The general implementation steps are as follows:

Here, the object ‘model’ is an R list object with the following main fields similar to those described for MATLAB:

  • model$A → An mxn matrix. the S matrix (stoichiometric matrix) must be renamed as model.A and stored as a sparse matrix. Using sparse(S) returns a sparse matrix for the S matrix.

  • model$obj → An nx1 vector. The objective function vector, f, explained above must be renamed as model.obj.

  • model$lb → An nx1 vector. The lower bound vector.

  • model$ub → An nx1 vector. The upper bound vector.

  • model$rhs → A zero m×1 vector. The right-hand-side vector, b, explained above must be renamed as model.rhs.

  • model$vtype → An nx1 vector. It is a cell array that can be of ‘B’, ‘C’ or ‘I’ for binary, continuous and integer respectively based on the problem being solved. In FBA, all the unknowns (rates) are continuous. Therefore, all elements of model.vtype is set to ‘C’.

  • model$sense → An mx1 vector. It is a cell array that can be of ‘=’, ‘<’ or ‘>’ for equality or inequality. It defines the model equality/inequality constraint. In FBA, all the linear set of equations derived from the differential mass balances are equality equations. Therefore, all elements of model.sense is set to ‘=’.

For simplicity, the above object can be defined as follows in R:

        model = list()

        model$A = S

        model$obj = c(rep(0,ncol(S)))

        model$lb = lb

        model$ub = ub

        model$rhs = c(rep(0,nrow(S)))

        model$vtype = 'C'

        model$sense = '='

Further information on how to handle models in using Gurobi solver can be found here. The output ‘sol’ is similar to the one obtained from MATLAB as described previously.