Network

class modules.gemtractor.network.network.Network[source]

Bases: object

a class representing a network

_Network__create_sbml_gene(model, identifier, name, compartment, gemtractor)

create an SBML gene species for the Enzyme-centric network

Parameters:
Returns:

the SBML species representing a gene

Return type:

libsbml:Species

_Network__create_sbml_gene_complex(model, identifier, name, compartment, gemtractor, genes, nodemap)

create an SBML gene-complex species for the Enzyme-centric network

Parameters:
  • model – the SBML model
  • identifier (str) – the identifier of the gene complex
  • name (str) – the gene complex’ name
  • compartment – the compartment in which the gene complex will appear
  • gemtractor (gemtractor.GEMtractor) – the GEMtractor
  • genes (list of gene.Gene) – the genes, which are part of this complex
  • nodemap (dict) – mapper to map gene identifiers to corresponding SBML species
Returns:

the SBML species representing a gene complex

Return type:

libsbml:Species

_Network__create_sbml_reaction_species(model, identifier, name, compartment, gemtractor)

create an SBML reaction species for the Reaction-centric network

Parameters:
  • model – the SBML model
  • identifier (str) – the identifier of the reaction
  • name (str) – the reaction’s name
  • compartment – the compartment in which the reaction will appear
  • gemtractor (gemtractor.GEMtractor) – the GEMtractor
Returns:

the SBML species representing a reaction

Return type:

libsbml:Species

add_gene(gene)[source]

adds a gene/gene-product/enzyme to the network

if there is not yet a gene with that identifier, it will create a new gene and add it to the internal structure

eventually, the gene with the corresponding identifier is returned (may be an already existing gene, though)

Parameters:
  • identifier (str) – the id of the gene
  • name (str) – the name of the gene
Returns:

the gene with id ‘identifier’

Return type:

gene.Gene

add_genes(reaction, gene_complexes)[source]

adds multiple genes to this network and to a reaction

iterates all genes and complexes from ‘gene_complexes’ in ‘gene_complexes’ and - creates new genes if necessary (using add_gene()) - creates new gene complexes and their genes if necessary (using add_gene()) - links the gene and the reaction

Parameters:
add_reaction(identifier, name)[source]

adds a reaction to the network

if there is not yet a reaction with that identifier, it will create a new reaction and add it to the internal structure

eventually, the reaction with the corresponding identifier is returned (may be an already existing reaction, though)

Parameters:
  • identifier (str) – the id of the reaction
  • name (str) – the name of the reaction
Returns:

the reaction with id ‘identifier’

Return type:

reaction.Reaction

add_species(identifier, name)[source]

adds a species to the network

if there is not yet a species with that identifier, it will create a new species and add it to the internal structure

eventually, the species with the corresponding identifier is returned (may be an already existing species, though)

Parameters:
  • identifier (str) – the id of the species
  • name (str) – the name of the species
Returns:

the species with id ‘identifier’

Return type:

species.Species

calc_genenet()[source]

Calculate the enzyme-centric network

Let’s say you have this network:

  • A -r-> B (reaction r turns A into B)
  • B -s-> C (reaction s turns B into C)

and let’s assume the reactions are catalyzed by the following enzymes:

  • r: V or W
  • s: X and (Y or Z)

then the enzyme-centric network will be:

  • V -> X+Y (V links to X+Y)
  • V -> X+Z (V links to X+Z)
  • W -> X+Y (W links to X+Y)
  • W -> X+Z (W links to X+Z)
calc_reaction_net()[source]

Calculate the reaction-centric network

Let’s say you have this network:

  • A -r-> B (reaction r turns A into B)
  • B -s-> C (reaction s turns B into C)

then the reaction-centric network will be:

  • r -> s (r links to s)
static create_gml_edge(source, target)[source]

create a GML edge

Parameters:
  • source (str) – the identifier of the source node in the network
  • target (str) – the identifier of the target node in the network
Returns:

the GML representation of the edge

Return type:

str

static create_gml_node(nid, ntype, nshape, nlabel)[source]

create a GML node

Parameters:
  • nid (str) – the identifier of the node in the network
  • ntype (str) – the node’s type
  • nshape (str) – the node’s shape
  • nlabel (str) – the node’s label
Returns:

the GML representation of the network node

Return type:

str

static create_gml_prefix()[source]

create the prefix for a GML file

Returns:the preamble string for GML files
Return type:str
static create_graphml_node(nid, ntype, nshape, nlabel)[source]

create a GraphML node

Parameters:
  • nid (str) – the identifier of the node in the network
  • ntype (str) – the node’s type
  • nshape (str) – the node’s shape
  • nlabel (str) – the node’s label
Returns:

the GraphML representation of the network node

Return type:

str

static create_graphml_prefix()[source]

create the prefix for a GraphML file

Returns:the preamble string for GraphML files
Return type:str
static create_sbml_reaction(model, identifier, reactant, product)[source]

create an SBML reaction for the Enzyme-centric or Reaction-centric network

the reaction will consume and produce exactly one species

Parameters:
  • model – the SBML model
  • identifier (str) – the identifier of the reaction
  • reactant – the reactant consumed by the reaction
  • product – the product produced by the reaction
Returns:

the SBML reaction

Return type:

libsbml:Reaction

export_en_csv(file_path)[source]

export the enzyme-centric network in CSV format

Parameters:file_path (str) – where to store the exported format?
export_en_dot(file_path)[source]

export the enzyme-centric network in DOT format

Parameters:file_path (str) – where to store the exported format?
export_en_gml(file_path)[source]

export the enzyme-centric network in GML format

Parameters:file_path (str) – where to store the exported format?
export_en_graphml(file_path)[source]

export the enzyme-centric network in GraphML format

Parameters:file_path (str) – where to store the exported format?
export_en_sbml(file_path, gemtractor, model_id, model_name=None, filter_species=None, filter_reactions=None, filter_genes=None, filter_gene_complexes=None, remove_reaction_enzymes_removed=True, remove_ghost_species=False, discard_fake_enzymes=False, remove_reaction_missing_species=False, removing_enzyme_removes_complex=True)[source]

export the enzyme-centric network in SBML format

will attach the trimming-settings as SBML note

writes the document using the libsbml:SBMLWriter <http://sbml.org/Special/Software/libSBML/docs/python-api/class_s_b_m_l_writer.html> – returns the result of libsbml:SBMLWriter.writeSBML

Parameters:
  • file_path (str) – where to store the exported format?
  • model_id (str) – the model’s identifier, will be postfixed with a greeting from us
  • model_name (str) – the model’s name, will be prefixed with a greeting from us
  • filter_species (list of str) – species identifiers to get rid of
  • filter_reactions (list of str) – reaction identifiers to get rid of
  • filter_genes (list of str) – enzyme identifiers to get rid of
  • filter_gene_complexes (list of str) – enzyme-complex identifiers to get rid of, every list-item should be of format: ‘A + B + gene42’
  • remove_reaction_enzymes_removed (bool) – should we remove a reaction if all it’s genes were removed?
  • remove_ghost_species (bool) – should species be removed, that do not participate in any reaction anymore - even though they might be required in other entities?
  • discard_fake_enzymes (bool) – should fake enzymes (implicitly assumes enzymes, if no enzymes are annotated to a reaction) be removed?
  • remove_reaction_missing_species (bool) – remove a reaction if one of the participating genes was removed?
  • removing_enzyme_removes_complex (bool) – if an enzyme is removed, should also all enzyme complexes be removed in which it participates?
Returns:

true on success, otherwise false

Return type:

bool

export_mn_csv(file_path)[source]

export the metabolite-reaction network in CSV format

Parameters:file_path (str) – where to store the exported format?
export_mn_dot(file_path)[source]

export the metabolite-reaction network in DOT format

Parameters:file_path (str) – where to store the exported format?
export_mn_gml(file_path)[source]

export the metabolite-reaction network in GML format

Parameters:file_path (str) – where to store the exported format?
export_mn_graphml(file_path)[source]

export the metabolite-reaction network in GraphML format

Parameters:file_path (str) – where to store the exported format?
export_rn_csv(file_path)[source]

export the reaction-centric network in CSV format

Parameters:file_path (str) – where to store the exported format?
export_rn_dot(file_path)[source]

export the reaction-centric network in DOT format

Parameters:file_path (str) – where to store the exported format?
export_rn_gml(file_path)[source]

export the reaction-centric network in GMl format

Parameters:file_path (str) – where to store the exported format?
export_rn_graphml(file_path)[source]

export the reaction-centric network in GraphML format

Parameters:file_path (str) – where to store the exported format?
export_rn_sbml(file_path, gemtractor, model_id, model_name=None, filter_species=None, filter_reactions=None, filter_genes=None, filter_gene_complexes=None, remove_reaction_enzymes_removed=True, remove_ghost_species=False, discard_fake_enzymes=False, remove_reaction_missing_species=False, removing_enzyme_removes_complex=True)[source]

export the reaction-centric network in SBML format

will attach the trimming-settings as SBML note

writes the document using the libsbml:SBMLWriter <http://sbml.org/Special/Software/libSBML/docs/python-api/class_s_b_m_l_writer.html> – returns the result of libsbml:SBMLWriter.writeSBML

Parameters:
  • file_path (str) – where to store the exported format?
  • model_id (str) – the model’s identifier, will be postfixed with a greeting from us
  • model_name (str) – the model’s name, will be prefixed with a greeting from us
  • filter_species (list of str) – species identifiers to get rid of
  • filter_reactions (list of str) – reaction identifiers to get rid of
  • filter_genes (list of str) – enzyme identifiers to get rid of
  • filter_gene_complexes (list of str) – enzyme-complex identifiers to get rid of, every list-item should be of format: ‘A + B + gene42’
  • remove_reaction_enzymes_removed (bool) – should we remove a reaction if all it’s genes were removed?
  • remove_ghost_species (bool) – should species be removed, that do not participate in any reaction anymore - even though they might be required in other entities?
  • discard_fake_enzymes (bool) – should fake enzymes (implicitly assumes enzymes, if no enzymes are annotated to a reaction) be removed?
  • remove_reaction_missing_species (bool) – remove a reaction if one of the participating genes was removed?
  • removing_enzyme_removes_complex (bool) – if an enzyme is removed, should also all enzyme complexes be removed in which it participates?
Returns:

true on success, otherwise false

Return type:

bool

serialize()[source]

serialize to a JSON-dumpable object

the object will contain the following information:

Returns:JSON-dumpable object
Return type:dict