Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pysam dispatch call to samtools index does not accept '-M' parameter from documentation #1155

Closed
NatPRoach opened this issue Dec 30, 2022 · 1 comment

Comments

@NatPRoach
Copy link

NatPRoach commented Dec 30, 2022

package version
pysam 0.20.0

When running the usage function for pysam index in the python interpreter the parameter -M is listed as a way to get it to accept multiple files to index.

Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:27:35) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pysam
>>> print(pysam.index.usage())
Usage: samtools index -M [-bc] [-m INT] <in1.bam> <in2.bam>...
   or: samtools index [-bc] [-m INT] <in.bam> [out.index]
Options:
  -b       Generate BAI-format index for BAM files [default]
  -c       Generate CSI-format index for BAM files
  -m INT   Set minimum interval size for CSI indices to 2^INT [14]
  -M       Interpret all filename arguments as files to be indexed
  -o FILE  Write index to FILE [alternative to <out.index> as an argument]
  -@ INT   Sets the number of threads [none]

However attempting to run pysam with this parameter results in an error.

import pysam
from pathlib import Path
from fgpyo.sam.builder import SamBuilder

builder = SamBuilder()
builder.add_pair()
builder.add_pair()

example1 = Path("example1.bam")
builder.to_path(example1)
example2 = Path("example2.bam")
builder.to_path(example2)

pysam.index("-M", str(example1), str(example2))

Results in the following error:

Traceback (most recent call last):
  File "/Users/nproach/Documents/fulcrum_genomics/internal_repos/fgpyo/mre.py", line 14, in <module>
    pysam.index("-M", str(example1), str(example2))
  File "/Users/nproach/miniconda3/envs/fgpyo-test/lib/python3.10/site-packages/pysam/utils.py", line 56, in __call__
    retval, stderr, stdout = _pysam_dispatch(
  File "pysam/libcutils.pyx", line 323, in pysam.libcutils._pysam_dispatch
OSError: No such file or directory: '-M'
@jmarshall
Copy link
Member

Thanks for the report. Somewhat unfortunately, the Python code contains an additional option parser for the index subcommands, and that had not been updated to account for newer options added to samtools or bcftools. I've fixed this by simplifying the additional parser so that it doesn't need its own list of the simple options like -M.

This should now be fixed if you build your own pysam from the Git repository, and the fix will appear in the next pysam release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants