def parseEnsemblLabels(intree):
    """
    Function to convert a Dendropy tree obtained from Ensembl (in NHX) format.
    Returns a new tree (leaves the input tree unchanged)

    :param intree: a tree as Dendropy object
    """
    t = intree.clone(depth=1)
    for n in t.internal_nodes():
        if n.annotations['D'].value == 'Y' or n.annotations['DD'].value == 'Y':
            n.label = 'duplication'
        else:
            n.label = 'speciation'
    t.seed_node.label = None

    # if the tree is unrooted with root node of degree 2, turn into trifurcation
    # while keeping the correct state
    cn = t.seed_node.child_nodes()
    if not t.is_rooted and len(cn)==2:
        i = 1 if cn[0].is_leaf() else 0
        tmp = cn[i].label
        cn[i].edge.collapse()
        t.seed_node.label = tmp

    return(t)