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
评论列表
文章目录