`label_key` is a string (a key in the otu object) or a callable that takes two arguments:
        the node, and the otu (which may be None for an internal node)
    If `leaf_labels` is not None, it shoulr be a (list, dict) pair which will be filled. The list will
        hold the order encountered,
        and the dict will map name to index in the list

def convert_tree_to_newick(tree,
                           otu_group,
                           label_key,
                           leaf_labels,
                           needs_quotes_pattern=NEWICK_NEEDING_QUOTING,
                           subtree_id=None,
                           bracket_ingroup=False):
    """`label_key` is a string (a key in the otu object) or a callable that takes two arguments:
        the node, and the otu (which may be None for an internal node)
    If `leaf_labels` is not None, it shoulr be a (list, dict) pair which will be filled. The list will
        hold the order encountered,
        and the dict will map name to index in the list
    """
    assert (not is_str_type(label_key)) or (label_key in PhyloSchema._NEWICK_PROP_VALS)  # pylint: disable=W0212
    ingroup_node_id = tree.get('^ot:inGroupClade')
    if subtree_id:
        if subtree_id == 'ingroup':
            root_id = ingroup_node_id
            ingroup_node_id = None  # turns of the comment pre-ingroup-marker
        else:
            root_id = subtree_id
    else:
        root_id = tree['^ot:rootNodeId']
    edges = tree['edgeBySourceId']
    if root_id not in edges:
        return None
    nodes = tree['nodeById']
    sio, out = get_utf_8_string_io_writer()
    nexson_frag_write_newick(out,
                             edges,
                             nodes,
                             otu_group,
                             label_key,
                             leaf_labels,
                             root_id,
                             needs_quotes_pattern=needs_quotes_pattern,
                             ingroup_id=ingroup_node_id,
                             bracket_ingroup=bracket_ingroup)
    flush_utf_8_writer(out)
    return sio.getvalue()