keggtools.analysis#

KEGG Enrichment analysis core.

Classes#

Enrichment

KEGG pathway enrichment analysis.

EnrichmentResult

Results of KEGG pathway enrichment analysis.

Functions#

plot_enrichment_result(enrichment[, ax, figsize, ...])

Plot enrichment results.

Module Contents#

class keggtools.analysis.Enrichment(pathways)#

KEGG pathway enrichment analysis.

Parameters:

pathways (list[keggtools.models.Pathway])

all_pathways: list[keggtools.models.Pathway]#
get_subset(subset, inplace=False)#

Create subset of analysis result by list of pathway ids.

Parameters:
  • subset (List[str]) – List of pathway identifer to filter enrichment result by.

  • inplace (bool) – Update instance variable of enrichment result list and overwrite with generated subset.

Returns:

Subset of enrichment results.

Return type:

List[EnrichmentResult]

result: list[EnrichmentResult] = []#
run_analysis(gene_list)#

List of gene ids. Return list of EnrichmentResult instances.

Parameters:

gene_list (List[str]) – List of genes to analyse.

Returns:

List of enrichment result instances.

Return type:

List[EnrichmentResult]

to_csv(file_obj, delimiter='\t', overwrite=False)#

Save result summary as file.

Parameters:
  • file_obj (str | io.IOBase | Any) – String to file or IOBase object

  • delimiter (str) – Deleimiter used for csv.

  • overwrite (bool) – Set to True to overwrite file, if already exist.

  • file_obj

Return type:

None

to_dataframe()#

Return analysis result as pandas DataFrame. Required pandas dependency.

Returns:

Export enrichment results as pandas dataframe.

Return type:

pandas.DataFrame

to_json()#

Export to json dict.

Return type:

List[Dict[str, Any]]

Returns:

Json dict of enrichment results.

class keggtools.analysis.EnrichmentResult(org, pathway_id, pathway_name, found_genes, pathway_genes, pathway_title=None)#

Results of KEGG pathway enrichment analysis.

Parameters:
  • org (str)

  • pathway_id (str)

  • pathway_name (str)

  • found_genes (list)

  • pathway_genes (list)

  • pathway_title (str | None)

__str__()#

Build string summary of KEGG path analysis result instance.

Return type:

str

Returns:

Returns string that describes the enrichment result instance.

found_genes: list#
static get_header()#

Build default header for enrichment analysis.

Return type:

List[str]

Returns:

List of header names as string.

json_summary(gene_delimiter=',')#

Build json summary for enrichment analysis.

Parameters:

gene_delimiter (str) – Delimiter to seperate genes in gene list.

Return type:

Dict[str, Any]

Returns:

Summary of enrichment result instance as dict.

organism: str#
pathway_genes: list#
property pathway_genes_count: int#

Count of pathway genes.

Return type:

int

Returns:

Number of genes in pathway.

pathway_id: str#
pathway_name: str#
pathway_title: str | None = None#
pvalue: float | None = None#
property study_count: int#

Count of study genes.

Return type:

int

Returns:

Number of genes found in analysis of pathway.

keggtools.analysis.plot_enrichment_result(enrichment, ax=None, figsize=(7, 7), cmap='coolwarm', min_study_count=1, max_pval=None, use_percent_study_count=True)#

Plot enrichment results.

Parameters:
Return type:

matplotlib.axes.Axes