API documentation for padmet.classes

Node

class padmet.classes.node.Node(_type, _id, misc=None)[source]

A Node represent an element in a metabolic network

e.g: compound, reaction.

Parameters:
  • _type (str) – The type of the node (‘reaction’,’pathway’)
  • _id (str) – the identifier of the node (‘rxn-45)
  • misc (dict) – A dictionary of miscellaneous data ({‘DIRECTION’:[REVERSIBLE]}) (the default value is None)
toString()[source]

This function is used to stock the information relative to the node in a padmet file.

Returns:string with all data sep by tab’ ex: reaction RXN0..
Return type:str

Policy

class padmet.classes.policy.Policy(policy_in_array=None)[source]

A Policy define the types of relations and nodes of a network.

A policy contains 3 attributes:

policy_in_array: Is a list of list of relations

e.g: [[‘reaction’,’consumes’,’compounds’],[‘reaction’,’produces’,’compounds’]]

class_of_node: Is a set of all the type of nodes represented in the network

e.g: set([‘reaction’, ‘compound’])

type_of_arc: Is a dictionary of all the types of arcs represented in the network

(e.g: {‘reaction’:[‘consumes’,’compounds’]})

Parameters:policy_in_array (list) –

Is a list of list of relations

e.g: [[‘reaction’,’consumes’,’compounds’],[‘reaction’,’produces’,’compounds’]]

(the default value is None)

getClassOfNode()[source]
Returns:return class_of_node
Return type:set
getPolicyInArray()[source]
Returns:return policy_in_array
Return type:list
getTypeOfArc()[source]
Returns:return type_of_arc
Return type:dict
setPolicyInArray(policy_in_array)[source]

From policy_in_array, set class_of_node and type_of_arc

Parameters:policy_in_array (list) – Is a list of list of arcs. e.g: [[‘reaction’,’consumes’,’compounds’],[‘reaction’,’produces’,’compounds’]]

Relation

class padmet.classes.relation.Relation(id_in, _type, id_out, misc=None)[source]

A Relation represent a link between two elements (node) in a metabolic network.

e.g: RXN-1 consumes CPD-1

A Relation contains 4 attributes:

_type: The type of the relation (e.g: ‘consumes’ or ‘produces’)

id_in: the identifier of the node corresponding to the subject of the relation (e.g: ‘RXN-1)

id_out: the identifier of the node corresponding to the object of the relation (e.g: ‘CPD-1)

misc: A dictionary of miscellaneous data, k = tag of the data, v = list of values

(e.g: {‘STOICHIOMETRY’:[1.0]})

Parameters:
  • id_in (str) – the identifier of the node corresponding to the subject of the relation (‘RXN-1)
  • _type (str) – The type of the relation (e.g: ‘consumes’ or ‘produces’)
  • id_out (str) – the identifier of the node corresponding to the object of the relation (‘CPD-1)
  • _misc (dict) – A dictionary of miscellaneous data (e.g: {‘STOICHIOMETRY’:[1.0]})
compare(relation)[source]

compare 2 relations. First check if ids and type are the same, then check the misc dictionary. :param relation: the relation to compare :type relation: padmet.Relation

Returns:Return True if relation are the same, False if not
Return type:bool
toString()[source]

This function is used to stock the information relative to the node in a padmet file.

Returns:string with all data sep by tab’ ex: RXN0 consumes CPD-A..
Return type:str

PadmetRef

class padmet.classes.padmetRef.PadmetRef(padmetRef_file=None)[source]

PadmetRef is an object representing a DATABASE of metabolic network.

Contains <Policy>, <Node> and <Relation>:

The policy defines the way Node and Relation are associated.

A node is an Object that contains information about an element of the network (can be a pathway, reaction…).

A realtion defines how two nodes are connected. In a relation there is a node “in” and a node “out”. (reactionX’in’ consumes metaboliteX’out’).

PadmetRef contains 3 attributs:

dicOfNode: a dictionary of node: key=Node’s unique id / value = <Node>.

dicOfRelationIn: a dictionnary of relation with: key= nodeIN id / value = list of <relation>.

dicOfRelationOut: a dictionnary of relation with: key= nodeOut id / value = list of <relation>.

policy: a <policy>.

info: a dictionnary of informations about the network, the database used… This dictionnary is always represented in the header of a padmet file.

if None, initializes an empty <PadmetRef>

Parameters:padmetRef_file (str) – pathname of the padmet file
createNode(_type, _id, dicOfMisc={}, listOfRelation=None)[source]

Creation of new node to add in the network.

Parameters:
  • _type (str) – type of node (gene, reaction…)
  • _id (str) – id of the node
  • dicOfMisc (dict) – dictionnary of miscellaneous data
  • listOfRelation (list or None) – list of relation
Returns:

new_node

Return type:

padmet.classes.Node

delNode(node_id)[source]

Allows to delete a node, the relations associated to the node, and for some relations, delete the associated node. For relations where the node to del is ‘in’:

if rlt type in [‘has_xref’,’has_name’,’has_suppData’]: delNode out
For relations where the node to del is ‘out’:
if rlt type in [‘consumes’,’produces’]
Parameters:node_id (str) – id of node to delete
Returns:True if node successfully deleted, False if node not in dicOfNode
Return type:bool
generateFile(output)[source]

Allow to create a padmet file to stock all the data. @param output: pathname of the padmet file to create

Parameters:output (str) – path to output file
getAllRelation()[source]
Returns:return a set of all relations
Return type:set
loadGraph(padmet_file)[source]

Allow to recover all the informations of the padmet file. The section Data Base informations corresponds to the self.info The section Nodes corresponds to the data of each nodes in self.dicOfNode, sep =” ” The section Relations corresponds to the data of each relations in self.dicOfRelationIn/Out, sep =” “

Parameters:padmet_file (str) – the pathname of the padmet file to load.
setDicOfNode(source)[source]

Set dicOfNode from a dict or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef) – may be a dict or an other padmet from where will be copied the dicOfNode
setInfo(source)[source]

All the information printed in the header of a padmet stocked in a dict. {“metacyc”:{version:XX,…},”ecocyc”:{…}…} set Info from a dictionnary or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef) – may be a dict or an other padmet from where will be copied the info
setPolicy(source)[source]

Set policy from a list or copying from an other padmet

Parameters:source (list or padmet.classes.PadmetRef) – may be a list or an other padmet from where will be copied the policy
setdicOfRelationIn(source)[source]

Set dicOfRelationIn from a dict or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef) – may be a dict or an other padmet from where will be copied the dicOfRelationIn
setdicOfRelationOut(source)[source]

Set dicOfRelationOut from a dict or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef) – may be a dict or an other padmet from where will be copied the dicOfRelationOut
updateFromSbml(sbml_file, verbose=False)[source]

Initialize a padmetRef from sbml. Copy all species, convert id with sbmlPlugin stock name in COMMON NAME. Copy all reactions, convert id with sbmlPlugin, stock name in common name, stock compart and stoichio data relative to reactants and products in the misc of consumes/produces relations

Parameters:
  • sbml_file (str) – pathname of the sbml file
  • verbose (bool) – if True print supp info

PadmetSpec

class padmet.classes.padmetSpec.PadmetSpec(padmetSpec_file=None)[source]

PadmetSpec is an object representing the metabolic network of a species(organism) based on a reference database PadmetRef. contains <Policy>, <Node> and <Relation> The policy defines the way Node and Relation are associated A node is an Object that contains information about an element of the network (can be a pathway, reaction…). A relation defines how two nodes are connected. In a relation there is a node “in” and a node “out”. (reactionX’in’ consumes metaboliteX’out’) PadmetSpec contains 3 attributes:

dicOfNode: a dictionary of node: key=Node’s unique id / value = <Node> dicOfRelationIn: a dictionary of relation with: key= nodeIN id / value = list of <relation> dicOfRelationOut: a dictionary of relation with: key= nodeOut id / value = list of <relation> policy: a <policy> info: a dictionary of informations about the network, the database used… This dictionary is always represented in the header of a padmet file

if None, initializes an empty <PadmetSpec>

Parameters:padmetSpec_file (str) – pathname of the padmet file
change_compart(old_compart, new_compart, verbose=False)[source]

#TODO

copyNode(padmet, node_id)[source]

copyNode() allows to copy a node from an other padmetSpec or padmetRef. It copies all the relations ‘in’ and ‘out’ and it calls the function _copyNodeExtend() to recover the associated node.

Parameters:
  • Padmet (padmet.classes.PadmetRef/PadmetSpec) – padmet from where to copy the node
  • node_id (str) – the id of the node to copy
createNode(_type, _id, dicOfMisc={}, listOfRelation=None)[source]

Creation of new node to add in the network.

Parameters:
  • _type (str) – type of node (gene, reaction…)
  • _id (str) – id of the node
  • dicOfMisc (dict) – dictionnary of miscellaneous data
  • listOfRelation (list or None) – list of relation
Returns:

new_node

Return type:

padmet.classes.Node

delCompart(compart, verbose=False)[source]

#TODO

delNode(node_id)[source]

Allows to delete a node, the relations associated to the node, and for some relations, delete the associated node. For relations where the node to del is ‘in’:

if rlt type in [‘has_xref’,’has_name’,’has_suppData’]: delNode out
For relations where the node to del is ‘out’:
if rlt type in [‘consumes’,’produces’]
Parameters:node_id (str) – id of node to delete
Returns:True if node successfully deleted, False if node not in dicOfNode
Return type:bool
extract_pathway(node_id, padmetRef_file, output, sbml=None)[source]

Allow to extract a pathway in a csv file. Need a padmetRef to check the total number of reactions in the pathway. Header = “Reactions (metacyc_id)”, “Reactions (common_name)”, “EC-Number”,

“Formula (metacyc_id)”, “Formula (common_name)”, “Found in the network”
Parameters:
  • node_id (str) – id of the pathway
  • padmetRef_file (str) – pathname of the padmet ref file
  • output (str) – pathname of the output to create
  • sbml (None or str) – if path given, create a sbml file of this pathway
generateFile(output)[source]

Allow to create a padmet file to stock all the data.

Parameters:output (str) – path to output file
getAllRelation()[source]

return a set of all relations

Returns:return a set of all relations
Return type:set
getRelation(rlt_id_in, rlt_type, rlt_id_out)[source]

return a relation

Returns:return a relation
Return type:Relation
getRelationTypeIDIn(rlt_type, rlt_id_in)[source]

return a relation

Returns:return a relation
Return type:Relation
get_all_compart()[source]

#TODO

get_growth_medium(b_compart='C-BOUNDARY')[source]

return set of metabolites corresponding to the growth medium

ko(genes, verbose=False)[source]

remove all reactions associated to a given gene or list of genes

Parameters:
  • genes (str or list) – one gene or list of genes to remove
  • verbose (bool) – print more info
loadGraph(padmet_file)[source]

Allow to recover all the information of the padmet file. The section Data Base information corresponds to the self.info The section Nodes corresponds to the data of each nodes in self.dicOfNode, sep =” ” The section Relations corresponds to the data of each relations in self.dicOfRelationIn/Out, sep =” “

Parameters:padmet_file (str) – the pathname of the padmet file to load.
network_report(output_dir, padmetRef_file=None, verbose=False)[source]

Summurizes the network in a folder (output_dir) of 4 files. all_pathways.tsv: report on the pathways of the network. PadmetRef is used to recover the total reactions of a pathways. (sep = ” “) line = dbRef_id, Common name, Number of reactions found,

Total number of reaction, Ratio (Reaction found / Total)

all_reactions.tsv: report on the reactions of the network. (sep = ” “) line = dbRef_id, Common name, formula (with id),

formula (with common name), in pathways, associated genes, sources

all_metabolites.tsv: report on the metabolites of the network. (sep = ” “) line = dbRef_id, Common name, Produced (p), Consumed (c), Both (cp) all_genes.tsv: report on the genes of the network. (sep= ” “) line = “id”, “Common name”, “linked reactions”

Parameters:
  • padmetRef_file (str) – pathname of the padmet of reference
  • output_dir (str) – pathname of the folder where to create the reports
  • verbose (bool) – if true print info.
remove_growth_medium(b_compart='C-BOUNDARY', verbose=False)[source]

#TODO

setDicOfNode(source)[source]

Set dicOfNode from a dict or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef/PadmetSpec) – may be a dict or an other padmet from where will be copied the dicOfNode
setInfo(source)[source]

All the information printed in the header of a padmet stocked in a dict. {“metacyc”:{version:XX,…},”ecocyc”:{…}…} set Info from a dictionary or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef/PadmetSpec) – may be a dict or an other padmet from where will be copied the info
setPolicy(source)[source]

Set policy from a list or copying from an other padmet

Parameters:source (list or padmet.classes.PadmetRef/PadmetSpec) – may be a list or an other padmet from where will be copied the policy
set_growth_medium(new_growth_medium=None, padmetRef=None, rxn_prefix={'ExchangeSeed', 'TransportSeed'}, b_compart='C-BOUNDARY', e_compart='e', c_compart='c', verbose=False)[source]

if new_growth_medium is None: just remove the growth medium by deleting reactions starting with rxn_prefix else: remove and change by the new growth_medium, a list of compounds.

Parameters:
  • new_growth_medium (list or None) – list of metabolites ids for the new media
  • padmetRef (str) – path name of the padmet ref file
  • rxn_prefix (set) – set of prefix corresponding to reactions of exchanges (specific to growth medium)
  • b_compart (str) – ID of the boundary compartment, compound in this compart will have BoundaryCondition True in sbml
  • verbose (bool) – print more info
setdicOfRelationIn(source)[source]

Set dicOfRelationIn from a dict or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef/PadmetSpec) – may be a dict or an other padmet from where will be copied the dicOfRelationIn
setdicOfRelationOut(source)[source]

Set dicOfRelationOut from a dict or copying from an other padmet

Parameters:source (dict or padmet.classes.PadmetRef/PadmetSpec) – may be a dict or an other padmet from where will be copied the dicOfRelationOut
updateFromPadmet(padmet)[source]

update padmet from another padmet file

Parameters:padmet (padmet.classes.PadmetRef/PadmetSpec) – padmet instance
updateFromSbml(sbml_file, padmetRef=None, mapping_file=None, verbose=False, force=False, source_tool=None, source_category=None, source_id=None)[source]

Copy data from sbml to padmet. If the id of the sbml are different with the padmetRef, need to add a dictionary of associations between the id in the sbml and the id of the database of reference. if no padmetRef, will create reactions and compounds based on the given sbml @param sbml_file: pathname of the sbml file @param padmetRef: <PadmetRef> padmet of reference. @param mapping_dict (opt): pathname of the file containing the association original_id ref_id, sep =” ” @param verbose: print info @param force: if true, allow to copy reactions that are not in padmetRef by creating new reaction @type sbml_file, assocIdOriginRef: str @type padmetRef: PadmetRef @type verbose, force: bool @return: _ @rtype: None

updateNode(node_id, data, action)[source]

Allows to update miscellaneous data of a Node. @param node_id: the id of node to update @param data: tuple with data[0] refers to the miscellaneous data key (ex: common_name, direction …), data[1] is a list of value to add / update. data[1] can be None if the action is to pop the key @param action: if == “add”: the list data[1] will be added (ex: adding a common_name) if == “remove”: if data[1] is not None, the list data[1] will be removed (ex: remove just one specific common_name) if == “update”:data[1] is the new value of the key data[0] ex: updateNode(‘RXN-5’,(‘direction’,[‘LEFT-TO-RIGHT’]),update). The reaction’ direction will be change to left2right

Parameters:
  • node_id (str) – the id of the node to update
  • data (tuple) – tuple of data to update, data[0] is the key, data[1] is a value, list or None
  • action (str) – action in [‘add’,’pop’,’remove’,’update’]. Check description for more information
Returns:

True if node successfully updated

Return type:

bool