Python package for the analysis and visualization of network graphs.
Project description
graph-express
Python package for the analysis and visualization of network graphs with familiar libraries such as NetworkX, NetworKit, igraph, cdlib, and Plotly.
Requirements
- Python 3.6.8+
- cdlib>=0.3.0
- datashader>=0.10.0
- kaleido>=0.2.1
- leidenalg>=0.8.3
- networkit>=7.0
- networkx>=2.3
- networkx-gdf>=1.1
- openpyxl>=3.1.2
- pandas>=0.25.3
- plotly>=3.10.0
- python-igraph>=0.8.3
- python-louvain>=0.14
Usage
The following is an overview of the package, to be replaced with guidelines detailing its usage with examples.
Import high-level class
import graph_express.graph_express as gx
Read graph from file
Accepted extensions include all formats supported by networkx and networkx-gdf.
G = gx.read_graph("/path/to/file.ext", ...)
Compute centrality and communities
Generates a data frame with node centrality values and communities, e.g., using the Leiden algorithm:
df = gx.compute(G, attrs=["degree", "leiden"])
Plot network graph
Calculates positions and plots the network graph.
fig = gx.draw(G, layout="forceatlas2", renderer="networkx")
Import specific classes
This package implements six classes with static methods to allow inheriting their implemented methods:
import graph_express
Centrality = graph_express.Centrality()
Community = graph_express.Community()
Convert = graph_express.Convert()
Draw = graph_express.Draw()
Graph = graph_express.Graph()
Layout = graph_express.Layout()
Note that all implemented methods are static and also exposed by graph_express.graph_express
(see example above).
Centrality
Computes weighted or unweighted (in-/out-) degree, bridging, and brokering centrality. Wrappers available for NetworkX (nx
) and NetworKit (nk
).
from graph_express import Centrality
# Centrality.bridging_centrality
# Centrality.bridging_coef
# Centrality.brokering_centrality
# Centrality.degree
# Centrality.in_degree
# Centrality.nk_centrality
# Centrality.nx_centrality
# Centrality.out_degree
# Centrality.weighted_degree
# Centrality.weighted_in_degree
# Centrality.weighted_out_degree
Community
Computes Louvain or Leiden community modules, as implemented by the authors. Wrappers available for cdlib and NetworKit (nk
).
from graph_express import Community
# Community.cdlib_community
# Community.leiden
# Community.louvain
# Community.nk_community
Convert
Converts graphs from and to igraph (ig
), NetworKit (nk
), NetworkX (nx
), Pandas (pd
), and PyTorch Geometric (pyg
) formats.
from graph_express import Convert
# Convert.ig2nk
# Convert.ig2nx
# Convert.nk2ig
# Convert.nk2nx
# Convert.nx2ig
# Convert.nx2nk
# Convert.nx2pyg
# Convert.pd2nx
# Convert.pyg2nx
Draw
Plots network graphs using NetworkX (nx
) or Plotly, as well as degree histograms and similarity matrices among graphs.
from graph_express import Draw
# Draw.draw
# Draw.draw_nx
# Draw.draw_plotly
# Draw.histogram
# Draw.similarity_matrix
Graph
Convenience functions to read or write from file, as well as manipulate graph objects.
from graph_express import Graph
# Graph.adjacency
# Graph.agg_edge_attr
# Graph.agg_nodes
# Graph.compose
# Graph.density
# Graph.diameter
# Graph.edges
# Graph.graph
# Graph.info
# Graph.is_graph
# Graph.isolates
# Graph.k_core
# Graph.nodes
# Graph.read_graph
# Graph.remove_edges
# Graph.remove_nodes
# Graph.remove_selfloop_edges
# Graph.set_edge_attributes
# Graph.set_node_attributes
# Graph.write_graph
Layout
Calculate node positions to use for graph_express.draw
.
from graph_express import Layout
# Layout.layout
# Layout.circular_layout
# Layout.forceatlas2_layout
# Layout.kamada_kawai_layout
# Layout.random_layout
Command line interface
An experimental CLI is partially implemented and may be executed with graph-express
.
graph-express [-h] [-o OUTPUT] [-a ATTRS [ATTRS ...]] [-c NODE_COLOR]
[-e EDGE_ATTR [EDGE_ATTR ...]] [-g GROUPS] [-k K_CORE]
[-l LAYOUT] [-n NODE_ATTR [NODE_ATTR ...]] [-p POS]
[-r SEED] [-s SOURCE] [-t TARGET] [--directed]
[--multigraph] [--no-edges-attrs] [--no-node-attrs]
[--normalized] [--selfloops]
{build,compute,plot} input [input ...]
positional arguments:
{build,compute,plot} Action to execute.
input Path to input graphs or data set files.
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output path to write returned data.
-a ATTRS [ATTRS ...], --attrs ATTRS [ATTRS ...]
Available attributes: ['bridging_centrality',
'bridging_coef', 'brokering_centrality', 'degree',
'in_degree', 'nk_centrality', 'nx_centrality',
'out_degree', 'weighted_degree', 'weighted_in_degree',
'weighted_out_degree', 'cdlib_community', 'label',
'leiden', 'louvain', 'nk_community'].
-c NODE_COLOR, --color NODE_COLOR
Set node color (example: '#ccc').
-e EDGE_ATTR [EDGE_ATTR ...], --edge-attrs EDGE_ATTR [EDGE_ATTR ...]
Set edge attributes to consider when building graphs.
-g GROUPS, --groups GROUPS
Get node groups from file (containing two columns,
indexed by 'id').
-k K_CORE, --k-core K_CORE
Apply k-core to graph.
-l LAYOUT, --layout LAYOUT
Available layouts: ['circular_layout',
'forceatlas2_layout', 'kamada_kawai_layout', 'layout',
'random_layout'] (default: 'kamada_kawai').
-n NODE_ATTR [NODE_ATTR ...], --node-attrs NODE_ATTR [NODE_ATTR ...]
Set node attributes to consider when building graphs.
-p POS, --positions POS
Get node 2 or 3-dimensional positions from file.
-r SEED, --random-seed SEED
Specify random seed for predictable randomness.
-s SOURCE, --source SOURCE
Field name to consider as source.
-t TARGET, --target TARGET
Field name to consider as target.
--directed Set as directed graph.
--multigraph Set as multigraph (allow multiple edges connecting a
same pair of nodes).
--no-edges-attrs Ignore edge attributes when building graphs.
--no-node-attrs Ignore node attributes when building graphs.
--normalized Returns normalized centrality values (from 0 to 1.0).
--selfloops Allow edges connecting a node to itself.
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file graph_express-1.0a3.tar.gz
.
File metadata
- Download URL: graph_express-1.0a3.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a9e6252b4703da87c5b3ec47969b8249ea5fdfc046bc952c8324060ca579d6e |
|
MD5 | 74fe2d98731201ea40614354b9204c55 |
|
BLAKE2b-256 | c795b859416d77f29e6c93cdd48a99778e8ab39d5d1ed973dceccfb5f1f3c5c2 |
File details
Details for the file graph_express-1.0a3-py3-none-any.whl
.
File metadata
- Download URL: graph_express-1.0a3-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 851edd005cb4523af4fd9804e95abcc41e4b2c79a6ae9c67e65ab84a7813d115 |
|
MD5 | ed600d67f0ab9fd29d060793258b2fb1 |
|
BLAKE2b-256 | ab8cba1bf9577c271a9938efe5d97acd71edb9a613a4d82e16667778ca6cae61 |