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

Cannot pass argument to pybedtools.sort() #372

Closed mpj5142 closed 1 year ago

mpj5142 commented 2 years ago

Hello,

I am trying to sort my PyBedtools object using the -chrThenSizeA option present in Bedtools sort. However, I can't seem to find a way to pass this argument through to PyBedtools. I think this is because the option acts as a flag, and doesn't have any associated values (i.e. g=0).

If I try to pass just the option as-is:

>>> bedtool_sort=bedtool_subset.sort(chrThenSizeA)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'chrThenSizeA' is not defined

If I try to pass the argument as a string:

>>> bedtool_sort=bedtool_subset.sort("chrThenSizeA")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "conda_envs/test2/lib/python3.9/site-packages/pybedtools/bedtool.py", line 923, in decorated
    result = method(self, *args, **kwargs)
  File "conda_envs/test2/lib/python3.9/site-packages/pybedtools/bedtool.py", line 365, in wrapped
    cmds, tmp, stdin = self.handle_kwargs(prog=prog,
TypeError: keywords must be strings

If I try to pass a blank value along with the argument:

>>> bedtool_sort=bedtool_subset.sort(chrThenSizeA='')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "conda_envs/test2/lib/python3.9/site-packages/pybedtools/bedtool.py", line 923, in decorated
    result = method(self, *args, **kwargs)
  File "conda_envs/test2/lib/python3.9/site-packages/pybedtools/bedtool.py", line 402, in wrapped
    stream = call_bedtools(
  File "conda_envs/test2/lib/python3.9/site-packages/pybedtools/helpers.py", line 460, in call_bedtools
    raise BEDToolsError(subprocess.list2cmdline(cmds), stderr)
pybedtools.helpers.BEDToolsError:
Command was:

        bedtools sort -i /tmp/pybedtools.ypek0855.tmp -chrThenSizeA ""

Error message was:

*****ERROR: Unrecognized parameter:  *****

Do you have any advice for this issue? My BedTools version is v.2.30.0, and my PyBedtools version is 0.9.0.

Thank you very much!

daler commented 1 year ago

If this is still an issue (or at least, for future reference for other users), use chrThenSizeA=True. See this section of the docs for how arguments are translated.