@@ -395,15 +395,23 @@ def compute_alpha_index(maxi_graph, cluster_vertexs):
395
395
396
396
nb_nodes = len (cluster_vertexs )
397
397
nb_edges = cluster_graph .ecount ()
398
+ nb_component = len (cluster_graph .connected_components ())
399
+
400
+ if nb_nodes <= 2 :
401
+ # use to prevent div by zero
402
+ alpha_index_non_planar = 0
403
+
404
+ else :
405
+ alpha_index_non_planar = (nb_edges - nb_nodes + nb_component ) / ( (nb_nodes * (nb_nodes - 1 ) / 2 ) - (nb_nodes - 1 ) )
398
406
399
- alpha_index = (nb_edges - nb_nodes ) / ( (nb_nodes * (nb_nodes - 1 ) / 2 ) - (nb_nodes - 1 ) )
400
407
401
- # # Formula for planar graph
402
- # nb_component = len(cluster_graph.components()) # should be 0
403
- # nb_cycle = nb_edges - nb_nodes + nb_component
404
- # alpha_index = nb_cycle / (2 * nb_edges - 5)
408
+ print ( 'alpha index, non planar graph' , alpha_index_non_planar )
409
+ # Formula for planar graph
410
+ nb_cycle = nb_edges - nb_nodes + nb_component
411
+ alpha_index_planar = nb_cycle / (2 * nb_nodes - 5 )
405
412
406
- return round (alpha_index , 2 )
413
+ print ('alpha index, planar graph' , alpha_index_planar )
414
+ return f'planar: { round (alpha_index_planar , 2 )} , non planar: { round (alpha_index_non_planar , 2 )} '
407
415
408
416
409
417
def run (PROTEINS , TARGETS , GCUSER , GAP , CUTOFF , ADVANCEDSETTINGSFILENAME ):
0 commit comments