OpenGraph
- class openmsimodel.graph.open_graph.OpenGraph(name, dirpath, output, layout, add_bidirectional_edges, take_small_sample=False)
Bases:
Runnablethis class provides modules to build and visualize a networkx or graphviz object from gemd objects. By taking folder path containing GEMD thin JSON files, it establishes the relationships between them by interpreting their uuids/links, and flexibly produces anything from a svg image with simple labels, to a dot products containing all the gemd assets, from attributes, file links or tags.
- ARGUMENT_PARSER_TYPE
alias of
OpenMSIModelParser
- build_graph(assets_to_add, add_separate_node, which, update=True, uuid_to_track='auto')
creates a NetworkX graph representation of the GEMD relationships by reading every object generated by the GEMDEncoder object, storing all of its links by uid, and forming directed relationships, such as ingredient->process, or process->material It then allows filtering the objects mapped (i.e., removing spec or runs, measurements or ingredients) and saves a NetworkX graph in “dot” as .png
- Args:
which (bool): to plot a graph of specs, runs or templates add_separate_node (bool): bool to determine whether or not to add assets as attribute of related node, or as separate node assets_to_add (dict): dict to determine which of attributes, tags and/or file links to add to model update (bool, optional): bool to determinate updating instance variable svg_path and dot_path. Defaults to True. uuid_to_track (str, optional): _description_. Defaults to “auto”.
- Returns:
NetworkX Graph G_nx: graph containing knowledge in question, with uuids as name PyGraphVIZ Graph G_pviz_relabeled: graph containing highlighted knowledge in question, with individual names assigned to uuids dict name_mapping: mapping from uuid to name
- handle_gemd_obj(G, uid, obj_data, obj_type, obj_state, which, assets_to_add, add_separate_node)
method to handle the addition of a gemd object
- Args:
G (NetworkX graph): graph uid (str): uid of current object obj_data (dict): data of current object obj_type (str): type of current object which (bool): to plot a graph of specs, runs or templates, or all assets_to_add (dict): dict to determine which of attributes, tags and/or file links to add to model add_separate_node (bool): bool to determine whether or not to add assets as attribute of related node, or as separate node
- classmethod map_to_graphviz(G)
helper method to map NetworkX graph to Graphviz graph
- Args:
G (_type_): _description_ name_mapping (_type_, optional): _description_. Defaults to None.
- Returns:
_type_: _description_
- classmethod slice_subgraph(G, uuid, funcs, add_current=True)
applies paseed function(s) to graph object of interest with uuid=uuid. If elements are found to match the criteria, a subgraph containing all those elements is returned
- Args:
G (NetworkX graph): knowledge graph in questoin uuid (str): uuid of current element of interest on which the functions are applied funcs (list): list of function(s) to apply to graph add_current (bool, optional): whether or not to add the current element of interest. Defaults to True.
G (NetworkX graph): Graph to save
- classmethod return_uuid(identifier)
return the identifier of interest.
- Args:
identifier (str): identifier of object of interest
- Returns:
str: identifier
- classmethod extract_subgraph(G, identifier, func)
extract subgraph from graph knowledge, based on functions applied to element of interest to filter in additional desired elements. Examples includes neighbords, descendants, ancestors, etc.
- Args:
G (NetworkX graph): Graph to save identifier (str): uuid or identifier of element of interest func (func): function to determine whether graph element should be added to subgraph or not
- Returns:
NetworkX graph: subgraph filtered based on passed criteria
- classmethod save_graph(dest, G_nx, G_gviz, name)
class method to save Graphviz graph.
- Args:
dest (Pathlib.Path): path where to save the graph G_nx (Networkx graph): Networkx version of graph G_gviz (Graphviz graph): Graphviz version of graph name (str): name of file to save graph to
- Returns:
str: paths to, respectively, the dot and svg files
- classmethod get_argument_parser(*args, **kwargs)
Get the argument parser used to run the code
- Parameters:
args (list) – Any arguments to this method are names of arguments recognized by Argument parsers of the
ARGUMENT_PARSER_TYPEtypekwargs (dict) – Any keyword arguments to this method define custom default values for their given arguments, whose names must be recognized by Argument parsers of the
ARGUMENT_PARSER_TYPEtype
- Returns:
An argument parser of the
ARGUMENT_PARSER_TYPEtype to use for the object
- classmethod get_command_line_arguments()
Get the list of argument names and the dictionary of argument names/default values to add to the argument parser