This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in pysam: trying to read BAM file using CYTHON

I am trying to read BAM file using CYTHON via pysam but was not successful in doing so because of errors that are pasted below with code,

>>> pyximport.install()
(None, <pyximport.pyximport.PyxImporter object at 0x7fc5c0c12ba8>)
>>> import _pysam_flagstat
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named '_pysam_flagstat'
>>> from pysam.calignmentfile cimport AlignmentFile,AlignedSegment 
File "<stdin>", line 1
from pysam.calignmentfile cimport AlignmentFile,AlignedSegment 
                                ^
SyntaxError: invalid syntax
>>> import cython
>>> from pysam.calignmentfile cimport AlignmentFile,AlignedSegment 
 File "<stdin>", line 1
 from pysam.calignmentfile cimport AlignmentFile,AlignedSegment 
                                ^
SyntaxError: invalid syntax

I have installed pysam and cython correctly but don't now I am seeing this error. Is there any solution?

next-gen alignment pysam

1 answer

The cython stuff, such as cimport isn't really intended for use in interactive sessions, to me knowledge. That's all for writing modules, which it doesn't appear you're doing. Just use pysam in the normal python manner.

So you mean to say that cimport is not used for reading BAM files?

It's not directly used in python interactive sessions to do so. One instead does import pysam.

Log in to answer this question.