-
Notifications
You must be signed in to change notification settings - Fork 4
Barplot API
Ilia Popov edited this page Apr 15, 2025
·
4 revisions
This API provides a function to create a customizable horizontal barplot from KEGGaNOG single mode output, typically used to visualize pathways completeness — it only takes pathways with completeness > 0.
barplot(df, ...)
| PARAMETER | DESCRIPTION |
|---|---|
df |
Input data as a pandas DataFrame TYPE: pd.DataFrame
|
figsize |
Size of the figure (width, height) TYPE: Tuple[int, int]DEFAULT: (8, 12)
|
cmap |
Colormap name or list of colors TYPE: str or listDEFAULT: "Greens"
|
cmap_range |
Colormap index range TYPE: Tuple[int, int]DEFAULT: (8, 30)
|
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"
|
xlabel |
Label for X-axis TYPE: strDEFAULT: "Pathway completeness"
|
xlabel_fontsize |
Font size of X-axis label TYPE: floatDEFAULT: 14.0
|
xlabel_color |
Font color of X-axis label TYPE: strDEFAULT: "black"
|
xlabel_weight |
Font weight of X-axis label TYPE: strDEFAULT: "normal"
|
xlabel_style |
Font style of X-axis label TYPE: strDEFAULT: "normal"
|
ylabel |
Label for Y-axis TYPE: strDEFAULT: "Pathway"
|
ylabel_fontsize |
Font size of Y-axis label TYPE: floatDEFAULT: 14.0
|
ylabel_color |
Font color of Y-axis label TYPE: strDEFAULT: "black"
|
ylabel_weight |
Font weight of Y-axis label TYPE: strDEFAULT: "normal"
|
ylabel_style |
Font style of Y-axis label TYPE: strDEFAULT: "normal"
|
xticks_fontsize |
Font size of X-axis ticks TYPE: floatDEFAULT: 12.0
|
xticks_color |
Font color of X-axis ticks TYPE: strDEFAULT: "black"
|
xtick_weight |
Font weight of X-axis ticks TYPE: strDEFAULT: "normal"
|
xtick_style |
Font style of X-axis ticks TYPE: strDEFAULT: "normal"
|
yticks_fontsize |
Font size of Y-axis ticks TYPE: floatDEFAULT: 12.0
|
yticks_color |
Font color of Y-axis ticks TYPE: strDEFAULT: "black"
|
ytick_weight |
Font weight of Y-axis ticks TYPE: strDEFAULT: "normal"
|
ytick_style |
Font style of Y-axis ticks TYPE: strDEFAULT: "normal"
|
grid |
Display grid TYPE: boolDEFAULT: True
|
grid_linestyle |
Line style of grid lines TYPE: strDEFAULT: "--" |
grid_alpha |
Opacity of grid lines TYPE: floatDEFAULT: 0.5 |
background_color |
Background color of the figure TYPE: str or NoneDEFAULT: None |
sort_order |
Sort bars by value ("ascending" or "descending") 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 single-sample mode
! KEGGaNOG -i some_data/sample.emapper.annotations -o KEGGaNOG_single_output
Then user can easily build a barplot on KEGGaNOG output
import kegganog as kgn
import pandas as pd
df = pd.read_csv("KEGGaNOG_single_output/SAMPLE_pathways.tsv", sep="\t")
kgnbar = kgn.barplot(df,
figsize = (8, 10),
sort_order="descending",
yticks_fontsize = 8,
cmap = "Blues",
)
# To plot a fig please use:
kgnbar.plotfig()Sample output:

kgn.barplot() returns an object containing the barplot figure and axis, so, user is able to further customize its plot!
E.g. user wants to divide pathways with completeness > 0.5 and < 0.5:
kgnbar.ax.axvline(0.5, color="red", linestyle="--")
kgnbar.plotfig()Sample output:

For saving a plot please use:
kgnbar.savefig("pic_name.png", dpi=600)