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

Create methods and type stubs on pysam htslib C extension calls #22

Open
NatPRoach opened this issue Nov 30, 2022 · 4 comments · May be fixed by #26
Open

Create methods and type stubs on pysam htslib C extension calls #22

NatPRoach opened this issue Nov 30, 2022 · 4 comments · May be fixed by #26
Labels
enhancement New feature or request

Comments

@NatPRoach
Copy link
Contributor

NatPRoach commented Nov 30, 2022

It is often helpful to use pysam bindings to htslib functions a la

import pysam
pysam.sort(myfile, "-o", my_output)

etc.

mypy will complain when attempting to use these functions (presumably because they originate from a C extension module) with an error "AttributeError: module pysam has no attribute 'sort'"

I think it would behoove us to make wrapper functions around the pysam htslib calls with named parameters and type checking etc.
This will require generating stubs for the functions, e.g.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    def sort(*args: Any) -> None:
        pass
else:
    from pysam import sort

def sort_samfile( ... ) -> None:
    ... (some invocation that references `sort` ...
@NatPRoach NatPRoach added the enhancement New feature or request label Nov 30, 2022
@nh13
Copy link
Member

nh13 commented Dec 4, 2022

Why not solve it in pysam so everyone can benefit? pysam-developers/pysam#1153

@tfenne
Copy link
Member

tfenne commented Dec 5, 2022

Well, @nh13 part of the goal of this would be to provide a better interface that has the commonly used parameters to each of samtools' command line modules exposed as actual python parameters, so they are easier to use. E.g. instead of sort(*args: Any), we might want:

def sort(in_bam: Path, out_bam: Path, compress: int = 5, by_name: bool = False, threads: int = 1)

@nh13
Copy link
Member

nh13 commented Dec 5, 2022

That makes sense. My only hesitancy is that the interface is tied to a specific samtools version, so we’d have to pin the version and revisit the available options each time we update the samtools dependency. And then why not have it in pysam?

@NatPRoach
Copy link
Contributor Author

@nh13 @tfenne I have a draft PR for the first of the wrappers here, more to come. If we want to get them reviewed here and then use that to make a PR into pysam I am also fine with that. Would just need the heads up if that's what we want to do.

#26

@clintval clintval linked a pull request Nov 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants