-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation_plots_all.py
194 lines (137 loc) · 8.89 KB
/
evaluation_plots_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from inputs import *
from create_graph import create_graph
from assign_nodes import *
from evaluation import *
import textwrap
from wikipathways_converter import get_wikipathways_list
from graph_similarity_metrics import *
from constants import (
WIKIPATHWAYS_SUBFOLDER
)
'''def read_edge_type_file(all_dfs,output_dir):
edge_type_comparison_file = output_dir + '/Evaluation_Files/edge_type_comparison.csv'
df = pd.read_csv(edge_type_comparison_file,sep=',')
all_dfs = pd.concat([all_dfs,df], axis=0)
return all_dfs'''
'''def read_ontology_type_file(all_dfs,output_dir):
intermediate_nodes_comparison_file = output_dir + '/Evaluation_Files/intermediate_nodes_comparison.csv'
df = pd.read_csv(intermediate_nodes_comparison_file,sep=',')
all_dfs = pd.concat([all_dfs,df], axis=0)
return all_dfs'''
#Generates histogram with N number of categories by pathway, where lists are the input
def edge_type_comparison_visualization(output_dir,df):
output_folder = output_dir+'/node_edge_evaluation'
plt_file = output_folder + '/edge_type_comparison.png'
sns_plot = sns.barplot(df, x='Edge_Type', y = 'Percent_Edges',hue='Algorithm',errorbar=None)
sns_plot.set_title("Edge Type Comparison for all Wikipathway Diagrams")
wrap_labels(sns_plot, 20)
sns_plot.tick_params(axis='x', labelrotation=45)
plt.tick_params(axis='x', which='major', labelsize=7)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
def wrap_labels(ax, width, break_long_words=False):
labels = []
for label in ax.get_xticklabels():
text = label.get_text()
labels.append(textwrap.fill(text, width=width,
break_long_words=break_long_words))
ax.set_xticklabels(labels, rotation=0)
def intermediate_nodes_comparison_visualization(output_dir,df):
output_folder = output_dir+'/node_edge_evaluation'
plt_file = output_folder + '/intermediate_nodes_comparison.png'
sns_plot = sns.barplot(df, x='Ontology_Type', y = 'Percent_Nodes',hue='Algorithm',errorbar=None)
sns_plot.set_title("Ontology Type Comparison for all Wikipathway Diagrams")
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
#Generates histogram with N number of categories by pathway, where lists are the input
def visualize_graph_similarity_metrics(results_file,all_wikipathways_dir):
results_df = pd.read_csv(results_file,sep=',')
algorithms = results_df.Algorithm.unique()
for algorithm in algorithms:
df = results_df.loc[results_df['Algorithm'] == algorithm]
plt_file = all_wikipathways_dir + '/graph_similarity/' + algorithm + '_Graph_Similarity_Metrics_Jaccard_Overlap.png'
sns_plot = sns.barplot(df, x='Pathway_ID', y = 'Score',hue='Metric',errorbar=None)
sns_plot.set_title("Graph Similarity Metrics for Wikipathways Diagrams and "+ algorithm)
plt.xticks(rotation=45)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
def visualize_graph_node_percentage_metrics(results_file,all_wikipathways_dir):
results_df = pd.read_csv(results_file,sep=',')
algorithms = results_df.Algorithm.unique()
metrics = results_df.Metric.unique()
for algorithm in algorithms:
df = results_df.loc[results_df['Algorithm'] == algorithm]
plt_file = all_wikipathways_dir + '/graph_similarity/' + algorithm + '_Graph_Node_Percentage_Metrics.png'
sns_plot = sns.barplot(df, x='Pathway_ID', y = 'Score',hue='Metric',errorbar=None)
sns_plot.set_title("Graph Node Percentage Metrics for Wikipathways Diagrams and "+ algorithm)
plt.xticks(rotation=45)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
#Generates boxplot of each
def visualize_literature_comparison_boxplot(all_subgraphs_cosine_sim_df,all_wikipathways_dir):
output_folder = all_wikipathways_dir+'/literature_comparison/Evaluation_Files'
plt_file = output_folder + '/Literature_Comparison_all_terms_boxplot.png'
sns.swarmplot(data=all_subgraphs_cosine_sim_df, x="Pathway_ID", y="Average_Cosine_Similarity",hue="Algorithm", dodge=True, legend=False)
sns.boxplot(data=all_subgraphs_cosine_sim_df, x='Pathway_ID', y = 'Average_Cosine_Similarity',hue='Algorithm').set_title("Cosine Similarity of subgraph to All Associated Literature Terms")
plt.xticks(rotation=45)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
def visualize_literature_comparison_scatterplot(all_subgraphs_cosine_sim_df,all_wikipathways_dir):
pathways = all_subgraphs_cosine_sim_df.Pathway_ID.unique()
for pathway in pathways:
df = all_subgraphs_cosine_sim_df.loc[all_subgraphs_cosine_sim_df['Pathway_ID'] == pathway]
terms = df.Term.unique()
plt_file = all_wikipathways_dir + '/' + pathway + '_output/Evaluation_Files/Literature_Comparison_all_terms_scatterplot.png'
sns_plot = sns.swarmplot(data=df, x='Algorithm', y = 'Average_Cosine_Similarity',hue='Term')
sns.lineplot(x="Algorithm", dashes=False, y="Average_Cosine_Similarity", hue="Term", style="Term", data=df,legend=False).set_title("Cosine Similarity of " + pathway + " Subgraph to All Associated Literature Terms")
sns.move_legend(sns_plot,"upper left", bbox_to_anchor=(1, 1))
plt.xticks(rotation=45)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
def visualize_literature_comparison_heatmap(term_averages_cosine_sim_df,all_wikipathways_dir):
output_folder = all_wikipathways_dir+'/literature_comparison/Evaluation_Files'
plt_file = output_folder + '/Literature_Comparison_all_terms_heatmap.png'
df_matrix = term_averages_cosine_sim_df.pivot_table(index='Pathway_ID',columns='Algorithm',values='Average_Cosine_Similarity')
sns.heatmap(df_matrix, fmt="g", cmap='viridis').set_title("Average Cosine Similarity of Subgraphs to All Associated Literature Terms")
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
#Generates boxplot of each
def visualize_literature_comparison_boxplot_all_pathways(all_subgraphs_zscore_df,all_wikipathways_dir):
output_folder = all_wikipathways_dir+'/literature_comparison/Evaluation_Files'
all_subgraphs_other_pathways = all_subgraphs_zscore_df.loc[all_subgraphs_zscore_df.Compared_Pathway != "Same_Pathway"]
all_subgraphs_same_pathway = all_subgraphs_zscore_df.loc[all_subgraphs_zscore_df.Compared_Pathway == "Same_Pathway"]
plt_file = output_folder + '/Literature_Comparison_all_pathways_boxplot.png'
sns.swarmplot(data=all_subgraphs_same_pathway, x="Pathway_ID", y="avg_zscore_per_pathway",hue='Algorithm',palette="flare",dodge=True, legend=False, marker="x", linewidth=1,size=10)
sns.swarmplot(data=all_subgraphs_other_pathways, x="Pathway_ID", y="avg_zscore_per_pathway",hue="Algorithm", dodge=True, legend=False)
sns.boxplot(data=all_subgraphs_other_pathways, x='Pathway_ID', y = 'avg_zscore_per_pathway',hue='Algorithm').set_title("Z-Score of Cosine Similarity to All Pathway Abstracts")
plt.xticks(rotation=45)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
def visualize_literature_comparison_scatterplot_all_pathways(all_subgraphs_zscore_df,all_wikipathways_dir):
pathways = all_subgraphs_zscore_df.Pathway_ID.unique()
for pathway in pathways:
df = all_subgraphs_zscore_df.loc[all_subgraphs_zscore_df['Pathway_ID'] == pathway]
plt_file = all_wikipathways_dir + '/' + pathway + '_output/Evaluation_Files/Literature_Comparison_all_pathways_scatterplot.png'
sns_plot = sns.swarmplot(data=df, x='Algorithm', y = 'avg_zscore_per_pathway',hue='Compared_Pathway')
sns.lineplot(x="Algorithm", dashes=False, y="avg_zscore_per_pathway", hue="Compared_Pathway", style="Compared_Pathway", data=df,legend=False).set_title("Z-Score of Cosine Similarity to All Pathway Abstracts for" + pathway)
sns.move_legend(sns_plot,"upper left", bbox_to_anchor=(1, 1))
plt.xticks(rotation=45)
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)
def visualize_literature_comparison_heatmap_all_pathways(all_subgraphs_zscore_df,all_wikipathways_dir):
output_folder = all_wikipathways_dir+'/literature_comparison/Evaluation_Files'
plt_file = output_folder + '/Literature_Comparison_all_pathways_heatmap.png'
df_matrix = all_subgraphs_zscore_df.pivot_table(index='Pathway_ID',columns='Algorithm',values='avg_zscore_per_pathway')
sns.heatmap(df_matrix, fmt="g", cmap='viridis').set_title("Z-Score of Subgraphs to All Other Pathways")
plt.savefig(plt_file,bbox_inches="tight")
plt.close()
logging.info('Created png: %s',plt_file)