I'm trying to learn to use cython to speed up some code based on pysam. My issue is not strictly speaking about bioinformatics, but rather about building tools using a bioinformatics library. I hope this is still relevant in this site (I hesitated posting it as a github issue to pysam, alternatively, but I was not sure that this was a problem with pysam).
In my project's folder, the bam25prime/libbam25prime.pyx file has the following content:
# cython: language_level=3
from pysam.libchtslib cimport BAM_FREVERSE
from pysam.libcalignedsegment cimport AlignedSegment
cdef object ccollapse_ali(AlignedSegment ali):
"""
Return the bed information corresponding to the 5' collapse
of AlignedSegment *ali*.
"""
if (ali.flag & BAM_FREVERSE) != 0:
return "\t".join([
ali.reference_name,
# five prime position
str(ali.reference_end - 1),
str(ali.reference_end),
".",
".",
"-"])
else:
return "\t".join([
ali.reference_name,
# five prime position
str(ali.reference_start),
str(ali.reference_start + 1),
".",
".",
"+"])
def collapse_ali(ali):
"""
Return the bed information corresponding to the 5' collapse
of AlignedSegment *ali*.
"""
return ccollapse_ali(ali)
In my setup.py, the setup function is called with this argument:
ext_modules = cythonize("bam25prime/libbam25prime.pyx").
When I try to do the build (running python3.6 setup.py build_ext), cython seems to miss some include paths, because I get the following error:
[1/1] Cythonizing bam25prime/libbam25prime.pyx
running build_ext
building 'bam25prime.libbam25prime' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -O3 -march=native -fomit-frame-pointer -fPIC -I/home/bli/.local/lib/python3.6/site-packages/pysam -I${HOME}/include -I/home/bli/include/python3.6m -I/home/bli/.local/include -c bam25prime/libbam25prime.c -o build/temp.linux-x86_64-3.6/bam25prime/libbam25prime.o
bam25prime/libbam25prime.c:497:28: fatal error: htslib/kstring.h: No such file or directory
If I manually re-run the gcc command, adding -I/home/bli/.local/lib/python3.6/site-packages/pysam/include/htslib, the header file gets found.
How do I get cython to correctly determine the path to the necessary header files?
I guess another way to formulate the question would be the following: How is cython supposed to determine what include flags to use?
Or maybe there is a problem with my pysam installation?
If I remember well, I installed it using pip3.6 --user install pysam. I have a ~/.pydistutils.cfg file containing the following settings
[install]
optimize=1
[build_ext]
include_dirs=${HOME}/include
library_dirs=${HOME}/lib
rpath=${HOME}/lib
user=1
Any advice appreciated.
C_INCLUDE_PATH? That's usually sufficient. – Devon Ryan Aug 02 '18 at 17:57