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

pileup on streaming SAM records #915

Closed
winni2k opened this issue May 3, 2020 · 4 comments
Closed

pileup on streaming SAM records #915

winni2k opened this issue May 3, 2020 · 4 comments

Comments

@winni2k
Copy link

winni2k commented May 3, 2020

I have a use case where I want to implement a read-group-aware samtools mpileup on a file streamed from stdin or a UNIX file descriptor. I think this could be done with pysam's pileup engine, but my testing shows that pileup requires an indexed BAM. Is there an easy way to get the pileup to work on SAM/BAM records streamed from stdin? If we assume that the reads are position sorted, then this should be feasible, no?

@jmarshall
Copy link
Member

The samtools mpileup command works fine when reading SAM from stdin, so certainly the underlying HTSlib pileup engine works with such input.

What pysam code have you considered, and did it result in a “pileup of samfiles not implemented yet” exception?

@winni2k
Copy link
Author

winni2k commented May 3, 2020

Here is what I ran. test2.bam has no index. I am not asking for a particular region in pileup, so an index should not be necessary. Likewise, if I am pileing up from stdin, then an index won't be available either.

Is there another way to do this?

In [1]: import pysam

In [2]: f = pysam.AlignmentFile('test2.bam', 'rb')

In [3]: for r in f.pileup():
   ...:     r
   ...:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-387591687760> in <module>
----> 1 for r in f.pileup():
      2     r
      3

pysam/libcalignmentfile.pyx in pysam.libcalignmentfile.AlignmentFile.pileup()

ValueError: no index available for pileup

This is running pysam 0.15.3

@jmarshall
Copy link
Member

Try applying PR #916 and rebuilding pysam.

@winni2k
Copy link
Author

winni2k commented May 4, 2020

Nice! I'll have a go.

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