File size: 1,484 Bytes
e3814d7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# --------------------------------------------------------
# a script to help read from npz format hic matrices.
# --------------------------------------------------------
import numpy as np
def read_npz(
file_name,
hic_caption='hic',
bound = None,
multiple = 1,
include_additional_channels = True,
compact_idx_caption = 'compact',
norm_caption = 'norm',
):
data = np.load(file_name)
if include_additional_channels:
hic_matrix = data[hic_caption]
hic_matrix[0] *= multiple
else:
hic_matrix = data[hic_caption]
if len(hic_matrix.shape) >= 3:
hic_matrix = hic_matrix[0]
hic_matrix *= multiple
if bound is not None:
mask = np.zeros((hic_matrix.shape[-2], hic_matrix.shape[-1]))
for i in range(mask.shape[0]):
for j in range(max(i-bound+1, 0), min(i+bound, mask.shape[1])):
mask[i][j] = 1
hic_matrix = hic_matrix * mask
if compact_idx_caption in data:
compact_idx = data[compact_idx_caption]
else:
compact_idx = [i for i in range(hic_matrix.shape[-2])]
if norm_caption in data:
norm = data[norm_caption]
else:
norm = np.ones(hic_matrix.shape[-2])
return hic_matrix, compact_idx, norm |