-
Notifications
You must be signed in to change notification settings - Fork 4
Correlation Network API
Ilia Popov edited this page Apr 15, 2025
·
2 revisions
This API generates a correlation network based on completeness values from KEGGaNOG multi-sample output. Correlation coefficients are calculated for each pathway pair across samples, and a network graph is built using significant correlations above a threshold.
The stronger the correlation the bolder the line
correlation_network(df, threshold=0.5, ...)
| PARAMETER | DESCRIPTION |
|---|---|
df |
Input data as a pandas DataFrame TYPE: pd.DataFrame
|
figsize |
Size of the figure (width, height) TYPE: Tuple[int, int]DEFAULT: (12, 6)
|
threshold |
Minimum correlation value to include edge in the network TYPE: floatDEFAULT: 0.5
|
node_size |
Size of the nodes TYPE: floatDEFAULT: 700.0
|
node_color |
Fill color of nodes TYPE: strDEFAULT: "#A3D5FF"
|
node_edgecolors |
Edge color of nodes TYPE: strDEFAULT: "#03045E"
|
node_linewidths |
Width of node borders TYPE: floatDEFAULT: 1.5
|
label_fontsize |
Font size of node labels TYPE: floatDEFAULT: 8.0
|
label_color |
Font color of labels TYPE: strDEFAULT: "#03045E"
|
label_verticalalignment |
Vertical alignment of labels TYPE: strDEFAULT: "center"
|
label_horizontalalignment |
Horizontal alignment of labels TYPE: strDEFAULT: "center"
|
label_weight |
Font weight of labels TYPE: strDEFAULT: "normal"
|
edge_cmap |
Colormap for edge correlation strength TYPE: matplotlib.colors.ColormapDEFAULT: plt.cm.coolwarm
|
cbar_size |
Width of the colorbar TYPE: floatDEFAULT: 0.5
|
title |
Plot title TYPE: str or NoneDEFAULT: None
|
title_fontsize |
Font size of title TYPE: floatDEFAULT: 16.0
|
title_color |
Font color of title TYPE: strDEFAULT: "black"
|
title_weight |
Font weight of title TYPE: strDEFAULT: "normal"
|
title_style |
Font style of title TYPE: strDEFAULT: "normal"
|
background_color |
Background color of the figure TYPE: strDEFAULT: "white"
|
save_matrix |
Optional file path to save the correlation matrix as CSV TYPE: str or NoneDEFAULT: None
|
Returns an object with:
-
fig: the Matplotlib figure object -
ax: the Matplotlib axis object
The object includes .plotfig() and .savefig() methods for convenience.
First, run KEGGaNOG in multi-sample mode:
Where to get demo data? Here
! KEGGaNOG -M -i demo_data/listFile.txt -o KEGGaNOG_multi_output
Then use the correlation network plot function:
import kegganog as kgn
import pandas as pd
df = pd.read_csv("KEGGaNOG_multi_output/merged_pathways.tsv", sep="\t")
kgnnet = kgn.correlation_network(
df,
node_size=780,
label_fontsize=7,
figsize=(8,5)
)
# To show the plot:
kgnnet.plotfig()Sample output:

To save the figure:
kgnnet.savefig("corrnet_plot.png", dpi=600)To export the correlation matrix as CSV:
kgn.correlation_network(df, save_matrix="correlation_matrix.csv")