tfcomb.network module
- tfcomb.network.build_network(edge_table, node1='TF1', node2='TF2', node_table=None, directed=False, multi=False, tool='networkx', verbosity=1)[source]
Build a network object from a table using either ‘networkx’ or ‘graph-tool’.
- Parameters:
edge_table (pd.DataFrame) – Table containing rows of edges and edge information between node1/node2.
node1 (str, optional) – The column to use as node1 ID. Default: “TF1”.
node2 (str, optional) – The column to use as node2 ID. Default: “TF2”.
node_table (pandas.DataFrame) – A table of attributes to use for nodes. Default: node attributes are estimated from the columns in edge_table.
directed (bool, optional) – Whether edges are directed or not. Default: False.
multi (bool, optional) – Allow multiple edges between two vertices. NOTE: Only valid for tool == ‘networkx’. If False, the first occurrence of TF1-TF2/TF2-TF1 in the table is used. Default: False.
tool (str, optional) – Which module to use for generating network. Must be one of ‘networkx’ or ‘graph-tool’. Default: ‘networkx’.
verbosity (int, optional) – Verbosity of logging (0/1/2/3). Default: 1.
- Returns:
if tool is ‘networkx’ (networkx.Graph / networkx.DiGraph / networkx.MultiGraph / networkx.MultiDiGraph - depending on parameters given.)
if tool is ‘graph-tool’ (graph_tool.Graph)
- tfcomb.network.get_degree(G, weight=None, direction='both')[source]
Get degree per node in graph. If weight is given, the degree is the sum of weighted edges.
- Parameters:
G (networkx.Graph) – An instance of networkx.Graph
weight (str, optional) – Name of an edge attribute within network. Default: None.
direction (str, optional) – Which edge direction to use for calculating degrees. Can be one of: [“both”, “in”, “out”]. Default: ‘both’.
- Returns:
A table of format (…)
- Return type:
DataFrame
- tfcomb.network.get_betweenness_centrality(G, weight=None)[source]
- Parameters:
G (networkx.Graph) – An instance of networkx.Graph
weight – Edge attribute. Default: None.
- tfcomb.network.subset_graph(G, nodes, depth=0)[source]
Subset a graph to a subset of nodes and their neighborhoods at the depth given by ‘depth’.
- Parameters:
G (networkx.Graph) – An instance of networkx.Graph.
nodes (str or list of str) – Nodes to keep.
depth (int, optional) – Default: 0 (only edges between given nodes)
- tfcomb.network.cluster_louvain(G, weight=None, attribute_name='cluster', logger=None)[source]
Cluster a network using community louvain clustering. By default, sets the attribute “cluster” to each node.
- Parameters:
G (networkx.Graph) – An instance of a network graph to cluster.
weight (str) – Attribute in graph to use as weight. The higher the weight, the stronger the link. Default: None.
attribute_name (str) – The attribute name to use for saving clustering. Default: “cluster”.
logger (a logger object) – An instance of a logger. Default: No logging.
- Return type:
None - clustering is added to ‘G’ in place.
- tfcomb.network.cluster_blockmodel(g, attribute_name='cluster')[source]
Clustering of a graph-tool graph using stochastic block model minimization.
- Parameters:
g (a graph.tool graph) – An instance of a graph.tool graph.
attribute_name (str) – The attribute name to use for saving clustering. Default: “cluster”.
- tfcomb.network.get_node_table(G)[source]
Get a table containing node names and node attributes for G.
- Parameters:
G (a networkx Graph object or graph_tool Graph object) –
- Return type:
pandas.DataFrame
- tfcomb.network.get_edge_table(G)[source]
Get a table containing edge names and edge attributes for G.
- Parameters:
G (a networkx Graph object.) –
- Return type:
pandas.DataFrame
- tfcomb.network.create_random_network(nodes, edges)[source]
Create a random network with the given list of nodes and total number of edges.
- Parameters:
nodes (list) – List of nodes to use in network.
edges (int) – Number of edges between nodes.
- Return type:
networkx.Graph containing random edges between nodes.
- tfcomb.network.plot_powerlaw(G, title='Node degree powerlaw fit', color='blue', save=None)[source]
Fit and plot a powerlaw distribution to the node degrees in the network.
- Parameters:
G (a networkx Graph object) – Networkx containing nodes and edges to analyze.
title (str, optional) – The title of the resulting plot. Default: “Node degree powerlaw fit”.
color (str, optional) – The color of the data plotted. Default: “blue”.
save (str, optional) – If not None, save the plot to the given path. Default: None.
- Returns:
ax – Axes object containing the plot.
- Return type:
matplotlib.axes