This is a test version of Biostars. For the public version, visit https://www.biostars.org.
pysam: How do I type an AlignedSegment in Cython?

I have the following code, where I want to type a:

for a in samfile:
    flag = a.flag
    is_reverse = flag & 0x10
    ....

It should have the type AlignedSegment from https://github.com/pysam-developers/pysam/blob/master/pysam/libcalignedsegment.pxd because that seems to be the type of a:

In [25]: a
Out[25]: <pysam.libcalignedsegment.AlignedSegment at 0x7f7fc5e53588>

When I use

from pysam.libcalignedsegment cimport AlignedSegment

I get the error

read_bam.cpp:618:28: fatal error: htslib/kstring.h: No such file or directory
compilation terminated.

I understand this means that it cannot find htslib when compiling. However pysam works so I guess it is me just cimporting pysam in the wrong way.

To be clear, I want to type a so I get no overhead:

 cdef AlignedSegment a

What do I import?

cython pysam

However pysam works

How did you test it ?

What is the command line and the output of your pysam installation ?

I am able to run

samfile = pysam.AlignmentFile("test.bam", "rb")
for a in samfile: print(a)

and it works :)

Export LIBRARY_PATH before starting Jupyter.

This is a problem when I try to compile a Cython project. echo $LIBRARY_PATH is empty, btw.

I know it's empty, you need to set it appropriately.

0 answers

No answers yet.

Log in to answer this question.