Input / output#

MATLAB functions in RAVEN/src/io of the RAVEN toolbox.

Functions#

Function

Summary

checkFileExistence

Check whether files exist.

cleanSheet

exportForGit

Export a model for a Git-maintained model repository.

exportModel

Export a constraint-based model to an SBML file (L3V1 FBCv2).

exportToExcelFormat

Export a model to the Microsoft Excel model format.

importModel

Import a constraint-based model from an SBML file.

parseYAML

Read a YAML file into a tree of MATLAB structs and cells.

readFasta

Read sequences from a FASTA file.

readYAMLmodel

Read a model structure from a YAML file.

writeExcel

Write one or more sheets to an .xlsx (Office Open XML) file.

writeFasta

Write sequences to a FASTA file.

writeYAMLmodel

Write a model to a YAML file in the cobra-format !!omap structure.

Reference#

checkFileExistence#

function files=checkFileExistence(files,varargin)

Check whether files exist.

A file name without a full path refers to a file in the current folder, which is prepended to the file name.

Parameters

files : char or cell

string or cell array of strings with the path or file name of one or more files.

Name-Value Arguments

fullOrTemp : double

controls path handling (default 0):

  • 0 : do not change path to file(s)

  • 1 : return full path to file(s)

  • 2 : copy file(s) to system default temporary folder and return full path

allowSpace : logical

true if the space character is allowed in the path (default true).

checkExist : logical

true if file existence is checked. Setting it to false returns the full path to a file that does not exist yet (default true). Can only be set to false if fullOrTemp is set to 1.

Returns

files : char or cell

string or cell array of strings with updated paths if fullOrTemp is 1 or 2, otherwise the original paths.

Examples

files = checkFileExistence(files, fullOrTemp, allowSpace, checkExist);

cleanSheet#

function [raw,keptRows,keptCols]=cleanSheet(raw,varargin)

exportForGit#

function out=exportForGit(model,varargin)

Export a model for a Git-maintained model repository.

Generates a directory structure and populates it with model files, ready to be committed to a Git or GitHub repository of a model. Writes the model as SBML L3V1 FBCv2 (XML) and YAML, COBRA text, MATLAB MAT-file and Microsoft Excel formats.

The flags mainBranchFlag, subDirs, COBRAtext and neverPrefixIDs accept a scalar logical, the value 0 or 1, or an empty value for the default. Text and other types raise RAVEN:badInput.

Parameters

model : struct

model structure in RAVEN format that should be exported.

Name-Value Arguments

prefix : char

prefix for all filenames (default 'model').

path : char

path where the directory structure should be generated and populated with all files (default current working directory). The folder, with any missing parent folders, is created if it does not exist.

formats : cell

cell array of strings specifying in what file formats the model should be exported (default all formats as {'mat', 'txt', 'xlsx', 'xml', 'yml'}).

mainBranchFlag : logical

true to raise an error if RAVEN (and GECKO for enzyme-constrained models) is not on the main or master branch (default false).

subDirs : logical

true to write the model files of each file format in their own subdirectory, with 'model' as parent directory, following the standard-GEM repository format. If false, all files are stored in the same folder (default true).

COBRAtext : logical

true to write the txt file in COBRA Toolbox format, which uses metabolite IDs. If false, the file uses metabolite names and compartments (default false).

neverPrefixIDs : logical

true if prefixes are never added to identifiers, even if they start with digits. This can result in invalid SBML files (default false).

Examples

exportForGit(model, prefix, path, formats, mainBranchFlag, subDirs, ...
    COBRAtext, neverPrefixIDs);

exportModel#

function exportModel(model,varargin)

Export a constraint-based model to an SBML file (L3V1 FBCv2).

Parameters

model : struct

a model structure.

Name-Value Arguments

fileName : char

file name to export the model to. A dialog window opens if no file name is specified.

neverPrefix : logical

true if prefixes are never added to identifiers, even if they start with digits. This can result in invalid SBML files (default false).

supressWarnings : logical

true if warnings should be suppressed. The check of the model structure (checkModelStruct) is skipped, which can result in invalid SBML files (default false).

sortIds : logical

true to sort metabolites, reactions and genes alphabetically by their identifiers (default false).

Examples

exportModel(model, fileName, neverPrefix, supressWarnings, sortIds);

exportToExcelFormat#

function exportToExcelFormat(model,varargin)

Export a model to the Microsoft Excel model format.

Parameters

model : struct

a model structure.

Name-Value Arguments

fileName : char

file name of the Excel file. Only the xlsx format is supported. A dialog window opens if fileName is empty.

sortIds : logical

true to sort metabolites, reactions and genes alphabetically by their identifiers (default false).

Examples

exportToExcelFormat(model, fileName, sortIds);

importModel#

function model=importModel(varargin)

Import a constraint-based model from an SBML file.

Name-Value Arguments

fileName : char

a SBML file to import. A dialog window opens if no file name is specified.

removeExcMets : logical

true to remove exchange metabolites from the imported model (default true).

removePrefix : logical

true to remove identifier prefixes when loading the model: G_ for genes, R_ for reactions, M_ for metabolites, and C_ for compartments. The prefix of a type is removed only if all identifiers of that type contain it (default true).

supressWarnings : logical

true to suppress warnings about the model structure (default false).

Returns

model : struct

imported model structure with fields:

  • id : model ID

  • name : name of model contents

  • annotation : additional information about model

  • rxns : reaction ids

  • mets : metabolite ids

  • S : stoichiometric matrix

  • lb : lower bounds

  • ub : upper bounds

  • rev : reversibility vector

  • c : objective coefficients

  • b : equality constraints for the metabolite equations

  • comps : compartment ids

  • compNames : compartment names

  • compOutside : the id (as in comps) for the compartment surrounding each of the compartments

  • compMiriams : structure with MIRIAM information about the compartments

  • rxnNames : reaction description

  • rxnComps : compartments for reactions

  • grRules : reaction to gene rules in text form

  • rxnGeneMat : reaction-to-gene mapping in sparse matrix form

  • subSystems : subsystem name for each reaction

  • eccodes : EC-codes for the reactions

  • rxnMiriams : structure with MIRIAM information about the reactions

  • rxnNotes : reaction notes

  • rxnReferences : reaction references

  • rxnConfidenceScores : reaction confidence scores

  • rxnDeltaG : reaction Gibbs free energy, from the deltaG notes field (the convention that exportModel writes and raven-toolbox reads and writes; omitted if no reaction has one)

  • genes : list of all genes

  • geneComps : compartments for genes

  • geneMiriams : structure with MIRIAM information about the genes

  • geneShortNames : gene alternative names (for example ERG10)

  • proteins : protein associated to each gene

  • metNames : metabolite description

  • metComps : compartments for metabolites

  • inchis : InChI-codes for metabolites

  • metFormulas : metabolite chemical formula

  • metMiriams : structure with MIRIAM information about the metabolites

  • metCharges : metabolite charge

  • metDeltaG : metabolite Gibbs free energy, from the deltaG notes field (the convention that exportModel writes and raven-toolbox reads and writes; omitted if no metabolite has one)

  • unconstrained : true if the metabolite is an exchange metabolite

Examples

model = importModel(fileName, removeExcMets, removePrefix, supressWarnings);

Notes

checkModelStruct checks the consistency of the imported model and raises warnings about problems in the model structure. supressWarnings skips this check.

parseYAML#

function out = parseYAML(filename)

Read a YAML file into a tree of MATLAB structs and cells.

Supports block-style mappings and sequences (indentation-based), flow-style mappings and sequences ({ key: value }, [a, b]), quoted and unquoted scalars, and comments. Does not support multi-document files, anchors, aliases, tags, or block scalars (|, >).

The function parses YAML configuration and data files with nested mappings, sequences and scalars (for example condition files consumed by applyCondition). readYAMLmodel loads a cobra-format model YAML: it applies the model schema and returns a populated RAVEN model struct.

Parameters

filename : char

path to the YAML file.

Returns

out : struct or cell or char or double or logical or []

MATLAB representation of the document:

  • mapping -> struct (keys sanitised to valid MATLAB field names)

  • sequence -> cell column vector

  • quoted or unquoted string -> char

  • integer or float -> double

  • true, false -> logical

  • null / ~ / empty value -> []

Examples

cfg = parseYAML('data/conditions/anaerobic.yml');

See also

readYAMLmodel

readFasta#

function fastaStruct=readFasta(fileName)

Read sequences from a FASTA file.

Reads a FASTA file into a structure array, providing the same Header and Sequence fields as the Bioinformatics Toolbox fastaread, but using only base MATLAB so that no toolbox is required.

Parameters

fileName : char

path to the FASTA file to read.

Returns

fastaStruct : struct

structure array with one element per sequence, with the fields:

  • Header : the header line, without the leading ">"

  • Sequence : the sequence with all line breaks removed

Examples

fastaStruct = readFasta('proteins.fa');

See also

writeFasta

readYAMLmodel#

function model=readYAMLmodel(varargin)

Read a model structure from a YAML file.

Reads a yaml file in the cobra-format model yaml structure that writeYAMLmodel writes.

Name-Value Arguments

fileName : char

a model file in yaml file format. A dialog window opens if no file name is specified.

verbose : logical

true to print the progress (default false).

Returns

model : struct

a model structure.

Examples

model = readYAMLmodel(fileName, verbose);

writeExcel#

function writeExcel(fileName,sheets)

Write one or more sheets to an .xlsx (Office Open XML) file.

Writes data to one or more worksheets of an .xlsx file. Each sheet can have a bold header row (frozen at the top), column widths and per-column number formats. Numeric, text and logical cell values are supported; empty values are written as blank cells.

Parameters

fileName : char

path of the .xlsx file to write. An existing file is overwritten.

sheets : struct

struct array, one element per worksheet, with fields: name : char the worksheet name (truncated to 31 characters; the characters []*?/: are removed). data : cell cell matrix with the cell values. Supported value types are char (text), numeric scalar, logical, and empty (written as a blank cell). header : cell, optional column captions written as a bold, frozen first row above the data (default none). widths : double, optional vector of column widths in character units (default: column widths are left to the spreadsheet application). isIntegers : logical, optional if true numeric cells use the '0' number format, otherwise '##0.00' (default true). colFormats : cell, optional per-column number-format codes that override the sheet default for individual columns (default none).

Examples

s.name='SHEET1'; s.header={'ID','VALUE'}; s.data={'a',1;'b',2};
writeExcel('out.xlsx',s);

See also

exportToExcelFormat

writeFasta#

function writeFasta(fileName,fastaStruct,lineWidth)

Write sequences to a FASTA file.

Writes a structure array of sequences to a FASTA file, replacing the Bioinformatics Toolbox fastawrite with base MATLAB so that no toolbox is required. An existing file is overwritten.

Parameters

fileName : char

path to the FASTA file to write.

fastaStruct : struct

structure array with one element per sequence, with the fields:

  • Header : the header line (written after a leading ">")

  • Sequence : the sequence

lineWidth : double

number of residues per sequence line (default 80).

Examples

writeFasta('proteins.fa', fastaStruct);

See also

readFasta

writeYAMLmodel#

function writeYAMLmodel(model,varargin)

Write a model to a YAML file in the cobra-format !!omap structure.

The format uses the standard !!omap layout, extended with RAVEN-only top-level per-entry keys (inchis, deltaG, metFrom, rxnFrom, references, confidence_score, protein, notes) and the GECKO ec-rxns and ec-enzymes sections. Reaction EC numbers are written inside the annotation block as ec-code, not as a top-level reaction key.

Parameters

model : struct

a model structure.

Name-Value Arguments

fileName : char

name of the file. A dialog window opens if no file name is specified.

sortIds : logical

true to sort metabolites, reactions, genes and compartments alphabetically by their identifier. If false, they keep their original order (default false).

Examples

writeYAMLmodel(model,fileName,sortIds);