Utilities¶
Graph Utils¶
-
rhodonite.utils.graph.add_dict_edge_list(g, prop_dict, prop_name, eval_type, **eprop_kwargs)[source]¶ Converts a dictionary to graph edges with an edge property map.
Parameters: - g (
graph_tool.Graph) – A graph. - prop_dict (
dict) – A dictionary where keys are tuples of source target vertices or indices, and values are the value of a property or weight assigned to the edge. vertices and values are the values to be inserted into the property map. - val_type (
str) – The type of the property. See graph_tool.PropertyMap. - eprop_kwargs – See graph_tool.PropertyMap.
- g (
-
rhodonite.utils.graph.dict_to_edge_prop(g, prop_dict, val_type, edge_index_dict=None)[source]¶ Maps dictionary values to an edge property using keys.
Parameters: - g (
graph_tool.Graph) – A graph. - prop_dict (
dict) – A dictionary where keys are tuples of source target vertices or indices, and values are the value of a property or weight assigned to the edge. - val_type (
str) – See graph_tool.PropertyMap. - eprop_kwargs – Other edge property map kwargs. See graph_tool.PropertyMap
- Returns
- eprop :
graph_tool.PropertyMap - An edge property map.
- eprop :
- g (
-
rhodonite.utils.graph.dict_to_vertex_prop(g, prop_dict, val_type)[source]¶ Maps dictionary values to a vertex property using keys.
Parameters: - g (
graph_tool.Graph) – A graph. - prop_dict (
dict) – A dictionary where vertices or vertex indices, and values are the value of a property or weight assigned to the vertex. - vprop_kwargs – See graph_tool.PropertyMap.
- Returns
- vprop :
graph_tool.PropertyMap
- g (
-
rhodonite.utils.graph.internalize_prop_dict(g, prop_dict, prop_tag='{}')[source]¶ internalize_props_from_dict Internalises property maps contained in a dictionary and that correspond to graph, g, to that graph itself.
Parameters: - g (
graph_tool.Graph) – A graph. - prop_dict (
dictofgraph_tool.PropertyMap) – A dictionary of graph_tool.PropertyMap for a graph, g, its vertices or edges. - prop_tag (
str, optional) – A common name to apply to the keys of internalized properties. Curly braces should be included to indicate where the unique key for each property map should be included. e.g. my_graph_prop_{} Defaults to key for each property map in prop_dict.
- g (
-
rhodonite.utils.graph.subgraph_eprop_agg(g, vertices, eprop, aggfuncs)[source]¶ Retrieves the edge property values of all edges in a subgraph and returns a list of user-provided aggregations.
Parameters: - g (
graph_tool.Graph) – The original graph. - vertices (
iter) – Vertices of the subgraph. - eprop (
graph_tool.PropertyMap) – An edge property of graph, g. - aggfuncs (
iter) – A series of aggregation functions that can be applied to an array of values from the property map. e.g. aggfuncs=[np.mean, np.median] will return the mean and the median, only retrieving the actual values from g once.
Returns: agg (
listA list of aggregated values.)- g (
-
rhodonite.utils.graph.subgraph_eprop_values(g, vertices, eprop)[source]¶ get_subgraph_eprop Retrieves the edge property values of all edges in a subgraph.
Parameters: - g (
graph_tool.Graph) – The original graph. - vertices (
iter) – Vertices of the subgraph. - eprop (
graph_tool.EdgePropertyMap) – An edge property for graph, g.
Returns: vals (
arrayEdge property values from the subgraph.)- g (