Skip to content

Instantly share code, notes, and snippets.

@aldro61
Last active May 8, 2016 01:24
Show Gist options
  • Save aldro61/d11d9b9093a2518ab0251bae011d5455 to your computer and use it in GitHub Desktop.
Save aldro61/d11d9b9093a2518ab0251bae011d5455 to your computer and use it in GitHub Desktop.
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