Open GMFranceschini opened 1 month ago
Yes indeed, I think that's the problem. If you can add it yourself, that should solve it.
Thank you! Indeed one could do this, right?
sum_contacts = clr.pixels()[:]["count"].sum()
clr.info["sum"] = sum_contacts
I can submit a PR to handle this corner case if it is useful. Our mcool files have been generated with hic2cool
so that might be the culprit.
Indeed this could be the reason!
I am not sure off the top of my head whether this would actually store the value in the file... @nvictus ?
In the end, my solution was a bit more complicated, as np.int64
was causing me trouble re-writing the metadata slot (I am not sure adding "sum" on clr.info directly was working).
Feel free to close the issue and let me know if I can contribute, I feel like computing the sum on the spot and adding it post downsampling would make sense.
def addSum_mcool(mcool_file, out_file):
clr = cl.Cooler(mcool_file)
c_sum = clr.pixels()[:]["count"].sum()
metadata = dict()
metadata["sum"] = int(c_sum)
for key, value in clr.info.items():
if isinstance(value, np.int64):
metadata[key] = int(value)
else:
metadata[key] = value
print("Sum of the matrix: ", metadata["sum"])
pixel_mat = clr.pixels()[:]
bins = clr.bins()[:]
cl.create_cooler(out_file, bins=bins, pixels=pixel_mat, metadata=metadata)
Hi, thank you for the amazing tool. I am encountering this error when downsampling a cool file, I was wondering if you could help me debug this.
I am running:
And I get:
I checked the output of
cooler info
and indeed there is not asum
field. Is that the problem? Should I generate one to make it work?