Skip to content

Heatmap API

Ilia Popov edited this page May 30, 2025 · 5 revisions

Heatmap FUNCTION

This API generates a heatmap from KEGGaNOG output, with optional grouping.
If user is not happy with default KEGGaNOG's heatmap — user can adjust some parameters!
For now the main usability for heatmap() function is:

  • Setting difficult sample name in KEGGaNOG's single mode
  • Reordering samples on heatmap in KEGGaNOG's multi mode
  • Using different figure size in any mode

heatmap() function automatically understands if input data frame is single sample or multi sample

Heatmap API is under development — more features coming soon

heatmap(df, ...)

PARAMETERS

PARAMETER DESCRIPTION
df Input data as a pandas DataFrame
TYPE: pd.DataFrame
figsize Size of the heatmap figure (width, height)
TYPE: Tuple[int, int]
DEFAULT: (10, 10)
color Colormap name
TYPE: str
DEFAULT: "Blues"
group Enable grouped heatmap layout
TYPE: bool
DEFAULT: False
sample_name Name of a single sample to create per-sample heatmap (used in single mode only)
TYPE: str or None
DEFAULT: None
annot Annotate cells with values (used in single mode only)
TYPE: bool
DEFAULT: False

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

Single MODE

First, run KEGGaNOG in single-sample mode:

Where to get demo data? Here

! KEGGaNOG -i demo_data/LaPla/LaPla.emapper.annotations -o KEGGaNOG_single_output

Then generate a full heatmap of pathway completeness
Now we can set the sample name comprehensively — using regular expressions

import kegganog as kgn
import pandas as pd

df = pd.read_csv("KEGGaNOG_single_output/SAMPLE_pathways.tsv", sep="\t")

kgnheat = kgn.heatmap(df, color="Greens", annot=False, sample_name="$\it{Lpb. plantarum}$ IS-10506")

# Show the figure
kgnheat.plotfig()

Sample output:

heatmap_figure

For saving a plot please use:

kgnheat.savefig("pic_name.png", dpi=600)

Multi MODE

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 generate a full heatmap of pathway completeness
kgn.heatmap() takes exactly the same order of samples as they are in input data frame
To change the order of samples on heatmap please change the order of columns in df

import kegganog as kgn
import pandas as pd

df = pd.read_csv("KEGGaNOG_multi_output/merged_pathways.tsv", sep="\t")
df = df[["Function", "StaCa", "BaSu", "TheMa", "PsePu", "AciSa", "MeRu", "CloAce", "LaPla", "SoCe", "BaThe"]]

kgnheat = kgn.heatmap(
    df,
    color="Greens",
    group=False,
)

# Show the figure
kgnheat.plotfig()

Sample output:

heatmap_figure

For saving a plot please use:

kgnheat.savefig("pic_name.png", dpi=600)

Clone this wiki locally