diff --git a/src/find_interaction_cluster/community_finder.py b/src/find_interaction_cluster/community_finder.py index b7467fc4ad2995017f4ab99554df16662c016cb4..9e5841b908829eeb30f93c75d8dd80202cb23eeb 100644 --- a/src/find_interaction_cluster/community_finder.py +++ b/src/find_interaction_cluster/community_finder.py @@ -49,7 +49,7 @@ def create_graph(interaction: np.array) -> nx.Graph: graph = nx.Graph() graph.add_nodes_from(nodes) for inter in interaction: - graph.add_edge(inter[0], inter[1], weight=inter[2]) + graph.add_edge(inter[0], inter[1], weight=float(inter[2])) logging.debug(f'Node : {len(nodes)} - Edges : {len(interaction)}') return graph @@ -87,7 +87,8 @@ def write_cytoscape_graph(graph: nx.Graph, dic_community: Dict[str, str], def find_communities(graph: nx.Graph, project: str, outfile: Path, result_file: Path, - feature: str = 'exon') -> Tuple[pd.DataFrame, Dict]: + feature: str = 'exon', inflation: float = 1.5, + compute_ec_cov: bool = True) -> Tuple[pd.DataFrame, Dict]: """ Find the communities within the graph. @@ -95,6 +96,9 @@ def find_communities(graph: nx.Graph, project: str, :param project: The name of the project :param outfile: A file containing interaction :param feature: the kind of analysed feature (exons or gene) + :param inflation: The inflation parameter + :param compute_ec_cov: If true, compute edges connectivity and \ + coverage. :return: The communities within the graph and the community \ to wich each exon belong """ @@ -102,12 +106,14 @@ def find_communities(graph: nx.Graph, project: str, logging.debug("Finding community ...") if not result_file.is_file(): cmd = f"mpirun -np 1 {ConfigGraph.get_hipmcl_prog()} -M {outfile} " \ - f"-I 1.5 -per-process-mem 50 -o {result_file}" + f"-I {inflation} -per-process-mem 50 -o {result_file}" sp.check_call(cmd, shell=True, stderr=sp.STDOUT) communities = get_communities_basefile(result_file) dic_community = {} - cov = round(community.coverage(graph, communities), 2) - modularity = community.modularity(graph, communities, weight='X') + cov = np.nan + if compute_ec_cov: + cov = round(community.coverage(graph, communities), 2) + modularity = community.modularity(graph, communities, weight='weight') d = {'community': [], 'nodes': [], 'edges': [], 'EC': [], 'HCS': [], '%E vs E in complete G': [], 'cov': [], 'modularity': [], f'{feature}s': []} @@ -124,7 +130,9 @@ def find_communities(graph: nx.Graph, project: str, 2) except ZeroDivisionError: complete = np.nan - edge_connectivity = nx.edge_connectivity(subg) + edge_connectivity = np.nan + if compute_ec_cov: + edge_connectivity = nx.edge_connectivity(subg) is_hc = 'yes' if edge_connectivity > nb_nodes / 2 else 'no' for exon in c: dic_community[exon] = {'num': f'C{k + 1}',