tooluniverse.enrichr_tool moduleΒΆ

class tooluniverse.enrichr_tool.EnrichrTool[source]ΒΆ

Bases: BaseTool

Tool to perform gene enrichment analysis using Enrichr.

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

Main entry point for the tool.

get_official_gene_name(gene_name)[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

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

submit_gene_list(gene_list)[source]ΒΆ

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

Parameters

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

Returns

str: The user list ID from Enrichr.

get_enrichment_results(user_list_id, library)[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

dict: The enrichment results.

build_graph(genes, enrichment_results)[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

networkx.Graph: The constructed graph.

rank_paths_by_weight(G, source, target)[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: List of tuples (path, weight) sorted by weight descending.

rank_paths_to_term(G, gene, term)[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 or None: List of tuples (path, weight) sorted by weight descending, or None if no paths.

enrichr_api(genes, libs)[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

tuple: (connected_path, connections) dictionaries.