def tree2parent_table(tree, data_cols=[]):
    """Converts tree to a parent table

    This parent table will have a special numbering for the internal nodes,
    such that their id is also their row in the table.

    parent table is a standard format of the Compbio Lab as of 02/01/2007.
    It is a list of triples (node_name, parent_name, dist, ...)

    * parent_name indicates the parent of the node.  If the node is a root
      (has no parent), then parent_name is -1

    * dist is the distance between the node and its parent.

    * additional columns can be added using the data_cols argument.  The
      values are looked up from node.data[col]
    """

    ptable = []

    for node in tree:
        if node.parent:
            pname = node.parent.name
        else:
            pname = -1
        row = [node.name, pname, node.dist]
        for col in data_cols:
            row.append(node.data[col])
        ptable.append(row)

    return ptable