pysam: How do I type an AlignedSegment in Cython?
0
0
Entering edit mode
4.0 years ago

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 • 1.4k views
0
Entering edit mode

However pysam works

How did you test it ?

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

0
Entering edit mode

I am able to run

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


and it works :)

0
Entering edit mode

Export LIBRARY_PATH before starting Jupyter.

0
Entering edit mode

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

0
Entering edit mode

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