diff --git a/InheritanceAlgorithm_v08042021.py b/InheritanceAlgorithm_v08042021.py deleted file mode 100644 index bb5f252c56bbfbddefb67c5e2411a61fe71d2ce7..0000000000000000000000000000000000000000 --- a/InheritanceAlgorithm_v08042021.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Wed Sep 5 15:54:10 2018 - -@author: mhennart -""" -import pandas as pd -import networkx as nx - - -def Mappind_cluster_ST (data, seuil ) : - Df = pd.crosstab(data['ST'], data[seuil]) - Df = Df.drop('NA') - - B = nx.Graph() - B.add_nodes_from(Df.index, bipartite=1) - B.add_nodes_from(Df.columns, bipartite=0) - - for i in Df.index : - for j in Df.columns : - if Df[j][i] > 0 : - B.add_edge(i,j, weight=Df[j][i]) - - dico = {} - ST_attribute = [] - while len(B.edges) > 0 : - edges = B.edges(data=True) - max_weight_edges = max([edge[2]['weight'] for edge in edges]) - edges_subgraph = [(u,v) for (u,v,d) in B.edges(data=True) if d['weight'] == max_weight_edges] - C = B.edge_subgraph(edges_subgraph).copy() - - for connected_component in nx.connected_components(C) : - S = C.subgraph(connected_component).copy() - top_nodes = {n for n, d in S.nodes(data=True) if d["bipartite"] == 0} - bottom_nodes = set(S) - top_nodes - - if len(top_nodes) == 1 : - u = list(top_nodes)[0] - v = min(bottom_nodes) - B.remove_nodes_from((u,v)) - dico[u]= [ v , 'relative_ST' ] - ST_attribute.append(v) - else : - no_strains_nodes = [(sum(d['weight'] for (u,v,d) in C.edges(top_node, data=True)), top_node) for top_node in top_nodes] - no_strains_nodes.sort() - for (no_strains_node, node) in no_strains_nodes : - u = node - degree = [(S.degree[x], x) for x in S.adj[u] if x not in ST_attribute ] - if len(degree) > 0 : - v = min(degree)[1] - B.remove_nodes_from((u,v)) - dico[u]= [ v , 'relative_ST' ] - ST_attribute.append(v) - - - top_nodes = {n for n, d in B.nodes(data=True) if d["bipartite"] == 0} - lambda_ = 10000 - for u in top_nodes : - dico[u]= [lambda_ , "arbitrary"] - lambda_ += 1 - - mapping = data[seuil].apply(lambda x : dico[x][0]) - attribute = data[seuil].apply(lambda x : dico[x][1]) - - return mapping, attribute - -in_ = "PartionnementMLST_ALL.txt" -data = pd.read_csv(in_, sep='\t', index_col=0, dtype=str) -data = data.fillna('NA') - -seuils = ['Seuil43', 'Seuil190'] -for seuil in seuils : - mapping, attribute = Mappind_cluster_ST (data, seuil) - data['Mapping_'+seuil] = mapping - data['Attribute_'+seuil] = attribute - -data.to_csv('ResultatsMapping_CG_SL.txt', sep="\t") -