#NEWLINE# def _walk_clades( trees , weights ) : #NEWLINE# #INDENT# 'Walk all the clades of all the trees\n\n    Parameters\n    ----------\n    trees : list of TreeNode\n        The trees to walk\n    weights : np.array\n        Tree weights\n\n    Returns\n    -------\n    list of tuple\n        The clades and support values sorted by support value such that the\n        most supported clade is index 0. The tuples are of the form:\n        (frozenset, float).\n    defaultdict(float)\n        The edge lengths, keyed by frozenset of the clade, and valued by the\n        weighted average length of the clade by the trees the clade was\n        observed in.\n\n    ' #NEWLINE# clade_counts = defaultdict ( float ) #NEWLINE# edge_lengths = defaultdict ( float ) #NEWLINE# total = weights . sum ( ) #NEWLINE# def tipnames_f( n ) : #NEWLINE# #INDENT# return ( [ n . name ] if n . is_tip ( ) else [ ] ) #NEWLINE# #UNINDENT# for ( tree , weight ) in zip ( trees , weights ) : #NEWLINE# #INDENT# tree . cache_attr ( tipnames_f , 'tip_names' , frozenset ) #NEWLINE# for node in tree . postorder ( ) : #NEWLINE# #INDENT# tip_names = node . tip_names #NEWLINE# length = ( ( node . length * weight ) if ( node . length is not None ) else None ) #NEWLINE# clade_counts [ tip_names ] += weight #NEWLINE# if ( length is None ) : #NEWLINE# #INDENT# edge_lengths [ tip_names ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# edge_lengths [ tip_names ] += ( length / total ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# clade_counts = sorted ( clade_counts . items ( ) , key = ( lambda x : len ( x [ 0 ] ) ) , reverse = True ) #NEWLINE# return ( clade_counts , edge_lengths )