deeptools / HiCExplorer

HiCExplorer is a powerful and easy to use set of tools to process, normalize and visualize Hi-C data.
https://hicexplorer.readthedocs.org
GNU General Public License v3.0
231 stars 70 forks source link

hicInterIntraTAD: ZeroDivisionError: division by zero #770

Open mdozmorov opened 2 years ago

mdozmorov commented 2 years ago

hicInterIntraTAD seems to be very useful; however, I immediately ran into the division by zero error. Is it possible to account for such (likely, frequent) events?

ERROR:hicexplorer.hicInterIntraTAD:division by zeroTraceback (most recent call last):
  File "/home/mdozmorov/miniconda3/envs/HiCExplorer/lib/python3.7/site-packages/hicexplorer/hicInterIntraTAD.py", line 224, in computeInterIntraTADs
    inter_left_density = inter_left_number_of_contacts_nnz / inter_left_number_of_contacts
ZeroDivisionError: division by zero
$ hicInfo --version
hicInfo 3.7.2
$ python --version
Python 3.7.12

The command itself:

hicInterIntraTAD --matrix ${MATRIX} \
             --tadDomains ${TADDOMAINS} \
             --outFileName ${OUTFILENAME} \
             --outFileNameRatioPlot ${OUTPLOT} \
             --threads 24

Thanks, Mikhail

joachimwolff commented 2 years ago

Hi Mikhail,

Thanks for reporting this bug. I will take care to fix it.

Best,

Joachim

cgirardot commented 2 years ago

Hi @joachimwolff

I have the same issue, did you get any chances to fix this bug?

thx

cgirardot commented 2 years ago

Hi @joachimwolff

reading the code, I have simply conditioned the code at line 213 (and line 224 ) and set the inter_right_density and inter_left_density to 0 when inter_right_number_of_contacts (inter_left_number_of_contacts) is 0.

For instance:

inter_right_density = 0
if inter_right_number_of_contacts > 0:
    inter_right_density = inter_right_number_of_contacts_nzz / inter_right_number_of_contacts

do you see an issue with this fix?