yezhengSTAT / mHiC

MIT License
22 stars 10 forks source link

Step 4: Type Error #16

Open aakashsur opened 4 years ago

aakashsur commented 4 years ago

When executing step 4 I get the following error:

Traceback (most recent call last):
  File "~/mhic/bin/KR_norm_mHiC.py", line 468, in <module>
    writeInteraction(norm_mtx, baseName, args.outdir, revFragsDic, args.chrNum, args.resolution)
  File "~/mhic/bin/KR_norm_mHiC.py", line 361, in writeInteraction
    matrixFile.write(("%s\t%d\t%s\t%d\t%.4f\n") % (chr1, mid1, chr2, mid2, values[i]))
TypeError: %d format: a number is required, not str

When I interrogate KR_norm_mHiC.py, it is trying to print the following:

LtaP_01 12500 LtaP_01 15500 3.3297406440638815

Where the type of each object is such:

<class 'str'> <class 'str'> <class 'str'> <class 'str'> <class 'numpy.float64'>

Clearly the bin coordinates are meant to be integers. I'm not sure why I would be running into this error, maybe a python version difference?

Also in regards to the string formatting, I think it is a bit more readable to use the Python 3 f-string formatting.

aakashsur commented 4 years ago

At any rate, adding some type conversion lines seems to do the trick. After

https://github.com/yezhengSTAT/mHiC/blob/ef8a240469e15ffe8b079c590e50ad72050491c9/bin/KR_norm_mHiC.py#L358

If we add:

mid1 = int(mid1)
mid2 = int(mid2)

the error resolves.