Skip to content

Correlation Network API

Ilia Popov edited this page Apr 15, 2025 · 2 revisions

Correlation_network FUNCTION

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, ...)

PARAMETERS

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: float
DEFAULT: 0.5
node_size Size of the nodes
TYPE: float
DEFAULT: 700.0
node_color Fill color of nodes
TYPE: str
DEFAULT: "#A3D5FF"
node_edgecolors Edge color of nodes
TYPE: str
DEFAULT: "#03045E"
node_linewidths Width of node borders
TYPE: float
DEFAULT: 1.5
label_fontsize Font size of node labels
TYPE: float
DEFAULT: 8.0
label_color Font color of labels
TYPE: str
DEFAULT: "#03045E"
label_verticalalignment Vertical alignment of labels
TYPE: str
DEFAULT: "center"
label_horizontalalignment Horizontal alignment of labels
TYPE: str
DEFAULT: "center"
label_weight Font weight of labels
TYPE: str
DEFAULT: "normal"
edge_cmap Colormap for edge correlation strength
TYPE: matplotlib.colors.Colormap
DEFAULT: plt.cm.coolwarm
cbar_size Width of the colorbar
TYPE: float
DEFAULT: 0.5
title Plot title
TYPE: str or None
DEFAULT: None
title_fontsize Font size of title
TYPE: float
DEFAULT: 16.0
title_color Font color of title
TYPE: str
DEFAULT: "black"
title_weight Font weight of title
TYPE: str
DEFAULT: "normal"
title_style Font style of title
TYPE: str
DEFAULT: "normal"
background_color Background color of the figure
TYPE: str
DEFAULT: "white"
save_matrix Optional file path to save the correlation matrix as CSV
TYPE: str or None
DEFAULT: None

RETURNS

Returns an object with:

  • fig: the Matplotlib figure object
  • ax: the Matplotlib axis object

The object includes .plotfig() and .savefig() methods for convenience.


USAGE EXAMPLE

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:

image

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")

Clone this wiki locally