matrix.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:gamtools 作者: pombo-lab 项目源码 文件源码
def read_triangular(filepath):
    """Open Pi matrix output from SLICE.

    All matrix opening functions return first the
    genomic windows corresponding to the axes of the
    proximity matrix, then the proximity matrix itself.
    Since SLICE output matrices do not embed the genomic
    locations of the windows, the first return value is
    None.

    :param str filepath: Path to the SLICE output file
    :returns: (None, SLICE Pi matrix)
    """

    with open(filepath) as in_data:
        arr = [[float(i) for i in line.split()] for line in in_data]
    size = len(arr[-1])
    proximity_matrix = np.zeros((size, size))
    lower_i = np.tril_indices_from(proximity_matrix)
    upper_i = np.triu_indices_from(proximity_matrix)
    proximity_matrix[:] = np.NAN
    proximity_matrix[lower_i] = list(itertools.chain(*arr))
    proximity_matrix[upper_i] = proximity_matrix.T[upper_i]
    proximity_matrix[proximity_matrix > 1.] = np.NAN

    return None, proximity_matrix
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号