def find_clades(self):
<EOL>ndict = {j: i for i, j in enumerate(self.names)}<EOL>namedict = {i: j for i, j in enumerate(self.names)}<EOL>clade_counts = {}<EOL>for tidx, ncopies in self.treedict.items():<EOL><INDENT>ttree = self.treelist[tidx].unroot()<EOL>for node in ttree.treenode.traverse('<STR_LIT>'):<EOL><INDENT>bits = np.zeros(len(ttree), dtype=np.bool_)<EOL>for child in node.iter_leaf_names():<EOL><INDENT>bits[ndict[child]] = True<EOL><DEDENT>bitstring = bits.tobytes()<EOL>revstring = np.invert(bits).tobytes()<EOL>if bitstring in clade_counts:<EOL><INDENT>clade_counts[bitstring] += ncopies<EOL><DEDENT>else:<EOL><INDENT>if revstring not in clade_counts:<EOL><INDENT>clade_counts[bitstring] = ncopies<EOL><DEDENT>else:<EOL><INDENT>clade_counts[revstring] += ncopies<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for key, val in clade_counts.items():<EOL><INDENT>clade_counts[key] = val / float(len(self.treelist))<EOL><DEDENT>self.namedict = namedict<EOL>self.clade_counts = sorted(<EOL>clade_counts.items(),<EOL>key=lambda x: x[<NUM_LIT:1>],<EOL>reverse=True)<EOL>
Count clade occurrences.