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

iterating on unnamed streams #1297

Open
cmdoret opened this issue Jul 9, 2024 · 0 comments
Open

iterating on unnamed streams #1297

cmdoret opened this issue Jul 9, 2024 · 0 comments

Comments

@cmdoret
Copy link

cmdoret commented Jul 9, 2024

Hello pysam devs

I would like to know whether pysam is the right tool for what I'd like to do:

tl;dr: I'd like to get an iterator of AlignmedSegments over an in-memory binary stream (no file, not stdio).

I'm streaming CRAM/BCF from an htsget server and wrote a client to lazily consume the binary stream. The client exposes it as a buffered read-only file object (io.RawIOBase) so that we can do:

with con.open() as stream:
    for chunk in stream:
        do_stuff(chunk) # : bytes

Now I wanted to make this stream easy to work with from python and thought I could just do pysam.AlignmentFile(stream), but it doesn't work because pysam requires that the input file is on disk, or has a file descriptor.

I found that this line in libcalignmentfile.pyx which indeed states this is not possible.
Is this a missing feature, or just out of scope for pysam (e.g. is there a fundamental reason why it is not possible), or maybe I'm just taking the wrong approach?

Any feedback or suggestions welcome :)

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

1 participant