Currently, it seems like providing a pathlib.Path into biom.util.biom_open does not work.
Minimal Example
```python
import pathlib
import biom
tbl = biom.example_table
outfile_str = "./example_table.str.biom"
outfile_plib = pathlib.Path("./example_table.plib.biom")
# Works
with biom.util.biom_open(outfile_str, "w") as f:
tbl.to_hdf5(f, "str")
# Does not work
with biom.util.biom_open(outfile_plib, "w") as f:
tbl.to_hdf5(f, "plib")
```
Error:
Traceback (most recent call last):
File "code.py", line 14, in <module>
with biom.util.biom_open(outfile_plib, "w") as f:
File "/home/grahman/miniconda3/envs/st3/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/home/grahman/miniconda3/envs/st3/lib/python3.8/site-packages/biom/util.py", line 455, in biom_open
elif mode in ['w', 'wb'] and fp.endswith('.gz'):
AttributeError: 'PosixPath' object has no attribute 'endswith'
Seems like it currently uses str.endswith to look for compression which is causing an error as this method does not exist in the pathlib.Path class. Current workaround is coercing to str when passing the file handle but I'm pretty partial to using pathlib nowadays so if it's possible I think it'd be useful. Potentially easy solution is just doing that coercion in biom.util.open prior to calling endswith but I'm not sure if that will have any unintended consequences.
BIOM version 2.1.13
Currently, it seems like providing a
pathlib.Path
intobiom.util.biom_open
does not work.Minimal Example
```python import pathlib import biom tbl = biom.example_table outfile_str = "./example_table.str.biom" outfile_plib = pathlib.Path("./example_table.plib.biom") # Works with biom.util.biom_open(outfile_str, "w") as f: tbl.to_hdf5(f, "str") # Does not work with biom.util.biom_open(outfile_plib, "w") as f: tbl.to_hdf5(f, "plib") ```
Error:
Seems like it currently uses
str.endswith
to look for compression which is causing an error as this method does not exist in thepathlib.Path
class. Current workaround is coercing tostr
when passing the file handle but I'm pretty partial to usingpathlib
nowadays so if it's possible I think it'd be useful. Potentially easy solution is just doing that coercion inbiom.util.open
prior to callingendswith
but I'm not sure if that will have any unintended consequences.