daler / pybedtools

Python wrapper -- and more -- for BEDTools (bioinformatics tools for "genome arithmetic")
http://daler.github.io/pybedtools
Other
297 stars 103 forks source link

Cannot create a BedTool object from list of regions that uses np.int64 coordinates #390

Closed aksarkar closed 11 months ago

aksarkar commented 1 year ago

The following minimal example raises an exception

mamba create -yqn test conda-forge::python=3.9 bioconda::pybedtools=0.9.0 conda-forge::numpy=1.19
## Preparing transaction: ...working... done
## Verifying transaction: ...working... done
## Executing transaction: ...working... done
conda run -n test python -c "import numpy as np, pybedtools; pybedtools.BedTool([['chr1', np.int64(1), np.int64(2)]])"
## Traceback (most recent call last):
##   File "<string>", line 1, in <module>
##   File "/home/ec2-user/mambaforge3/envs/test/lib/python3.9/site-packages/pybedtools/bedtool.py", line 589, in __init__
##     fn = BedTool(iter(fn)).saveas().fn
##   File "/home/ec2-user/mambaforge3/envs/test/lib/python3.9/site-packages/pybedtools/bedtool.py", line 923, in decorated
##     result = method(self, *args, **kwargs)
##   File "/home/ec2-user/mambaforge3/envs/test/lib/python3.9/site-packages/pybedtools/bedtool.py", line 3362, in saveas
##     fn = self._collapse(
##   File "/home/ec2-user/mambaforge3/envs/test/lib/python3.9/site-packages/pybedtools/bedtool.py", line 1422, in _collapse
##     for i in iterable:
##   File "pybedtools/cbedtools.pyx", line 793, in pybedtools.cbedtools.IntervalIterator.__next__
##   File "pybedtools/cbedtools.pyx", line 657, in pybedtools.cbedtools.create_interval_from_list
##   File "pybedtools/cbedtools.pyx", line 579, in pybedtools.cbedtools.isdigit
## AttributeError: 'numpy.int64' object has no attribute 'isdigit'
## 
## ERROR conda.cli.main_run:execute(47): `conda run python -c import numpy as np,pybedtools; pybedtools.BedTool([['chr1', np.int64(1), np.int64(2)]])` failed. (See above for error)

The reason appears to be that numpy integer types are not correctly handled https://github.com/daler/pybedtools/blob/master/pybedtools/cbedtools.pyx#L576

I ran into the same problem as #362 and I think this is the root cause.