From 569867e4baa097a232848c8c706f048c0b6829a1 Mon Sep 17 00:00:00 2001
From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr>
Date: Tue, 9 Feb 2021 09:45:35 +0100
Subject: [PATCH] src/find_interaction_cluster/config.py: fix merge problem by
 re-creating function get_communities_basefile

---
 src/find_interaction_cluster/config.py | 32 ++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/find_interaction_cluster/config.py b/src/find_interaction_cluster/config.py
index 5793dd39..fe864f7b 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, inflation: float,
@@ -90,7 +91,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`
 
@@ -109,6 +111,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
@@ -125,3 +152,4 @@ class ConfigGraph:
     get_hip_folder = get_hipmcl_folder
     get_hipmcl_prog = get_hipmcl_prog
     good_projects = get_good_project()
+    ppi_threshold = 700
\ No newline at end of file
-- 
GitLab