psamm.graph
– Graph Related Functions¶
-
class
psamm.graph.
Entity
(props={})¶ Base class for graph entities.
-
class
psamm.graph.
Graph
(props={})¶ Graph entity representing a collection of nodes and edges.
-
add_node
(node)¶ add node to a Graph entity. node: Node entity.
-
get_node
(node_id)¶ get Node object. :param node_id: text_type(compound object) or text_type(a string that
contains single or multiple reaction IDs).
-
write_graphviz
(f, width, height)¶ Write the nodes and edges information into a dot file.
Print a given graph object to a graph file in the dot format. This graph can then be converted to an image file using the graphviz program.
Parameters: - self – Graph entity, including nodes and edges entities.
- f – An empty file.
- width – Width of final metabolic map.
- height – Height of final metabolic map.
-
write_graphviz_compartmentalized
(f, compartment_tree, extracellular, width, height)¶ Function to write compartmentalized version of dot file for graph.
Print a given graph object to a graph file in the dot format. In this graph, reaction nodes will be separated into different areas in the visualization based on the defined cellular compartments in the GEM.
Parameters: - self – Graph entity.
- f – An empty file.
- compartment_tree – a defaultdict of set, each element represents a compartment and its adjacent compartments.
- extracellular – the extracellular compartment in the model
- width – Width of final metabolic map.
- height – Height of final metabolic map..
-
write_nodes_tables
(f)¶ write a table file (.tsv) that contains nodes information.
Write all node information from a given graph object into a tab separated table. This table will include IDs, shapes, fill colors, and labels. This table can be used to import the graph information to other programs.
Parameters: - self – Graph entity.
- f – An empty file.
-
write_edges_tables
(f)¶ Write a tab separated table that contains edges information, including edge source, edge dest, and edge properties.
Write all edge information from a given graph object into a tab separated table. This table will include IDs, source nodes and destination nodes. This table can be used to import the graph information to other programs.
Parameters: - self – Graph entity.
- f – An empty TSV file.
-
-
class
psamm.graph.
Node
(props={})¶ Node entity represents a vertex in the graph.
-
class
psamm.graph.
Edge
(source, dest, props={})¶ Edge entity represents a connection between nodes.
-
psamm.graph.
get_compound_dict
(model)¶ Parse through model compounds and return a formula dict.
This function will parse the compound information in a given model and return a dictionary of compound IDs to compound formula objects.
Parameters: model – <class ‘psamm.datasource.native.NativeModel’>
-
psamm.graph.
make_network_dict
(nm, mm, subset=None, method='fpp', element=None, excluded_reactions=[], reaction_dict={}, analysis=None)¶ Create a dictionary of reactant/product pairs to reaction directions.
Returns a dictionary that connects predicted reactant/product pairs to their original reaction directions. This dictionary is used when generating bipartite graph objects. This can be done either using the FindPrimaryPairs method to predict reactant/product pairs or by mapping all possible pairs.
Parameters: - nm – <class ‘psamm.datasource.native.NativeModel’>, the native model
- mm – <class ‘psamm.metabolicmodel.MetabolicModel’>, the metabolic model.
- subset – None or path to a file that contains a list of reactions or compound ids. By default, it is None. It defines which reaction need to be visualized.
- method – ‘fpp’ or ‘no-fpp’, the method used for visualization.
- element – Symbol of chemical atom, such as ‘C’ (‘C’ indicates carbon).
- excluded_reactions – a list that contains reactions excluded from visualization.
- reaction_dict – dictionary of FBA or FVA results. By default it is an empty dictionary.
- analysis – “None” type or a string indicates if FBA or FVA file is given in command line.
-
psamm.graph.
write_network_dict
(network_dict)¶ Print out network dictionary object to a tab separated table.
Print information from the dictionary “network_dict”. This information includes four items: reaction ID, reactant, product, and direction. this can table can be used as an input to other graph visualization and analysis software.
- Args:
- network_dict: Dictionary object from make_network_dict()
-
psamm.graph.
make_cpair_dict
(filter_dict, args_method, args_combine, style_flux_dict, hide_edges=[])¶ Create a mapping from compound pair to a defaultdict containing lists of reactions for the forward, reverse, and both directions.
Returns a dictionary that connects reactant/product pair to all reactions that contain this pair. Those reactions are stored in a dictionary and classified by reaction direction. For example: {(c1, c2): {‘forward’: [rxn1], ‘back’: [rxn3], ‘both’: [rxn4, rxn5]}, (c3, c4): {…}, …}
Parameters: - filter_dict – A dictionary mapping reaction entry to compound pairs (inside of the pairs there are cpd objects, not cpd IDs)
- args_method – a string, including ‘fpp’ and ‘no-fpp’.
- args_combine – combine level, default = 0, optional: 1 and 2.
- style_flux_dict – a dictionary to set the edge style when fba or fva input is given.
- hide_edges – to determine edges between which compound pair need to be hidden.
-
psamm.graph.
make_bipartite_graph_object
(cpairs_dict, new_id_mapping, method, args_combine, model_compound_entries, new_style_flux_dict, analysis=None)¶ Makes a bipartite graph object from a cpair_dict object.
Start from empty graph() and cpair dict to make a graph object. Nodes only have rxn/cpd ID and rxn/cpd entry info in this initial graph. The information can be modified to add on other properties like color, or names.
Parameters: - cpairs_dict – defaultdict of compound_pair: defaultdict of direction: reaction list. e.g. {(c1, c2): {‘forward”:[rx1], ‘both’:[rx2}}.
- new_id_mapping – dictionary of rxn_id_suffix: rxn_id.
- method – options=[‘fpp’, ‘no-fpp’, file_path].
- args_combine – Command line argument, could be 0, 1, 2.
- model_compound_entries – dict of cpd_id:compound_entry.
- new_style_flux_dict – a dictionary to determine the edge style with the new reaction IDs.
- return: A graph object that contains basic nodes and edges.
- only ID and rxn/cpd entry are in node properties, no features like color, shape.
-
psamm.graph.
dir_value
(direction)¶ Assign value to different reaction directions