22import pickle as pkl
33from pathlib import Path
44from typing import Dict , Iterable
5-
5+ import numpy as np
6+ import seaborn as sns
67from matplotlib import pyplot as plt
78import pandas as pd
89from sklearn .metrics import precision_score , recall_score
@@ -169,3 +170,48 @@ def precision_and_recall_edge(file_paths: Iterable[Path], edge_table: pd.DataFra
169170 plt .plot ([], [])
170171 plt .title ("Empty Pathway Files" )
171172 plt .savefig (output_png )
173+
174+
175+ @staticmethod
176+ def jaccard_edge_heatmap (file_paths : Iterable [Path ], edge_table : pd .DataFrame , output_png :str = None ):
177+ """
178+ Takes in file paths for a specific dataset and an associated gold standard edge table.
179+ Generates a jaccard index heatmap image that compares all the edge similarity between each dataset and the gold standard
180+ Returns output back to output_png
181+ @param file_paths: file paths of pathway reconstruction algorithm outputs
182+ @param edge_table: the gold standard edges
183+ @param output_png (optional): the filename to plot the heatmap (not a PRC)
184+ """
185+ gs_edges = set ()
186+ for row in edge_table .itertuples ():
187+ gs_edges .add ((row [1 ], row [2 ]))
188+
189+ # calculate all the jaccard edge index for each method against the gold standard
190+ jaccard_edge_indices_list = []
191+ algorithms = []
192+ for file in file_paths :
193+ df = pd .read_table (file , sep = "\t " , header = 0 , usecols = ["Node1" , "Node2" ])
194+ method_edges = set ()
195+ for row in df .itertuples ():
196+ method_edges .add ((row [1 ], row [2 ]))
197+ edge_union = gs_edges | method_edges
198+ edge_intersection = gs_edges & method_edges
199+ jaccard_edge_index = len (edge_intersection ) / len (edge_union )
200+ jaccard_edge_indices_list .append (float (jaccard_edge_index ))
201+ algorithms .append (file .split ("/" )[1 ].split ("-" )[1 ])
202+
203+ jaccard_edge_indices = np .asanyarray ([jaccard_edge_indices_list ])
204+
205+ plt .figure (figsize = (10 , 8 ))
206+ sns .heatmap (
207+ jaccard_edge_indices ,
208+ annot = True ,
209+ cmap = "viridis" ,
210+ xticklabels = algorithms ,
211+ yticklabels = ["" ],
212+ )
213+ plt .xlabel ("Algorithms" )
214+ plt .ylabel ("Pathways" )
215+ plt .title ("Jaccard Index Edge Heatmap" )
216+ plt .tick_params (axis = 'x' , which = 'major' , labelsize = 7.5 )
217+ plt .savefig (output_png , format = "png" , dpi = 300 )
0 commit comments