def read_D(filename):
    """reads an upper triangular matrix with phylogentic distances
       between species.
       Returns a dictionary with distances for species names."""
    D = {}
    f = open(filename)
    cols = f.readline().rstrip().split('\t')
    for line in f:
        elems = line.strip().split('\t')
        for i,e in enumerate(elems):
            if e!='' and i>0:
                D[(cols[i],elems[0])] = float(e)
                D[(elems[0],cols[i])] = float(e)
    f.close()
    return D