diff --git a/src/find_interaction_cluster/config.py b/src/find_interaction_cluster/config.py index 3c3d262c93c8d2dfa35e9e5c13e5b5d2a5caad5c..795e5a056f1482a199ec0f67a33d18bc96f10607 100644 --- a/src/find_interaction_cluster/config.py +++ b/src/find_interaction_cluster/config.py @@ -9,7 +9,8 @@ Description: Configuration folder from ..db_utils.config import Config from pathlib import Path from ..figures_utils.config_figures import get_good_project -from typing import List +from typing import List, Dict +import pandas as pd def get_weight_folder(weight: int, global_weight: int): @@ -81,7 +82,8 @@ def get_hipmcl_prog() -> Path: return get_hipmcl_folder() / "bin" / "hipmcl" -def get_communities(result: Path, threshold: int = 0) -> List[List[str]]: +def get_communities_basefile(result: Path, threshold: int = 0 + ) -> List[List[str]]: """ Get the communities inside the file `result` @@ -100,6 +102,31 @@ def get_communities(result: Path, threshold: int = 0) -> List[List[str]]: return communities +def get_communities(result: Path, feature: str, threshold: int = 0, + ) -> Dict[str, List[str]]: + """ + Get the communities inside the file `result` + + :param result: A file containing the communities found by the hipMCL \ + program. + :param threshold: The number of exon the community must contains at least \ + to be recovered + :param feature: The kind of feature analysed + :return: The list of communities find by the hipMCL program. + + >>> get_communities(Config.tests_files / "test_community_file.txt", "gene", + ... 0) + {'C1': ['415', '416', '421', '422', '423', '433', '441', '475', \ +'481', '502', '511'], 'C2': ['10123', '10209', '8812', '9140', '9166']} + """ + df = pd.read_csv(result, sep="\t")[["community", "nodes", f"{feature}s"]] + df = df[df["nodes"] >= threshold].copy() + df.index = df["community"] + df.drop(["nodes", "community"], axis=1, inplace=True) + dic = df.to_dict()[f"{feature}s"] + return {k: dic[k].split(", ") for k in dic} + + class ConfigGraph: """ Class containing all the variables that will be used in this submodule @@ -116,4 +143,3 @@ class ConfigGraph: get_hipmcl_prog = get_hipmcl_prog good_projects = get_good_project() ppi_threshold = 700 -