# psamm.datasource.native – Native data format parser¶

Module for reading and writing native formats.

These formats are either table-based or YAML-based. Table-based formats are space-separated and empty lines are ignored. Comments starting with pound (#). YAML-based formats are structured data following the YAML specification.

class psamm.datasource.native.ModelReader(model_from, context=None)

Reader of native YAML-based model format.

The reader can be created from a model YAML file or directly from a dict, string or File-like object. Use reader_from_path() to read the model from a YAML file or directory and use the constructor to read from other sources. Any externally referenced file (with include) will be read on demand by the parse methods. To read the model fully into memory, use the create_model() to create a NativeModel.

biomass_reaction

Biomass reaction specified by the model.

create_model()

Return NativeModel fully loaded into memory.

default_compartment

Default compartment specified by the model.

The compartment that is implied when not specified. In some contexts (e.g. for exchange compounds) the extracellular compartment may be implied instead. Defaults to ‘c’.

default_flux_limit

Default flux limit specified by the model.

When flux limits on reactions are not specified, this value will be used. Flux limit of [0;x] will be implied for irreversible reactions and [-x;x] for reversible reactions, where x is this value. Defaults to 1000.

extracellular_compartment

Extracellular compartment specified by the model.

Defaults to ‘e’.

has_model_definition()

Return True when the list of model reactions is set in the model.

name

Name specified by the model.

parse_compartments()

Parse compartment information from model.

Return tuple of: 1) iterator of psamm.datasource.entry.CompartmentEntry; 2) Set of pairs defining the compartment boundaries of the model.

parse_compounds()

Yield CompoundEntries for defined compounds

parse_exchange()

Yield tuples of exchange compounds.

Each exchange compound is a tuple of compound, reaction ID, lower and upper flux limits.

parse_limits()

Yield tuples of reaction ID, lower, and upper bound flux limits

parse_medium()

Yield tuples of exchange compounds.

Each exchange compound is a tuple of compound, reaction ID, lower and upper flux limits.

parse_model()

Yield reaction IDs of model reactions

parse_reactions()

Yield tuples of reaction ID and reactions defined in the model

classmethod reader_from_path(path)

Create a model from specified path.

Path can be a directory containing a model.yaml or model.yml file or it can be a path naming the central model file directly.

class psamm.datasource.native.ModelWriter

Writer for native (YAML) format.

convert_compartment_entry(compartment, adjacencies)

Convert compartment entry to YAML dict.

Parameters: compartment – psamm.datasource.entry.CompartmentEntry. adjacencies – Sequence of IDs or a single ID of adjacent compartments (or None).
convert_compound_entry(compound)

Convert compound entry to YAML dict.

convert_reaction_entry(reaction)

Convert reaction entry to YAML dict.

write_compartments(stream, compartments, adjacencies, properties=None)

Write iterable of compartments as YAML object to stream.

Parameters: stream – File-like object. compartments – Iterable of compartment entries. adjacencies – Dictionary mapping IDs to adjacent compartment IDs. properties – Set of compartment properties to output (or None to output all).
write_compounds(stream, compounds, properties=None)

Write iterable of compounds as YAML object to stream.

Parameters: stream – File-like object. compounds – Iterable of compound entries. properties – Set of compound properties to output (or None to output all).
write_reactions(stream, reactions, properties=None)

Write iterable of reactions as YAML object to stream.

Parameters: stream – File-like object. compounds – Iterable of reaction entries. properties – Set of reaction properties to output (or None to output all).
class psamm.datasource.native.NativeModel(properties={})

Represents model in the native format.

biomass_reaction

Return biomass reaction property.

compartment_boundaries

Return set of compartment boundaries.

compartments

Return compartments entry set.

compounds

Return compound entry set.

create_metabolic_model()
default_compartment

Return default compartment property.

default_flux_limit

Return default flux limit property.

exchange

Return dict of exchange compounds and properties.

extracellular_compartment

Return extracellular compartment property.

limits

Return dict of reaction limits.

model

Return dict of model reactions.

name

Return model name property.

reactions

Return reaction entry set.

version_string

Return model version string.

exception psamm.datasource.native.ParseError

Exception used to signal errors while parsing

psamm.datasource.native.float_constructor(loader, node)

Construct Decimal from YAML float encoding.

psamm.datasource.native.parse_compound(compound_def, context=None)

Parse a structured compound definition as obtained from a YAML file

Returns a CompoundEntry.

psamm.datasource.native.parse_compound_file(path, format)

Open and parse reaction file based on file extension or given format

Path can be given as a string or a context.

psamm.datasource.native.parse_compound_list(path, compounds)

Parse a structured list of compounds as obtained from a YAML file

Yields CompoundEntries. Path can be given as a string or a context.

psamm.datasource.native.parse_compound_table_file(path, f)

Parse a tab-separated file containing compound IDs and properties

The compound properties are parsed according to the header which specifies which property is contained in each column.

psamm.datasource.native.parse_compound_yaml_file(path, f)

Parse a file as a YAML-format list of compounds

Path can be given as a string or a context.

psamm.datasource.native.parse_exchange(exchange_def, default_compartment)

Parse a structured exchange definition as obtained from a YAML file.

Returns in iterator of compound, reaction, lower and upper bounds.

psamm.datasource.native.parse_exchange_file(path, default_compartment)

Parse a file as a list of exchange compounds with flux limits.

The file format is detected and the file is parsed accordingly. Path can be given as a string or a context.

psamm.datasource.native.parse_exchange_list(path, exchange, default_compartment)

Parse a structured exchange list as obtained from a YAML file.

Yields tuples of compound, reaction ID, lower and upper flux bounds. Path can be given as a string or a context.

psamm.datasource.native.parse_exchange_table_file(f)

Parse a space-separated file containing exchange compound flux limits.

The first two columns contain compound IDs and compartment while the third column contains the lower flux limits. The fourth column is optional and contains the upper flux limit.

psamm.datasource.native.parse_exchange_yaml_file(path, f, default_compartment)

Parse a file as a YAML-format exchange definition.

Path can be given as a string or a context.

psamm.datasource.native.parse_limit(limit_def)

Parse a structured flux limit definition as obtained from a YAML file

Returns a tuple of reaction, lower and upper bound.

psamm.datasource.native.parse_limits_file(path)

Parse a file as a list of reaction flux limits

The file format is detected and the file is parsed accordingly. Path can be given as a string or a context.

psamm.datasource.native.parse_limits_list(path, limits)

Parse a structured list of flux limits as obtained from a YAML file

Yields tuples of reaction ID, lower and upper flux bounds. Path can be given as a string or a context.

psamm.datasource.native.parse_limits_table_file(f)

Parse a space-separated file containing reaction flux limits

The first column contains reaction IDs while the second column contains the lower flux limits. The third column is optional and contains the upper flux limit.

psamm.datasource.native.parse_limits_yaml_file(path, f)

Parse a file as a YAML-format flux limits definition

Path can be given as a string or a context.

psamm.datasource.native.parse_medium(exchange_def, default_compartment)

Parse a structured exchange definition as obtained from a YAML file.

Returns in iterator of compound, reaction, lower and upper bounds.

psamm.datasource.native.parse_medium_file(path, default_compartment)

Parse a file as a list of exchange compounds with flux limits.

The file format is detected and the file is parsed accordingly. Path can be given as a string or a context.

psamm.datasource.native.parse_medium_list(path, exchange, default_compartment)

Parse a structured exchange list as obtained from a YAML file.

Yields tuples of compound, reaction ID, lower and upper flux bounds. Path can be given as a string or a context.

psamm.datasource.native.parse_medium_table_file(f)

Parse a space-separated file containing exchange compound flux limits.

The first two columns contain compound IDs and compartment while the third column contains the lower flux limits. The fourth column is optional and contains the upper flux limit.

psamm.datasource.native.parse_medium_yaml_file(path, f, default_compartment)

Parse a file as a YAML-format exchange definition.

Path can be given as a string or a context.

psamm.datasource.native.parse_model_file(path)

Parse a file as a list of model reactions

The file format is detected and the file is parsed accordinly. The file is specified as a file path that will be opened for reading. Path can be given as a string or a context.

psamm.datasource.native.parse_model_group(path, group)

Parse a structured model group as obtained from a YAML file

Path can be given as a string or a context.

psamm.datasource.native.parse_model_group_list(path, groups)

Parse a structured list of model groups as obtained from a YAML file

Yields reaction IDs. Path can be given as a string or a context.

psamm.datasource.native.parse_model_table_file(path, f)

Parse a file as a list of model reactions

Yields reactions IDs. Path can be given as a string or a context.

psamm.datasource.native.parse_model_yaml_file(path, f)

Parse a file as a YAML-format list of model reaction groups

Path can be given as a string or a context.

psamm.datasource.native.parse_reaction(reaction_def, default_compartment, context=None)

Parse a structured reaction definition as obtained from a YAML file

Returns a ReactionEntry.

psamm.datasource.native.parse_reaction_equation(equation_def, default_compartment)

Parse a structured reaction equation as obtained from a YAML file

Returns a Reaction.

psamm.datasource.native.parse_reaction_equation_string(equation, default_compartment)

Parse a string representation of a reaction equation.

Converts undefined compartments to the default compartment.

psamm.datasource.native.parse_reaction_file(path, default_compartment=None)

Open and parse reaction file based on file extension

Path can be given as a string or a context.

psamm.datasource.native.parse_reaction_list(path, reactions, default_compartment=None)

Parse a structured list of reactions as obtained from a YAML file

Yields tuples of reaction ID and reaction object. Path can be given as a string or a context.

psamm.datasource.native.parse_reaction_table_file(path, f, default_compartment)

Parse a tab-separated file containing reaction IDs and properties

The reaction properties are parsed according to the header which specifies which property is contained in each column.

psamm.datasource.native.parse_reaction_yaml_file(path, f, default_compartment)

Parse a file as a YAML-format list of reactions

Path can be given as a string or a context.

psamm.datasource.native.resolve_format(format, path)

Looks at a file’s extension and format (if any) and returns format.

psamm.datasource.native.yaml_load(stream)