Last active
May 8, 2016 01:24
-
-
Save aldro61/d11d9b9093a2518ab0251bae011d5455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_hic_matrix(hic_path): | |
f = open(hic_path, "r") | |
# Parse the header | |
header = f.next() | |
assert header[0] == "#" | |
min_row, max_row, min_col, max_col = [int(x) for x in header[2:].split(" ")] | |
# Create an empty matrix of n_fragments x n_fragments | |
hic = np.zeros((max_col + 1, max_col + 1)) | |
# Fill in the values (symmetric) | |
for l in f: | |
interaction, chr1, row, chr2, column = [int(x) for x in l.split("\t")] | |
assert chr1 == chr2 # cis data only | |
hic[row, column] = hic[column, row] = interaction | |
# Make sure that the matrix is symmetric | |
assert np.all(hic == hic.T) | |
return hic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment