diff --git a/Visualisation_des_donnes_de_mapping.py b/Visualisation_des_donnes_de_mapping.py index b7449b5ef2b80a9945cd359134042d9078327804..260585f14d8c410e4f24a34b21b09f2efb3fd5f5 100644 --- a/Visualisation_des_donnes_de_mapping.py +++ b/Visualisation_des_donnes_de_mapping.py @@ -5,7 +5,7 @@ import matplotlib.pyplot as plt import seaborn as sns #### Importation des données -def Distance_matrix_clustering (input_file,val_infini=50): +def Distance_matrix_clustering (input_file,val_infini=50.2, n_clusters=5): dataframe= pd.read_excel(input_file,index_col = 0) print(dataframe.head()) @@ -45,10 +45,8 @@ def Distance_matrix_clustering (input_file,val_infini=50): else: matrice_pour_traitement[indice_ligne-ajustement_ligne][indice_colonne-ajustement_colonne]=data_tab[indice_ligne][indice_colonne] - - ##### Traitement de la matrice de distance - nombre_de_clusters=7 + nombre_de_clusters=n_clusters clustering = AgglomerativeClustering(n_clusters = nombre_de_clusters, metric = "precomputed",linkage="complete").fit(matrice_pour_traitement) #results_clustering=pd.DataFrame ({'in': [clustering.labels_] }) results_clustering=clustering.labels_ @@ -67,60 +65,66 @@ def Distance_matrix_clustering (input_file,val_infini=50): Liste_de_nom_trier_selon_cluster.append(Liste_nieme_cluster) Liste_d_indice_trier_selon_cluster.append(Liste_nieme_indice_cluster) - - ###### visualisation - - l_identifiants_de_graphes=[111,111,111,111,111,111,111,111] - plt.figure(figsize=(15, 3)) for num_graph in range (nombre_de_clusters): donnes_graph=[] - indentifiant_graphe=l_identifiants_de_graphes[num_graph] + indentifiant_graphe=111 for sous_indice in range(len(Liste_de_nom_trier_selon_cluster[num_graph])): donnes_graph.append(matrice_pour_traitement[Liste_d_indice_trier_selon_cluster[num_graph][0]][Liste_d_indice_trier_selon_cluster[num_graph][sous_indice]]) print(matrice_pour_traitement[Liste_d_indice_trier_selon_cluster[num_graph][0]][Liste_d_indice_trier_selon_cluster[num_graph][sous_indice]]) plt.subplot(indentifiant_graphe) plt.plot(Liste_de_nom_trier_selon_cluster[num_graph],donnes_graph ) - - plt.suptitle('les differents cluster') + plt.tick_params(axis='x', rotation=90, size=0.08,labelsize = 7) + plt.suptitle('les differents clusters n='+str(n_clusters)) plt.show() -#Distance_matrix_clustering("C:\\Users\\mumec\\Desktop\\Mini_codes\\DistanceMatrix_compose_interet.xlsx") - - -def visualisation_recouvrement (File, titre_du_graphique="Recouvrement moyen des différents pathways obtenues du mapping de ",numero_de_la_colonne_a_grapher=1): +def visualisation_recouvrement (File, titre_du_graphique="Recouvrement moyen des différents pathways obtenues du mapping de ",numero_de_la_colonne_a_grapher=2,num_colonne_label=0): dataframe= pd.read_excel(File) colnames = list(dataframe.columns) + fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(40, 5), sharex=False, sharey=False) -# create figure and axes - fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(20, 7), sharex=False, sharey=False) - - p1 = sns.barplot(x=colnames[0], y=colnames[numero_de_la_colonne_a_grapher], data=dataframe, palette='Spectral', ax=ax1) + p1 = sns.barplot(x=colnames[num_colonne_label], y=colnames[numero_de_la_colonne_a_grapher], data=dataframe, palette='Spectral', ax=ax1) p1.set(title=titre_du_graphique) - p1.bar_label(p1.containers[0]) # add annotation - p1.tick_params(axis='x', rotation=90, size=1) #rotation des ticklabels + p1.bar_label(p1.containers[0], fontsize=6, fmt='%.1f') # add annotation + p1.tick_params(axis='x', rotation=90, size=0.05,labelsize = 6) #rotation des ticklabels plt.show() -visualisation_recouvrement ("C:\\Users\\mumec\\Desktop\\Mini_codes\\fichier_pour_tests_graph.xlsx",titre_du_graphique="Recouvrement moyen des différentes voies métaboliques de la liste constructeurs sur KEGG") - - - - - - - - - +def color_pie(Data, Labels, Colors,Explode=None,fsize=(10,10)): + plt.figure(figsize = fsize) + plt.pie(Data, labels = Labels, + pctdistance = 0.7, + explode=Explode, + colors=Colors, + autopct = lambda x: str(round(x, 1)) + '%') + plt.legend(loc=1, fontsize=10) + plt.show() +def visualisation_frequences_metabolites (File, titre_du_graphique="fréquence des métabolites d'intérêts du mapping de ",numero_de_la_colonne_a_grapher=1, num_colonne_label=0): + dataframe= pd.read_excel(File) + colnames = list(dataframe.columns) + p1 = sns.barplot(x=colnames[num_colonne_label], y=colnames[numero_de_la_colonne_a_grapher], data=dataframe, palette='Spectral') + p1.set(title=titre_du_graphique) + p1.bar_label(p1.containers[0], fontsize=6, fmt='%.f') # add annotation + p1.tick_params(axis='x', rotation=90, size=0.05,labelsize = 5) #rotation des ticklabels + plt.show() +def boite_a_metabolites (File, titre_du_graphique="boîte à moustache",numero_de_la_colonne_a_grapher=1): + dataframe= pd.read_excel(File) + colnames = list(dataframe.columns) + B1= sns.boxplot( + color='goldenrod', + data=dataframe, + y=colnames[numero_de_la_colonne_a_grapher]); + B1.set(title=titre_du_graphique) + plt.show() @@ -131,7 +135,3 @@ visualisation_recouvrement ("C:\\Users\\mumec\\Desktop\\Mini_codes\\fichier_pour -#plt.plot(results_clustering) -#plt.title('clustering') -#plt.xlabel(metabolites_labels) -#plt.show() \ No newline at end of file