Skip to content
Snippets Groups Projects
Commit 61dcf23f authored by nfontrod's avatar nfontrod
Browse files

src/find_interaction_cluster/community_finder.py: fix create_graph to use...

src/find_interaction_cluster/community_finder.py: fix create_graph to use weight if wanted + add 2 paramters in findo_community functions
parent 0f6dce74
Branches
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ def create_graph(interaction: np.array) -> nx.Graph: ...@@ -49,7 +49,7 @@ def create_graph(interaction: np.array) -> nx.Graph:
graph = nx.Graph() graph = nx.Graph()
graph.add_nodes_from(nodes) graph.add_nodes_from(nodes)
for inter in interaction: 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)}') logging.debug(f'Node : {len(nodes)} - Edges : {len(interaction)}')
return graph return graph
...@@ -87,7 +87,8 @@ def write_cytoscape_graph(graph: nx.Graph, dic_community: Dict[str, str], ...@@ -87,7 +87,8 @@ def write_cytoscape_graph(graph: nx.Graph, dic_community: Dict[str, str],
def find_communities(graph: nx.Graph, project: str, def find_communities(graph: nx.Graph, project: str,
outfile: Path, result_file: Path, 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. Find the communities within the graph.
...@@ -95,6 +96,9 @@ def find_communities(graph: nx.Graph, project: str, ...@@ -95,6 +96,9 @@ def find_communities(graph: nx.Graph, project: str,
:param project: The name of the project :param project: The name of the project
:param outfile: A file containing interaction :param outfile: A file containing interaction
:param feature: the kind of analysed feature (exons or gene) :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 \ :return: The communities within the graph and the community \
to wich each exon belong to wich each exon belong
""" """
...@@ -102,12 +106,14 @@ def find_communities(graph: nx.Graph, project: str, ...@@ -102,12 +106,14 @@ def find_communities(graph: nx.Graph, project: str,
logging.debug("Finding community ...") logging.debug("Finding community ...")
if not result_file.is_file(): if not result_file.is_file():
cmd = f"mpirun -np 1 {ConfigGraph.get_hipmcl_prog()} -M {outfile} " \ 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) sp.check_call(cmd, shell=True, stderr=sp.STDOUT)
communities = get_communities_basefile(result_file) communities = get_communities_basefile(result_file)
dic_community = {} dic_community = {}
cov = round(community.coverage(graph, communities), 2) cov = np.nan
modularity = community.modularity(graph, communities, weight='X') if compute_ec_cov:
cov = round(community.coverage(graph, communities), 2)
modularity = community.modularity(graph, communities, weight='weight')
d = {'community': [], 'nodes': [], 'edges': [], 'EC': [], 'HCS': [], d = {'community': [], 'nodes': [], 'edges': [], 'EC': [], 'HCS': [],
'%E vs E in complete G': [], '%E vs E in complete G': [],
'cov': [], 'modularity': [], f'{feature}s': []} 'cov': [], 'modularity': [], f'{feature}s': []}
...@@ -124,7 +130,9 @@ def find_communities(graph: nx.Graph, project: str, ...@@ -124,7 +130,9 @@ def find_communities(graph: nx.Graph, project: str,
2) 2)
except ZeroDivisionError: except ZeroDivisionError:
complete = np.nan 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' is_hc = 'yes' if edge_connectivity > nb_nodes / 2 else 'no'
for exon in c: for exon in c:
dic_community[exon] = {'num': f'C{k + 1}', dic_community[exon] = {'num': f'C{k + 1}',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment