def write_newick(rootnode, <EOL>features=None, <EOL>format=<NUM_LIT:1>, <EOL>format_root_node=True,<EOL>is_leaf_fn=None, <EOL>dist_formatter=None,<EOL>support_formatter=None,<EOL>name_formatter=None):
newick = []<EOL>leaf = is_leaf_fn if is_leaf_fn else lambda n: not bool(n.children)<EOL>for postorder, node in rootnode.iter_prepostorder(is_leaf_fn=is_leaf_fn):<EOL><INDENT>if postorder:<EOL><INDENT>newick.append("<STR_LIT:)>")<EOL>if node.up is not None or format_root_node:<EOL><INDENT>newick.append(format_node(node, "<STR_LIT>", format,<EOL>dist_formatter=dist_formatter,<EOL>support_formatter=support_formatter,<EOL>name_formatter=name_formatter))<EOL>newick.append(_get_features_string(node, features))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if node is not rootnode and node != node.up.children[<NUM_LIT:0>]:<EOL><INDENT>newick.append("<STR_LIT:U+002C>")<EOL><DEDENT>if leaf(node):<EOL><INDENT>safe_name = re.sub("<STR_LIT:[>"+_ILEGAL_NEWICK_CHARS+"<STR_LIT:]>", "<STR_LIT:_>",str(getattr(node, "<STR_LIT:name>")))<EOL>newick.append(format_node(node, "<STR_LIT>", format,<EOL>dist_formatter=dist_formatter,<EOL>support_formatter=support_formatter,<EOL>name_formatter=name_formatter))<EOL>newick.append(_get_features_string(node, features))<EOL><DEDENT>else:<EOL><INDENT>newick.append("<STR_LIT:(>")<EOL><DEDENT><DEDENT><DEDENT>newick.append("<STR_LIT:;>")<EOL>return '<STR_LIT>'.join(newick)<EOL>
Iteratively export a tree structure and returns its NHX
representation.