def check_monophyly(self, <EOL>values, <EOL>target_attr, <EOL>ignore_missing=False,<EOL>unrooted=False):
if type(values) != set:<EOL><INDENT>values = set(values)<EOL><DEDENT>n2leaves = self.get_cached_content()<EOL>if ignore_missing:<EOL><INDENT>found_values = set([getattr(n, target_attr) for n in n2leaves[self]])<EOL>missing_values = values - found_values<EOL>values = values & found_values<EOL><DEDENT>targets = set([leaf for leaf in n2leaves[self]<EOL>if getattr(leaf, target_attr) in values])<EOL>if not ignore_missing:<EOL><INDENT>if values - set([getattr(leaf, target_attr) for leaf in targets]):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if unrooted:<EOL><INDENT>smallest = None<EOL>for side1, side2 in self.iter_edges(cached_content=n2leaves):<EOL><INDENT>if targets.issubset(side1) and (not smallest or len(side1) < len(smallest)):<EOL><INDENT>smallest = side1<EOL><DEDENT>elif targets.issubset(side2) and (not smallest or len(side2) < len(smallest)):<EOL><INDENT>smallest = side2<EOL><DEDENT>if smallest is not None and len(smallest) == len(targets):<EOL><INDENT>break<EOL><DEDENT><DEDENT>foreign_leaves = smallest - targets<EOL><DEDENT>else:<EOL><INDENT>common = self.get_common_ancestor(targets)<EOL>observed = n2leaves[common]<EOL>foreign_leaves = set([leaf for leaf in observed<EOL>if getattr(leaf, target_attr) not in values])<EOL><DEDENT>if not foreign_leaves:<EOL><INDENT>return True, "<STR_LIT>", foreign_leaves<EOL><DEDENT>else:<EOL><INDENT>poly_common = self.get_common_ancestor(foreign_leaves)<EOL>polyphyletic = [leaf for leaf in poly_common if<EOL>getattr(leaf, target_attr) in values]<EOL>if polyphyletic:<EOL><INDENT>return False, "<STR_LIT>", foreign_leaves<EOL><DEDENT>else:<EOL><INDENT>return False, "<STR_LIT>", foreign_leaves<EOL><DEDENT><DEDENT>
Returns True if a given target attribute is monophyletic under
this node for the provided set of values.

If not all values are represented in the current tree
structure, a ValueError exception will be raised to warn that
strict monophyly could never be reached (this behaviour can be
avoided by enabling the `ignore_missing` flag.

Parameters:
-----------
values: 
    a set of values for which monophyly is expected.

target_attr: 
    node attribute being used to check monophyly (i.e. species for 
    species trees, names for gene family trees, or any custom feature
    present in the tree).

ignore_missing: 
    Avoid raising an Exception when missing attributes are found.

unrooted: 
    If True, tree will be treated as unrooted, thus allowing to find
    monophyly even when current outgroup is spliting a monophyletic group.

Returns: 
--------
the following tuple
IsMonophyletic (boolean),
clade type ('monophyletic', 'paraphyletic' or 'polyphyletic'),
leaves breaking the monophyly (set)