tooluniverse.enrichr_tool module

class tooluniverse.enrichr_tool.BaseTool(tool_config)[source][source]

Bases: object

__init__(tool_config)[source][source]
classmethod get_default_config_file()[source][source]

Get the path to the default configuration file for this tool type.

This method uses a robust path resolution strategy that works across different installation scenarios:

  1. Installed packages: Uses importlib.resources for proper package resource access

  2. Development mode: Falls back to file-based path resolution

  3. Legacy Python: Handles importlib.resources and importlib_resources

Override this method in subclasses to specify a custom defaults file.

Returns:

Path or resource object pointing to the defaults file

classmethod load_defaults_from_file()[source][source]

Load defaults from the configuration file

run(arguments=None)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

check_function_call(function_call_json)[source][source]
get_required_parameters()[source][source]

Retrieve required parameters from the endpoint definition. Returns: list: List of required parameters for the given endpoint.

tooluniverse.enrichr_tool.register_tool(tool_type_name=None, config=None)[source][source]

Decorator to automatically register tool classes and their configs.

Usage:

@register_tool(‘CustomToolName’, config={…}) class MyTool:

pass

class tooluniverse.enrichr_tool.EnrichrTool(tool_config)[source][source]

Bases: BaseTool

Tool to perform gene enrichment analysis using Enrichr.

__init__(tool_config)[source][source]
run(arguments)[source][source]

Main entry point for the tool.

get_official_gene_name(gene_name)[source][source]

Retrieve the official gene symbol for a given gene name or synonym using the MyGene.info API.

Parameters:

gene_name (str) – The gene name or synonym to query.

Returns:

The official gene symbol if found; otherwise, raises an Exception.

Return type:

str

submit_gene_list(gene_list)[source][source]

Submit the gene list to Enrichr and return the user list ID.

Parameters:

gene_list (str) – Newline-separated string of gene names.

Returns:

The user list ID from Enrichr.

Return type:

str

get_enrichment_results(user_list_id, library)[source][source]

Fetch enrichment results for a specific library.

Parameters:
  • user_list_id (str) – The user list ID from Enrichr.

  • library (str) – The name of the enrichment library.

Returns:

The enrichment results.

Return type:

dict

build_graph(genes, enrichment_results)[source][source]

Initialize and build the graph with gene nodes and enriched terms.

Parameters:
  • genes (list) – List of gene names.

  • enrichment_results (dict) – Dictionary of enrichment results by library.

Returns:

The constructed graph.

Return type:

networkx.Graph

rank_paths_by_weight(G, source, target)[source][source]

Find and rank paths between source and target based on total edge weight.

Parameters:
  • G (networkx.Graph) – The graph to search.

  • source (str) – The source node.

  • target (str) – The target node.

Returns:

List of tuples (path, weight) sorted by weight descending.

Return type:

list

rank_paths_to_term(G, gene, term)[source][source]

Find and rank paths from each gene to a specified term based on total edge weight.

Parameters:
  • G (networkx.Graph) – The graph to search.

  • gene (str) – The source gene.

  • term (str) – The target term.

Returns:

List of tuples (path, weight) sorted by weight descending, or None if no paths.

Return type:

list or None

enrichr_api(genes, libs)[source][source]

Main API function to perform gene enrichment analysis.

Parameters:
  • genes (list) – List of gene names.

  • libs (list) – List of enrichment libraries to use.

Returns:

(connected_path, connections) dictionaries.

Return type:

tuple