def writePhen(phen, filename, missing='9', sep='\t'):
    """
    must contain phen['iid'] and phen['vals']
    """
    N = phen['iid'].shape[0]
    M = phen['vals'].shape[1]
    assert N == phen['vals'].shape[0
        ], "number of individuals do not match up in phen['vals'] and phen['ids']"
    with open(filename, 'w') as f:
        for i in range(0, N):
            tmpstr = phen['iid'][i][0] + sep + phen['iid'][i][1]
            for m in range(0, M):
                tmpstr += sep + str(phen['vals'][i][m])
            tmpstr += '\n'
            f.write(tmpstr)
