def decorate(self, output_tree, output_tax, unique_names):
logging.info("<STR_LIT>")<EOL>encountered_taxonomies = {}<EOL>tc = TaxonomyCleaner()<EOL>for node in self.tree.preorder_internal_node_iter(exclude_seed_node=True):<EOL><INDENT>max_tax_string_length = <NUM_LIT:0><EOL>for tip in node.leaf_nodes():<EOL><INDENT>tip_label=tip.taxon.label.replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>if tip_label in self.taxonomy:<EOL><INDENT>tax_string_length= len(self.taxonomy[tip.taxon.label.replace('<STR_LIT:U+0020>', '<STR_LIT:_>')])<EOL>if tax_string_length > max_tax_string_length:<EOL><INDENT>max_tax_string_length = tax_string_length<EOL><DEDENT><DEDENT><DEDENT>logging.debug("<STR_LIT>" % max_tax_string_length)<EOL>tax_string_array = []<EOL>for rank in range(max_tax_string_length):<EOL><INDENT>rank_tax = []<EOL>for tip in node.leaf_nodes():<EOL><INDENT>tip_label = tip.taxon.label.replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>if tip_label in self.taxonomy:<EOL><INDENT>tip_tax = self.taxonomy[tip_label]<EOL>if len(tip_tax) > rank:<EOL><INDENT>tip_rank = tip_tax[rank]<EOL>if tip_rank not in rank_tax:<EOL><INDENT>rank_tax.append(tip_rank)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>consistent_taxonomy = len(rank_tax) == <NUM_LIT:1><EOL>if consistent_taxonomy:<EOL><INDENT>tax=rank_tax.pop()<EOL>logging.debug("<STR_LIT>"% tax)<EOL>if tax not in tc.meaningless_taxonomic_names:<EOL><INDENT>if unique_names:<EOL><INDENT>if tax in encountered_taxonomies:<EOL><INDENT>encountered_taxonomies[tax]+=<NUM_LIT:0><EOL>tax = "<STR_LIT>"% (tax, encountered_taxonomies[tax])<EOL><DEDENT>else:<EOL><INDENT>encountered_taxonomies[tax]=<NUM_LIT:0><EOL><DEDENT><DEDENT>tax_string_array.append(tax)<EOL><DEDENT><DEDENT><DEDENT>if any(tax_string_array):<EOL><INDENT>index = <NUM_LIT:0><EOL>for anc in node.ancestor_iter():<EOL><INDENT>try:<EOL><INDENT>index+=anc.tax<EOL><DEDENT>except:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>tax_string_array = tax_string_array[index:]<EOL>if any(tax_string_array):<EOL><INDENT>self._rename(node, '<STR_LIT>'.join(tax_string_array))<EOL><DEDENT>node.tax = len(tax_string_array)<EOL><DEDENT><DEDENT>logging.info("<STR_LIT>" % output_tree)<EOL>if output_tree:<EOL><INDENT>self.tree.write(path=output_tree, schema="<STR_LIT>")<EOL><DEDENT>if output_tax:<EOL><INDENT>self._write_consensus_strings(output_tax)<EOL><DEDENT>
Decorate a tree with taxonomy. This code does not allow inconsistent
taxonomy within a clade. If one sequence in a clade has a different
annotation to the rest, it will split the clade. Paraphyletic group
names are distinguished if unique_names = True using a simple tally of
each group (see unique_names below).

Parameters
----------
output_tree        : string
    File to which the decorated tree will be written.
output_tax         : string
    File to which the taxonomy strings for each tip in the tree will be
    written.
unique_names       : boolean
    True indicating that a unique number will be appended to the end of
    a taxonomic rank if it is found more than once in the tree
    (i.e. it is paraphyletic in the tree). If false, multiple clades
    may be assigned with the same name.