daler / pybedtools

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

Inconsistent behaviour when using files from `pathlib.PosixPath` with BedTool functions... #405

Closed dbolser closed 5 months ago

dbolser commented 6 months ago

Hello!

First off, great library! Thank you!!!

I found that this works fine (as expected):

from pathlib import Path
dir = Path('MyBucketOfBEDs')
files = list(dir.glob('ENCFF*.bed.gz'))
x = pybedtools.BedTool(files[0])
type(x)
# <class 'pybedtools.bedtool.BedTool'>
x
# <BedTool(MyBucketOfBEDs/ENCFF159DMY.bed.gz)>
len(x)
# 55569
# etc...

However, this fails (which is unexpected):

c = x.cat(files[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/danbolser/Work/IUK1/.venv/lib/python3.10/site-packages/pybedtools/bedtool.py", line 909, in decorated
    result = method(self, *args, **kwargs)
  File "/home/danbolser/Work/IUK1/.venv/lib/python3.10/site-packages/pybedtools/bedtool.py", line 3224, in cat
    assert isinstance(
AssertionError: Either filename or another BedTool instance required

You can see the code here just checks if it's a string... https://github.com/daler/pybedtools/blob/9876fa25e80c7547101e662ebe1c6388579405d5/pybedtools/bedtool.py#L3220-L3227

I'm not 100% sure how to fix this, but I think os.PathLike is the way to go... Lemmy try, and if it works I'll submit a patch.