cobra.test Package Contents Functions

read_sbml_model(filename, number=float, f_replace=F_REPLACE, **kwargs)

Reads SBML model from given filename.


Returns a cobra model for testing


alias for running all unit-tests on installed cobra

cobra.test.read_sbml_model(filename, number=float, f_replace=F_REPLACE, **kwargs)

Reads SBML model from given filename.

If the given filename ends with the suffix ‘’.gz’’ (for example, ‘’myfile.xml.gz’),’ the file is assumed to be compressed in gzip format and will be automatically decompressed upon reading. Similarly, if the given filename ends with ‘’.zip’’ or ‘’.bz2’,’ the file is assumed to be compressed in zip or bzip2 format (respectively). Files whose names lack these suffixes will be read uncompressed. Note that if the file is in zip format but the archive contains more than one file, only the first file in the archive will be read and the rest ignored.

To read a gzip/zip file, libSBML needs to be configured and linked with the zlib library at compile time. It also needs to be linked with the bzip2 library to read files in bzip2 format. (Both of these are the default configurations for libSBML.)

This function supports SBML with FBC-v1 and FBC-v2. FBC-v1 models are converted to FBC-v2 models before reading.

The parser tries to fall back to information in notes dictionaries if information is not available in the FBC packages, e.g., CHARGE, FORMULA on species, or GENE_ASSOCIATION, SUBSYSTEM on reactions.

  • filename (path to SBML file, or SBML string, or SBML file handle) – SBML which is read into cobra model

  • number (data type of stoichiometry: {float, int}) – In which data type should the stoichiometry be parsed.

  • f_replace (dict of replacement functions for id replacement) – Dictionary of replacement functions for gene, specie, and reaction. By default the following id changes are performed on import: clip G_ from genes, clip M_ from species, clip R_ from reactions If no replacements should be performed, set f_replace={}, None


Return type



Provided file handles cannot be opened in binary mode, i.e., use
with open(path, “r” as f):


File handles to compressed files are not supported yet.


Returns a cobra model for testing

model_name: str

One of ‘ecoli’, ‘textbook’, or ‘salmonella’, or the path to a pickled cobra.Model


alias for running all unit-tests on installed cobra