NetworkX for complex biological network analysis

Haz
Beautiful Biology
Published in
2 min readJan 14, 2023

NetworkX is an open-source Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. For biologists, NetworkX can assist in analyzing a wide variety of complex biological systems and is particularly well-suited for tasks such as protein-protein interaction networks, genetic regulatory networks, and ecological networks.

source: mouse brain connectivity data set (https://doi.org/10.1371/journal.pcbi.1007244)

For analyzing protein-protein interaction networks, NetworkX can be used to identify key proteins or modules within the network, such as hub proteins or densely connected regions, that may play a critical role in the cell’s function. Additionally, NetworkX can be used to study network topologies, such as degree distribution, clustering coefficient, and centrality measures, which can provide insight into the organization and functioning of the network. NetworkX is a powerful tool that can be used to study network topologies, such as degree distribution, clustering coefficient, and centrality measures, to provide insight into the organization and functioning of the network as well.

The following example shows a step-by-step approach to generating a protein-protein interaction network (PPI) from expression data.

#import packages

import pandas as pd
import networkx as nx
#read data 
df_ppi = pd.read_csv('ppi_data.csv')

#create dataframe
df_ppi = pd.DataFrame(df_ppi)
df_ppi
df_ppi : coexpression dataframe
#create graph object
ppi = nx.Graph(create_using=nx.DiGraph())

#create a graph from a dataframe
ppi = nx.from_pandas_edgelist(df=df_ppi, source='node1',target='node2', edge_attr='coexpression')

#create a dictionary of edges from the dataframe
ppi_edges = pd.DataFrame(
{
"source": [
'ABCE1','ABCE1','ABCE1','ABCE1','CAPRIN1','CAPRIN1','CAPRIN1','CAPRIN1','CAPRIN1','CAPRIN1','DDX58','DDX58',
'DDX58','DDX58','EIF4G1','EIF4G1','EIF4G1','EIF4G1','EIF4G1','G3BP1','G3BP1','G3BP1','G3BP1','G3BP1','G3BP1',
'PABPC1','PABPC1','PABPC1','SND1','SND1','TIA1'
],

"target": [
'PABPC1','DDX58','EIF4G1','G3BP1','PABPC1','EIF4G1','SND1','USP10','TIA1','G3BP1','SH2D3C','HDAC6','TIA1','G3BP1',
'PABPC1','SH2D3C','G3BP1','TIA1','USP10','PABPC1','SH2D3C','HDAC6','SND1','TIA1','USP10','TIA1','SH2D3C','USP10',
'USP10','TIA1','USP10'
],
"coexpression": [
0.181,0.0,0.215,0.837,0.228,0.227,0.088,0.197,0.185,0.238,0.0,0.062,0.065,0.0,0.575,0.0,0.208,0.116,0.355,0.284,
0.0,0.0,0.069,0.101,0.18,0.104,0.0,0.323,0.0,0.064,0.192
]
}
)
draw graph

nx.draw(
ppi,
pos=nx.circular_layout(ppi),
with_labels = True, #
node_size=2500,
node_shape = 'h',
node_color='salmon',
edge_color = 'brown',
alpha = 0.9,
width = [ppi.edges[p]['coexpression'] for p in ppi.edges] #change edge width wrt to coexpression value
)
Protein-Protein Interactions (PPIs) Network of G3BP1 (Ras GTPase-activating protein-binding protein 1)

--

--

Haz
Beautiful Biology

Data Enthusiast and a Researcher who loves to share ideas