/* Generated by Cython 0.13 on Mon Jan 31 00:58:16 2011 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif

#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif

#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif

#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif

#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif

#ifndef PySet_CheckExact
#  define PySet_CheckExact(obj)          (Py_TYPE(obj) == &PySet_Type)
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject PyLongObject
#endif


#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif

#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE_API__chimerascan__pysam__csamtools
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "ctype.h"
#include "unistd.h"
#include "razf.h"
#include "stdint.h"
#include "bam.h"
#include "sam.h"
#include "faidx.h"
#include "pysam_util.h"

/* inline attribute */
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE 
  #endif
#endif

/* unused attribute */
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__)) 
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || defined(__INTEL_COMPILER)
#   define CYTHON_UNUSED __attribute__ ((__unused__)) 
# else
#   define CYTHON_UNUSED 
# endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "csamtools.pyx",
};

/* Type declarations */

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1040
 *         samclose( self.fp )
 * 
 * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
 *     bamFile fp
 *     bam_iter_t iter
 */

typedef struct {
  bamFile fp;
  bam_iter_t iter;
} __pyx_t_11chimerascan_5pysam_9csamtools___iterdata;

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":56
 * ## private factory methods
 * #####################################################################
 * cdef class AlignedRead             # <<<<<<<<<<<<<<
 * cdef makeAlignedRead( bam1_t * src):
 *     '''enter src into AlignedRead.'''
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead {
  PyObject_HEAD
  bam1_t *_delegate;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":919
 * ## Thus I chose to rewrite the functions requiring callbacks. The downside is that if the samtools C-API or code
 * ## changes, the changes have to be manually entered.
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     """iterates over mapped reads in a region.
 * 
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow {
  PyObject_HEAD
  struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRow *__pyx_vtab;
  bam_iter_t iter;
  bam1_t *b;
  int retval;
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *samfile;
  samfile_t *fp;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":990
 *         samclose( self.fp )
 * 
 * cdef class IteratorRowAll:             # <<<<<<<<<<<<<<
 *     """iterates over all mapped reads
 *     """
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll {
  PyObject_HEAD
  struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRowAll *__pyx_vtab;
  bam1_t *b;
  samfile_t *fp;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":67
 *     return dest
 * 
 * cdef class PileupProxy             # <<<<<<<<<<<<<<
 * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):
 *      cdef PileupProxy dest
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy {
  PyObject_HEAD
  bam_pileup1_t *plp;
  int tid;
  int pos;
  int n_pu;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":77
 *      return dest
 * 
 * cdef class PileupRead             # <<<<<<<<<<<<<<
 * cdef makePileupRead( bam_pileup1_t * src ):
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead {
  PyObject_HEAD
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *_alignment;
  int32_t _qpos;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":217
 * ## Public methods
 * ######################################################################
 * cdef class Samfile:             # <<<<<<<<<<<<<<
 *     '''*(filename, mode='r', template = None, referencenames = None, referencelengths = None, text = NULL, header = None)*
 * 
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile {
  PyObject_HEAD
  struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_Samfile *__pyx_vtab;
  char *filename;
  samfile_t *samfile;
  bam_index_t *index;
  int isbam;
  int isremote;
  bam1_t *b;
  char *mode;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1049
 *     return bam_iter_read( d.fp, d.iter, b )
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 *     '''iterates over columns.
 * 
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *iter;
  int tid;
  int pos;
  int n_plp;
  bam_pileup1_t *plp;
  bam_plp_t pileup_iter;
  __pyx_t_11chimerascan_5pysam_9csamtools___iterdata iterdata;
};

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":806
 *             raise StopIteration
 * 
 * cdef class Fastafile:             # <<<<<<<<<<<<<<
 *     '''*(filename)*
 * 
 */

struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile {
  PyObject_HEAD
  char *filename;
  faidx_t *fastafile;
};


/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":217
 * ## Public methods
 * ######################################################################
 * cdef class Samfile:             # <<<<<<<<<<<<<<
 *     '''*(filename, mode='r', template = None, referencenames = None, referencelengths = None, text = NULL, header = None)*
 * 
 */

struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_Samfile {
  bam_header_t *(*_buildHeader)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *, PyObject *);
  bam1_t *(*getCurrent)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *);
  int (*cnext)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *);
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_Samfile *__pyx_vtabptr_11chimerascan_5pysam_9csamtools_Samfile;


/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":990
 *         samclose( self.fp )
 * 
 * cdef class IteratorRowAll:             # <<<<<<<<<<<<<<
 *     """iterates over all mapped reads
 *     """
 */

struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *);
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRowAll *__pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRowAll;


/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1049
 *     return bam_iter_read( d.fp, d.iter, b )
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 *     '''iterates over columns.
 * 
 */

struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorColumn {
  int (*cnext)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *);
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorColumn *__pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorColumn;


/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":919
 * ## Thus I chose to rewrite the functions requiring callbacks. The downside is that if the samtools C-API or code
 * ## changes, the changes have to be manually entered.
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     """iterates over mapped reads in a region.
 * 
 */

struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRow {
  bam1_t *(*getCurrent)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *);
  int (*cnext)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *);
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRow *__pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRow;

#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif

#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

#ifndef CYTHON_PROFILE
  #define CYTHON_PROFILE 1
#endif

#ifndef CYTHON_PROFILE_REUSE_FRAME
  #define CYTHON_PROFILE_REUSE_FRAME 0
#endif

#if CYTHON_PROFILE

  #include "compile.h"
  #include "frameobject.h"
  #include "traceback.h"

  #if CYTHON_PROFILE_REUSE_FRAME
    #define CYTHON_FRAME_MODIFIER static
    #define CYTHON_FRAME_DEL
  #else
    #define CYTHON_FRAME_MODIFIER
    #define CYTHON_FRAME_DEL Py_DECREF(__pyx_frame)
  #endif

  #define __Pyx_TraceDeclarations                                  \
  static PyCodeObject *__pyx_frame_code = NULL;                      \
  CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;           \
  int __Pyx_use_tracing = 0;                                                         

  #define __Pyx_TraceCall(funcname, srcfile, firstlineno)                            \
  if (unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc)) {      \
      __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, funcname, srcfile, firstlineno);  \
  }

  #define __Pyx_TraceException()                                                           \
  if (unlikely(__Pyx_use_tracing( && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \
      PyObject *exc_info = __Pyx_GetExceptionTuple();                                      \
      if (exc_info) {                                                                      \
          PyThreadState_GET()->c_profilefunc(                                              \
              PyThreadState_GET()->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);  \
          Py_DECREF(exc_info);                                                             \
      }                                                                                    \
  }

  #define __Pyx_TraceReturn(result)                                                  \
  if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \
      PyThreadState_GET()->c_profilefunc(                                            \
          PyThreadState_GET()->c_profileobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result);     \
      CYTHON_FRAME_DEL;                                                               \
  }

  static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
  static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, const char *funcname, const char *srcfile, int firstlineno); /*proto*/

#else

  #define __Pyx_TraceDeclarations
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno) 
  #define __Pyx_TraceException() 
  #define __Pyx_TraceReturn(result) 

#endif /* CYTHON_PROFILE */

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
static int __Pyx_EndUnpack(PyObject *, Py_ssize_t expected); /*proto*/

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict,
    const char* function_name, int kw_allowed); /*proto*/

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact); /*proto*/


static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
    }
    return r;
}

static CYTHON_INLINE long __Pyx_NegateNonNeg(long b) { return unlikely(b < 0) ? b : !b; }
static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
    return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
}

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (PyList_Append(L, x) < 0) return NULL;
        Py_INCREF(Py_None);
        return Py_None; /* this is just to have an accurate signature */
    }
    else {
        PyObject *r, *m;
        m = __Pyx_GetAttrString(L, "append");
        if (!m) return NULL;
        r = PyObject_CallFunctionObjArgs(m, x, NULL);
        Py_DECREF(m);
        return r;
    }
}

static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void);


#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    if (unlikely(d == Py_None)) {
        __Pyx_RaiseNoneIndexingError();
        return NULL;
    }
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred())
            PyErr_SetObject(PyExc_KeyError, key);
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#else
    #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#endif

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */

static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */

#define __Pyx_DelItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_DelItemInt_Fast(o, i) : \
                                                    __Pyx_DelItem_Generic(o, to_py_func(i)))

static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
    int r;
    if (!j) return -1;
    r = PyObject_DelItem(o, j);
    Py_DECREF(j);
    return r;
}

static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i) {
    if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && likely(i >= 0))
        return PySequence_DelItem(o, i);
    else {
        PyObject *j = PyInt_FromSsize_t(i);
        return __Pyx_DelItem_Generic(o, j);
    }
}

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, const char *modname); /*proto*/

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t);

static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject *);

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t);

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int64_t(int64_t);

static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject *);

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint8_t(uint8_t);

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

static CYTHON_INLINE uint64_t __Pyx_PyInt_from_py_uint64_t(PyObject *);

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from cpython.ref */

/* Module declarations from cpython.string */

/* Module declarations from python_string */

/* Module declarations from cpython.exc */

/* Module declarations from python_exc */

/* Module declarations from chimerascan.pysam.csamtools */

static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_AlignedRead = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_PileupProxy = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_PileupRead = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_Samfile = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_Fastafile = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorColumn = 0;
static PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(bam1_t *); /*proto*/
static PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_makePileupProxy(bam_pileup1_t *, int, int, int); /*proto*/
static PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_makePileupRead(bam_pileup1_t *); /*proto*/
static int __pyx_f_11chimerascan_5pysam_9csamtools_fetch_callback(bam1_t *, void *); /*proto*/
static int __pyx_f_11chimerascan_5pysam_9csamtools_pileup_callback(uint32_t, uint32_t, int, bam_pileup1_t *, void *); /*proto*/
static int __pyx_f_11chimerascan_5pysam_9csamtools_pileup_fetch_callback(bam1_t *, void *); /*proto*/
static int __pyx_f_11chimerascan_5pysam_9csamtools___advance(void *, bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_11chimerascan_5pysam_9csamtools_query_start(bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_11chimerascan_5pysam_9csamtools_query_end(bam1_t *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_get_seq_range(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_get_qual_range(bam1_t *, uint32_t, uint32_t); /*proto*/
#define __Pyx_MODULE_NAME "chimerascan.pysam.csamtools"
int __pyx_module_is_main_chimerascan__pysam__csamtools = 0;

/* Implementation of chimerascan.pysam.csamtools */
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_open;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_cmp;
static PyObject *__pyx_builtin_chr;
static char __pyx_k_1[] = "\t";
static char __pyx_k_2[] = "\n";
static char __pyx_k_3[] = "invalid file opening mode `%s`";
static char __pyx_k_4[] = "http:";
static char __pyx_k_5[] = "ftp:";
static char __pyx_k_6[] = "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing";
static char __pyx_k_7[] = "unequal names and lengths of reference sequences";
static char __pyx_k_8[] = "-";
static char __pyx_k_9[] = "file `%s` not found";
static char __pyx_k_10[] = "[bam_header_read] invalid BAM binary header (this is not a BAM file).\n";
static char __pyx_k_11[] = "invalid BAM binary header (is this a BAM file?)";
static char __pyx_k_12[] = "[samopen] no @SQ lines in the header.\n";
static char __pyx_k_13[] = "no @SQ lines in the header (is this a SAM file?)";
static char __pyx_k_14[] = "could not open file `%s`";
static char __pyx_k_15[] = ".bai";
static char __pyx_k_16[] = "error while opening index `%s` ";
static char __pyx_k_17[] = "I/O operation on closed file";
static char __pyx_k_18[] = "tid out of range 0<=tid<%i";
static char __pyx_k_19[] = "invalid region: start (%i) > end (%i)";
static char __pyx_k_20[] = "%s:%i-%i";
static char __pyx_k_21[] = "invalid region `%s`";
static char __pyx_k_22[] = "start out of range (%i)";
static char __pyx_k_23[] = "end out of range (%i)";
static char __pyx_k_24[] = "seek only available in bam files";
static char __pyx_k_26[] = "fetch called on bamfile without index";
static char __pyx_k_27[] = "callback functionality requires a region/reference";
static char __pyx_k_28[] = "no index available for fetch";
static char __pyx_k_29[] = "fetch called for samfile without header";
static char __pyx_k_30[] = "fetch for a region is not available for sam files";
static char __pyx_k_31[] = "callback not implemented yet";
static char __pyx_k_32[] = "no index available for pileup";
static char __pyx_k_33[] = "pileup of samfiles not implemented yet";
static char __pyx_k_34[] = "@";
static char __pyx_k_35[] = "header line without '@': '%s'";
static char __pyx_k_36[] = "header line with invalid type '%s': '%s'";
static char __pyx_k_37[] = ":";
static char __pyx_k_38[] = "unknown field code '%s' in record '%s'";
static char __pyx_k_39[] = "multiple '%s' lines are not permitted";
static char __pyx_k_40[] = "@%s";
static char __pyx_k_41[] = "%s:%s";
static char __pyx_k_42[] = "invalid type for record %s: %s, expected %s";
static char __pyx_k_43[] = "incomplete sequence information in '%s'";
static char __pyx_k_44[] = "calling len() on closed file";
static char __pyx_k_45[] = "no sequence/region supplied.";
static char __pyx_k_46[] = "";
static char __pyx_k_47[] = "error during iteration";
static char __pyx_k_48[] = "Invalid clipping in CIGAR string";
static char __pyx_k_49[] = "=ACMGRSVTWYHKDBN";
static char __pyx_k_50[] = "quality and sequence mismatch: %i != %i";
static char __pyx_k_51[] = "%c";
static char __pyx_k_52[] = "create_string_buffer";
static char __pyx_k_53[] = "<cccf";
static char __pyx_k_54[] = "<cccb";
static char __pyx_k_55[] = "<ccch";
static char __pyx_k_56[] = "integer %i out of range of BAM/SAM specification";
static char __pyx_k_57[] = "<ccci";
static char __pyx_k_58[] = "<cccB";
static char __pyx_k_59[] = "<cccH";
static char __pyx_k_60[] = "<cccI";
static char __pyx_k_61[] = "<cccc";
static char __pyx_k_62[] = "<ccc%is";
static char __pyx_k_63[] = "tags field too large";
static char __pyx_k_64[] = "tag '%s' not present";
static char __pyx_k_65[] = "Contig index";
static char __pyx_k_66[] = "Mapped position on contig";
static char __pyx_k_67[] = "Contig index for mate pair";
static char __pyx_k_68[] = "Position of mate pair";
static char __pyx_k_69[] = "Insert size";
static char __pyx_k_70[] = "Binary flag";
static char __pyx_k_71[] = "Count of cigar entries";
static char __pyx_k_72[] = "Cigar entries";
static char __pyx_k_73[] = "Mapping quality";
static char __pyx_k_74[] = "Bam index bin number";
static char __pyx_k_75[] = "Length of query name";
static char __pyx_k_76[] = "Query name";
static char __pyx_k_77[] = "Length of query sequence";
static char __pyx_k_78[] = "Query sequence";
static char __pyx_k_79[] = "Quality scores";
static char __pyx_k_80[] = "Length of auxilary data";
static char __pyx_k_81[] = "Maximum data length";
static char __pyx_k_82[] = "Current data length";
static char __pyx_k_83[] = "%-30s %-10s= %s";
static char __pyx_k_84[] = "(";
static char __pyx_k_85[] = ")";
static char __pyx_k_86[] = "-o";
static char __pyx_k_87[] = "option -o is forbidden in samtools view";
static char __pyx_k_88[] = "the query name (None if not present)";
static char __pyx_k_89[] = "the :term:`cigar` alignment (None if not present).\n        ";
static char __pyx_k_90[] = "read sequence bases, including :term:`soft clipped` bases (None if not present)";
static char __pyx_k_91[] = "read sequence base qualities, including :term:`soft clipped` bases (None if not present)";
static char __pyx_k_92[] = "aligned portion of the read and excludes any flanking bases that were :term:`soft clipped` (None if not present)\n\n        SAM/BAM files may included extra flanking bases sequences that were\n        not part of the alignment.  These bases may be the result of the\n        Smith-Waterman or other algorithms, which may not require alignments\n        that begin at the first residue or end at the last.  In addition,\n        extra sequencing adapters, multiplex identifiers, and low-quality bases that\n        were not considered for alignment may have been retained.";
static char __pyx_k_93[] = "aligned query sequence quality values (None if not present)";
static char __pyx_k_94[] = "start index of the aligned query portion of the sequence (0-based, inclusive)";
static char __pyx_k_95[] = "end index of the aligned query portion of the sequence (0-based, exclusive)";
static char __pyx_k_96[] = "Length of the aligned query sequence";
static char __pyx_k_97[] = "the tags in the AUX field.\n\n        This property permits convenience access to \n        the tags. Changes it the returned list will\n        not update the tags automatically. Instead,\n        the following is required for adding a \n        new tag::\n\n            read.tags = read.tags + [(\"RG\",0)]\n\n        ";
static char __pyx_k_98[] = "properties flag";
static char __pyx_k_99[] = "\n        :term:`target` ID\n\n        .. note::\n\n            This field contains the index of the reference sequence \n            in the sequence dictionary. To obtain the name\n            of the reference sequence, use :meth:`pysam.Samfile.getrname()`\n\n        ";
static char __pyx_k__A[] = "A";
static char __pyx_k__C[] = "C";
static char __pyx_k__I[] = "I";
static char __pyx_k__S[] = "S";
static char __pyx_k__Z[] = "Z";
static char __pyx_k__b[] = "b";
static char __pyx_k__c[] = "c";
static char __pyx_k__d[] = "d";
static char __pyx_k__f[] = "f";
static char __pyx_k__i[] = "i";
static char __pyx_k__n[] = "n";
static char __pyx_k__r[] = "r";
static char __pyx_k__s[] = "s";
static char __pyx_k__w[] = "w";
static char __pyx_k__x[] = "x";
static char __pyx_k_100[] = "0-based leftmost coordinate";
static char __pyx_k_101[] = "properties bin";
static char __pyx_k_102[] = "length of the read (read only). Returns 0 if not given.";
static char __pyx_k_103[] = "aligned end position of the read (read only).  Returns\n        None if not available.";
static char __pyx_k_104[] = "aligned length of the read (read only).  Returns None if\n        not available.";
static char __pyx_k_105[] = "mapping quality";
static char __pyx_k_106[] = "the :term:`reference` id of the mate ";
static char __pyx_k_107[] = "the position of the mate";
static char __pyx_k_108[] = "the insert size";
static char __pyx_k_109[] = "true if read is paired in sequencing";
static char __pyx_k_110[] = "true if read is mapped in a proper pair";
static char __pyx_k_111[] = "true if read itself is unmapped";
static char __pyx_k_112[] = "true if the mate is unmapped";
static char __pyx_k_113[] = "true if read is mapped to reverse strand";
static char __pyx_k_114[] = "true is read is mapped to reverse strand";
static char __pyx_k_115[] = "true if this is read1";
static char __pyx_k_116[] = "true if this is read2";
static char __pyx_k_117[] = "true if not primary alignment";
static char __pyx_k_118[] = "true if QC failure";
static char __pyx_k_119[] = " true if optical or PCR duplicate";
static char __pyx_k_120[] = "the chromosome ID as is defined in the header";
static char __pyx_k_121[] = "number of reads mapping to this column.";
static char __pyx_k_122[] = "list of reads (:class:`pysam.PileupRead`) aligned to this column";
static char __pyx_k_123[] = "a :class:`pysam.AlignedRead` object of the aligned read";
static char __pyx_k_124[] = "position of the read base at the pileup site, 0-based";
static char __pyx_k_125[] = "indel length; 0 for no indel, positive for ins and negative for del";
static char __pyx_k_126[] = "1 iff the base on the padded read is a deletion";
static char __pyx_k_127[] = "number of :term:`reference` sequences in the file.";
static char __pyx_k_128[] = "tuple with the names of :term:`reference` sequences.";
static char __pyx_k_129[] = "tuple of the lengths of the :term:`reference` sequences. The lengths are in the same order as :attr:`pysam.Samfile.reference`\n        ";
static char __pyx_k_130[] = "full contents of the :term:`sam file` header as a string.";
static char __pyx_k_131[] = "header information within the :term:`sam file`. The records and fields are returned as \n        a two-level dictionary.\n        ";
static char __pyx_k_132[] = "A pileup column. A pileup column contains  \n    all the reads that map to a certain target base.\n\n    tid      \n        chromosome ID as is defined in the header      \n    pos      \n        the target base coordinate (0-based)    \n    n \n        number of reads mapping to this column  \n    pileups  \n        list of reads (:class:`pysam.PileupRead`) aligned to this column    \n    ";
static char __pyx_k_133[] = "\n    stderr is captured. \n    ";
static char __pyx_k_134[] = "http://mail.python.org/pipermail/python-list/2000-June/038406.html";
static char __pyx_k_135[] = "Samfile._isOpen (line 271)";
static char __pyx_k_136[] = "Samfile._hasIndex (line 275)";
static char __pyx_k_137[] = "Samfile._open (line 279)";
static char __pyx_k_138[] = "Samfile.getrname (line 399)";
static char __pyx_k_139[] = "Samfile._parseRegion (line 407)";
static char __pyx_k_140[] = "Samfile.seek (line 453)";
static char __pyx_k_141[] = "Samfile.tell (line 462)";
static char __pyx_k_142[] = "Samfile.fetch (line 471)";
static char __pyx_k_143[] = "Samfile.pileup (line 550)";
static char __pyx_k_144[] = "Samfile.close (line 609)";
static char __pyx_k_145[] = "Samfile.write (line 623)";
static char __pyx_k_146[] = "Samfile._buildLine (line 715)";
static char __pyx_k_147[] = "Samfile.__next__ (line 794)";
static char __pyx_k_148[] = "Fastafile._isOpen (line 826)";
static char __pyx_k_149[] = "Fastafile._open (line 836)";
static char __pyx_k_150[] = "Fastafile.fetch (line 856)";
static char __pyx_k_151[] = "IteratorRow.__next__ (line 979)";
static char __pyx_k_152[] = "IteratorRowAll.__next__ (line 1024)";
static char __pyx_k_153[] = "IteratorColumn.__next__ (line 1105)";
static char __pyx_k_154[] = "AlignedRead.__str__ (line 1242)";
static char __pyx_k_155[] = "AlignedRead.compare (line 1255)";
static char __pyx_k_156[] = "AlignedRead.opt (line 1794)";
static char __pyx_k_157[] = "AlignedRead.fancy_str (line 1814)";
static char __pyx_k_158[] = "Outs.setdevice (line 1956)";
static char __pyx_k_159[] = "Outs.setfile (line 1961)";
static char __pyx_k_160[] = "Outs.restore (line 1973)";
static char __pyx_k_161[] = "_samtools_dispatch (line 1984)";
static char __pyx_k__AS[] = "AS";
static char __pyx_k__CL[] = "CL";
static char __pyx_k__CN[] = "CN";
static char __pyx_k__CO[] = "CO";
static char __pyx_k__DS[] = "DS";
static char __pyx_k__DT[] = "DT";
static char __pyx_k__GO[] = "GO";
static char __pyx_k__HD[] = "HD";
static char __pyx_k__ID[] = "ID";
static char __pyx_k__LB[] = "LB";
static char __pyx_k__LN[] = "LN";
static char __pyx_k__M5[] = "M5";
static char __pyx_k__PG[] = "PG";
static char __pyx_k__PI[] = "PI";
static char __pyx_k__PL[] = "PL";
static char __pyx_k__PU[] = "PU";
static char __pyx_k__RG[] = "RG";
static char __pyx_k__SM[] = "SM";
static char __pyx_k__SN[] = "SN";
static char __pyx_k__SO[] = "SO";
static char __pyx_k__SP[] = "SP";
static char __pyx_k__SQ[] = "SQ";
static char __pyx_k__UR[] = "UR";
static char __pyx_k__VN[] = "VN";
static char __pyx_k__fd[] = "fd";
static char __pyx_k__fp[] = "fp";
static char __pyx_k__id[] = "id";
static char __pyx_k__os[] = "os";
static char __pyx_k__rb[] = "rb";
static char __pyx_k__wb[] = "wb";
static char __pyx_k__wh[] = "wh";
static char __pyx_k__bam[] = "bam";
static char __pyx_k__beg[] = "beg";
static char __pyx_k__bin[] = "bin";
static char __pyx_k__chr[] = "chr";
static char __pyx_k__cmp[] = "cmp";
static char __pyx_k__dup[] = "dup";
static char __pyx_k__end[] = "end";
static char __pyx_k__map[] = "map";
static char __pyx_k__opt[] = "opt";
static char __pyx_k__plp[] = "plp";
static char __pyx_k__pos[] = "pos";
static char __pyx_k__raw[] = "raw";
static char __pyx_k__seq[] = "seq";
static char __pyx_k__sys[] = "sys";
static char __pyx_k__tid[] = "tid";
static char __pyx_k__wbu[] = "wbu";
static char __pyx_k__Outs[] = "Outs";
static char __pyx_k__args[] = "args";
static char __pyx_k__core[] = "core";
static char __pyx_k__data[] = "data";
static char __pyx_k__dup2[] = "dup2";
static char __pyx_k__flag[] = "flag";
static char __pyx_k__hash[] = "hash";
static char __pyx_k__iter[] = "iter";
static char __pyx_k__join[] = "join";
static char __pyx_k__mapq[] = "mapq";
static char __pyx_k__mode[] = "mode";
static char __pyx_k__mpos[] = "mpos";
static char __pyx_k__mtid[] = "mtid";
static char __pyx_k__n_pu[] = "n_pu";
static char __pyx_k__open[] = "open";
static char __pyx_k__path[] = "path";
static char __pyx_k__port[] = "port";
static char __pyx_k__qpos[] = "qpos";
static char __pyx_k__qseq[] = "qseq";
static char __pyx_k__qual[] = "qual";
static char __pyx_k__seek[] = "seek";
static char __pyx_k__self[] = "self";
static char __pyx_k__tags[] = "tags";
static char __pyx_k__tell[] = "tell";
static char __pyx_k__text[] = "text";
static char __pyx_k__view[] = "view";
static char __pyx_k___open[] = "_open";
static char __pyx_k___qpos[] = "_qpos";
static char __pyx_k__bqual[] = "bqual";
static char __pyx_k__chain[] = "chain";
static char __pyx_k__cigar[] = "cigar";
static char __pyx_k__close[] = "close";
static char __pyx_k__cnext[] = "cnext";
static char __pyx_k__fetch[] = "fetch";
static char __pyx_k__flush[] = "flush";
static char __pyx_k__indel[] = "indel";
static char __pyx_k__index[] = "index";
static char __pyx_k__isbam[] = "isbam";
static char __pyx_k__isize[] = "isize";
static char __pyx_k__l_aux[] = "l_aux";
static char __pyx_k__level[] = "level";
static char __pyx_k__n_plp[] = "n_plp";
static char __pyx_k__qname[] = "qname";
static char __pyx_k__rname[] = "rname";
static char __pyx_k__setfd[] = "setfd";
static char __pyx_k__split[] = "split";
static char __pyx_k__start[] = "start";
static char __pyx_k__strip[] = "strip";
static char __pyx_k__types[] = "types";
static char __pyx_k__where[] = "where";
static char __pyx_k__write[] = "write";
static char __pyx_k___indel[] = "_indel";
static char __pyx_k___level[] = "_level";
static char __pyx_k__ctypes[] = "ctypes";
static char __pyx_k__exists[] = "exists";
static char __pyx_k__fields[] = "fields";
static char __pyx_k__fileno[] = "fileno";
static char __pyx_k__header[] = "header";
static char __pyx_k__is_del[] = "is_del";
static char __pyx_k__l_qseq[] = "l_qseq";
static char __pyx_k__l_text[] = "l_text";
static char __pyx_k__m_data[] = "m_data";
static char __pyx_k__method[] = "method";
static char __pyx_k__object[] = "object";
static char __pyx_k__offset[] = "offset";
static char __pyx_k__pileup[] = "pileup";
static char __pyx_k__record[] = "record";
static char __pyx_k__region[] = "region";
static char __pyx_k__remove[] = "remove";
static char __pyx_k__retval[] = "retval";
static char __pyx_k__rg2lib[] = "rg2lib";
static char __pyx_k__stderr[] = "stderr";
static char __pyx_k__stdout[] = "stdout";
static char __pyx_k__struct[] = "struct";
static char __pyx_k__IOError[] = "IOError";
static char __pyx_k__IntType[] = "IntType";
static char __pyx_k__O_CREAT[] = "O_CREAT";
static char __pyx_k__Samfile[] = "Samfile";
static char __pyx_k____all__[] = "__all__";
static char __pyx_k____del__[] = "__del__";
static char __pyx_k____str__[] = "__str__";
static char __pyx_k___isOpen[] = "_isOpen";
static char __pyx_k___is_del[] = "_is_del";
static char __pyx_k__compare[] = "compare";
static char __pyx_k__is_head[] = "is_head";
static char __pyx_k__is_tail[] = "is_tail";
static char __pyx_k__l_qname[] = "l_qname";
static char __pyx_k__mkstemp[] = "mkstemp";
static char __pyx_k__n_cigar[] = "n_cigar";
static char __pyx_k__pileups[] = "pileups";
static char __pyx_k__release[] = "release";
static char __pyx_k__restore[] = "restore";
static char __pyx_k__samfile[] = "samfile";
static char __pyx_k__setfile[] = "setfile";
static char __pyx_k__streams[] = "streams";
static char __pyx_k__DictType[] = "DictType";
static char __pyx_k__KeyError[] = "KeyError";
static char __pyx_k__O_WRONLY[] = "O_WRONLY";
static char __pyx_k____dict__[] = "__dict__";
static char __pyx_k____init__[] = "__init__";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____next__[] = "__next__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k___is_head[] = "_is_head";
static char __pyx_k___is_tail[] = "_is_tail";
static char __pyx_k__calcsize[] = "calcsize";
static char __pyx_k__callback[] = "callback";
static char __pyx_k__data_len[] = "data_len";
static char __pyx_k__exc_type[] = "exc_type";
static char __pyx_k__filename[] = "filename";
static char __pyx_k__getrname[] = "getrname";
static char __pyx_k__isremote[] = "isremote";
static char __pyx_k__iterdata[] = "iterdata";
static char __pyx_k__samtools[] = "samtools";
static char __pyx_k__stderr_f[] = "stderr_f";
static char __pyx_k__stderr_h[] = "stderr_h";
static char __pyx_k__tempfile[] = "tempfile";
static char __pyx_k__template[] = "template";
static char __pyx_k__Fastafile[] = "Fastafile";
static char __pyx_k__FloatType[] = "FloatType";
static char __pyx_k___delegate[] = "_delegate";
static char __pyx_k___hasIndex[] = "_hasIndex";
static char __pyx_k__alignment[] = "alignment";
static char __pyx_k__exc_value[] = "exc_value";
static char __pyx_k__fancy_str[] = "fancy_str";
static char __pyx_k__fastafile[] = "fastafile";
static char __pyx_k__itertools[] = "itertools";
static char __pyx_k__n_targets[] = "n_targets";
static char __pyx_k__pack_into[] = "pack_into";
static char __pyx_k__readlines[] = "readlines";
static char __pyx_k__reference[] = "reference";
static char __pyx_k__setdevice[] = "setdevice";
static char __pyx_k__traceback[] = "traceback";
static char __pyx_k__until_eof[] = "until_eof";
static char __pyx_k__PileupRead[] = "PileupRead";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k___alignment[] = "_alignment";
static char __pyx_k___buildLine[] = "_buildLine";
static char __pyx_k__startswith[] = "startswith";
static char __pyx_k__target_len[] = "target_len";
static char __pyx_k__AlignedRead[] = "AlignedRead";
static char __pyx_k__IteratorRow[] = "IteratorRow";
static char __pyx_k__PileupProxy[] = "PileupProxy";
static char __pyx_k__StderrStore[] = "StderrStore";
static char __pyx_k__nreferences[] = "nreferences";
static char __pyx_k__pileup_iter[] = "pileup_iter";
static char __pyx_k__stderr_save[] = "stderr_save";
static char __pyx_k__target_name[] = "target_name";
static char __pyx_k__PileupColumn[] = "PileupColumn";
static char __pyx_k___buildHeader[] = "_buildHeader";
static char __pyx_k___parseRegion[] = "_parseRegion";
static char __pyx_k__StopIteration[] = "StopIteration";
static char __pyx_k__VALID_HEADERS[] = "VALID_HEADERS";
static char __pyx_k__IteratorColumn[] = "IteratorColumn";
static char __pyx_k__IteratorRowAll[] = "IteratorRowAll";
static char __pyx_k__readAndRelease[] = "readAndRelease";
static char __pyx_k__referencenames[] = "referencenames";
static char __pyx_k____getattribute__[] = "__getattribute__";
static char __pyx_k__referencelengths[] = "referencelengths";
static char __pyx_k__VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
static char __pyx_k__VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
static char __pyx_k___samtools_dispatch[] = "_samtools_dispatch";
static char __pyx_k__NotImplementedError[] = "NotImplementedError";
static char __pyx_k__VALID_HEADER_FIELDS[] = "VALID_HEADER_FIELDS";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_12;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_132;
static PyObject *__pyx_kp_s_133;
static PyObject *__pyx_kp_s_134;
static PyObject *__pyx_kp_u_135;
static PyObject *__pyx_kp_u_136;
static PyObject *__pyx_kp_u_137;
static PyObject *__pyx_kp_u_138;
static PyObject *__pyx_kp_u_139;
static PyObject *__pyx_kp_s_14;
static PyObject *__pyx_kp_u_140;
static PyObject *__pyx_kp_u_141;
static PyObject *__pyx_kp_u_142;
static PyObject *__pyx_kp_u_143;
static PyObject *__pyx_kp_u_144;
static PyObject *__pyx_kp_u_145;
static PyObject *__pyx_kp_u_146;
static PyObject *__pyx_kp_u_147;
static PyObject *__pyx_kp_u_148;
static PyObject *__pyx_kp_u_149;
static PyObject *__pyx_kp_s_15;
static PyObject *__pyx_kp_u_150;
static PyObject *__pyx_kp_u_151;
static PyObject *__pyx_kp_u_152;
static PyObject *__pyx_kp_u_153;
static PyObject *__pyx_kp_u_154;
static PyObject *__pyx_kp_u_155;
static PyObject *__pyx_kp_u_156;
static PyObject *__pyx_kp_u_157;
static PyObject *__pyx_kp_u_158;
static PyObject *__pyx_kp_u_159;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_kp_u_160;
static PyObject *__pyx_kp_u_161;
static PyObject *__pyx_kp_s_17;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_s_19;
static PyObject *__pyx_kp_s_2;
static PyObject *__pyx_kp_s_20;
static PyObject *__pyx_kp_s_21;
static PyObject *__pyx_kp_s_22;
static PyObject *__pyx_kp_s_23;
static PyObject *__pyx_kp_s_24;
static PyObject *__pyx_kp_s_26;
static PyObject *__pyx_kp_s_27;
static PyObject *__pyx_kp_s_28;
static PyObject *__pyx_kp_s_29;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_s_30;
static PyObject *__pyx_kp_s_31;
static PyObject *__pyx_kp_s_32;
static PyObject *__pyx_kp_s_33;
static PyObject *__pyx_kp_s_34;
static PyObject *__pyx_kp_s_35;
static PyObject *__pyx_kp_s_36;
static PyObject *__pyx_kp_s_37;
static PyObject *__pyx_kp_s_38;
static PyObject *__pyx_kp_s_39;
static PyObject *__pyx_kp_s_40;
static PyObject *__pyx_kp_s_41;
static PyObject *__pyx_kp_s_42;
static PyObject *__pyx_kp_s_43;
static PyObject *__pyx_kp_s_44;
static PyObject *__pyx_kp_s_45;
static PyObject *__pyx_kp_s_46;
static PyObject *__pyx_kp_s_47;
static PyObject *__pyx_kp_s_50;
static PyObject *__pyx_kp_s_51;
static PyObject *__pyx_n_s_52;
static PyObject *__pyx_kp_s_53;
static PyObject *__pyx_kp_s_54;
static PyObject *__pyx_kp_s_55;
static PyObject *__pyx_kp_s_56;
static PyObject *__pyx_kp_s_57;
static PyObject *__pyx_kp_s_58;
static PyObject *__pyx_kp_s_59;
static PyObject *__pyx_kp_s_6;
static PyObject *__pyx_kp_s_60;
static PyObject *__pyx_kp_s_61;
static PyObject *__pyx_kp_s_62;
static PyObject *__pyx_kp_s_63;
static PyObject *__pyx_kp_s_64;
static PyObject *__pyx_kp_s_65;
static PyObject *__pyx_kp_s_66;
static PyObject *__pyx_kp_s_67;
static PyObject *__pyx_kp_s_68;
static PyObject *__pyx_kp_s_69;
static PyObject *__pyx_kp_s_7;
static PyObject *__pyx_kp_s_70;
static PyObject *__pyx_kp_s_71;
static PyObject *__pyx_kp_s_72;
static PyObject *__pyx_kp_s_73;
static PyObject *__pyx_kp_s_74;
static PyObject *__pyx_kp_s_75;
static PyObject *__pyx_kp_s_76;
static PyObject *__pyx_kp_s_77;
static PyObject *__pyx_kp_s_78;
static PyObject *__pyx_kp_s_79;
static PyObject *__pyx_kp_s_80;
static PyObject *__pyx_kp_s_81;
static PyObject *__pyx_kp_s_82;
static PyObject *__pyx_kp_s_83;
static PyObject *__pyx_kp_s_84;
static PyObject *__pyx_kp_s_85;
static PyObject *__pyx_kp_s_86;
static PyObject *__pyx_kp_s_87;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_n_s__A;
static PyObject *__pyx_n_s__AS;
static PyObject *__pyx_n_s__AlignedRead;
static PyObject *__pyx_n_s__C;
static PyObject *__pyx_n_s__CL;
static PyObject *__pyx_n_s__CN;
static PyObject *__pyx_n_s__CO;
static PyObject *__pyx_n_s__DS;
static PyObject *__pyx_n_s__DT;
static PyObject *__pyx_n_s__DictType;
static PyObject *__pyx_n_s__Fastafile;
static PyObject *__pyx_n_s__FloatType;
static PyObject *__pyx_n_s__GO;
static PyObject *__pyx_n_s__HD;
static PyObject *__pyx_n_s__I;
static PyObject *__pyx_n_s__ID;
static PyObject *__pyx_n_s__IOError;
static PyObject *__pyx_n_s__IntType;
static PyObject *__pyx_n_s__IteratorColumn;
static PyObject *__pyx_n_s__IteratorRow;
static PyObject *__pyx_n_s__IteratorRowAll;
static PyObject *__pyx_n_s__KeyError;
static PyObject *__pyx_n_s__LB;
static PyObject *__pyx_n_s__LN;
static PyObject *__pyx_n_s__M5;
static PyObject *__pyx_n_s__NotImplementedError;
static PyObject *__pyx_n_s__O_CREAT;
static PyObject *__pyx_n_s__O_WRONLY;
static PyObject *__pyx_n_s__Outs;
static PyObject *__pyx_n_s__PG;
static PyObject *__pyx_n_s__PI;
static PyObject *__pyx_n_s__PL;
static PyObject *__pyx_n_s__PU;
static PyObject *__pyx_n_s__PileupColumn;
static PyObject *__pyx_n_s__PileupProxy;
static PyObject *__pyx_n_s__PileupRead;
static PyObject *__pyx_n_s__RG;
static PyObject *__pyx_n_s__S;
static PyObject *__pyx_n_s__SM;
static PyObject *__pyx_n_s__SN;
static PyObject *__pyx_n_s__SO;
static PyObject *__pyx_n_s__SP;
static PyObject *__pyx_n_s__SQ;
static PyObject *__pyx_n_s__Samfile;
static PyObject *__pyx_n_s__StderrStore;
static PyObject *__pyx_n_s__StopIteration;
static PyObject *__pyx_n_s__UR;
static PyObject *__pyx_n_s__VALID_HEADERS;
static PyObject *__pyx_n_s__VALID_HEADER_FIELDS;
static PyObject *__pyx_n_s__VALID_HEADER_ORDER;
static PyObject *__pyx_n_s__VALID_HEADER_TYPES;
static PyObject *__pyx_n_s__VN;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s__Z;
static PyObject *__pyx_n_s____all__;
static PyObject *__pyx_n_s____del__;
static PyObject *__pyx_n_s____dict__;
static PyObject *__pyx_n_s____getattribute__;
static PyObject *__pyx_n_s____init__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____next__;
static PyObject *__pyx_n_s____str__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___alignment;
static PyObject *__pyx_n_s___buildHeader;
static PyObject *__pyx_n_s___buildLine;
static PyObject *__pyx_n_s___delegate;
static PyObject *__pyx_n_s___hasIndex;
static PyObject *__pyx_n_s___indel;
static PyObject *__pyx_n_s___isOpen;
static PyObject *__pyx_n_s___is_del;
static PyObject *__pyx_n_s___is_head;
static PyObject *__pyx_n_s___is_tail;
static PyObject *__pyx_n_s___level;
static PyObject *__pyx_n_s___open;
static PyObject *__pyx_n_s___parseRegion;
static PyObject *__pyx_n_s___qpos;
static PyObject *__pyx_n_s___samtools_dispatch;
static PyObject *__pyx_n_s__alignment;
static PyObject *__pyx_n_s__args;
static PyObject *__pyx_n_s__b;
static PyObject *__pyx_n_s__bam;
static PyObject *__pyx_n_s__beg;
static PyObject *__pyx_n_s__bin;
static PyObject *__pyx_n_s__bqual;
static PyObject *__pyx_n_s__c;
static PyObject *__pyx_n_s__calcsize;
static PyObject *__pyx_n_s__callback;
static PyObject *__pyx_n_s__chain;
static PyObject *__pyx_n_s__chr;
static PyObject *__pyx_n_s__cigar;
static PyObject *__pyx_n_s__close;
static PyObject *__pyx_n_s__cmp;
static PyObject *__pyx_n_s__cnext;
static PyObject *__pyx_n_s__compare;
static PyObject *__pyx_n_s__core;
static PyObject *__pyx_n_s__ctypes;
static PyObject *__pyx_n_s__d;
static PyObject *__pyx_n_s__data;
static PyObject *__pyx_n_s__data_len;
static PyObject *__pyx_n_s__dup;
static PyObject *__pyx_n_s__dup2;
static PyObject *__pyx_n_s__end;
static PyObject *__pyx_n_s__exc_type;
static PyObject *__pyx_n_s__exc_value;
static PyObject *__pyx_n_s__exists;
static PyObject *__pyx_n_s__f;
static PyObject *__pyx_n_s__fancy_str;
static PyObject *__pyx_n_s__fastafile;
static PyObject *__pyx_n_s__fd;
static PyObject *__pyx_n_s__fetch;
static PyObject *__pyx_n_s__fields;
static PyObject *__pyx_n_s__filename;
static PyObject *__pyx_n_s__fileno;
static PyObject *__pyx_n_s__flag;
static PyObject *__pyx_n_s__flush;
static PyObject *__pyx_n_s__fp;
static PyObject *__pyx_n_s__getrname;
static PyObject *__pyx_n_s__hash;
static PyObject *__pyx_n_s__header;
static PyObject *__pyx_n_s__i;
static PyObject *__pyx_n_s__id;
static PyObject *__pyx_n_s__indel;
static PyObject *__pyx_n_s__index;
static PyObject *__pyx_n_s__is_del;
static PyObject *__pyx_n_s__is_head;
static PyObject *__pyx_n_s__is_tail;
static PyObject *__pyx_n_s__isbam;
static PyObject *__pyx_n_s__isize;
static PyObject *__pyx_n_s__isremote;
static PyObject *__pyx_n_s__iter;
static PyObject *__pyx_n_s__iterdata;
static PyObject *__pyx_n_s__itertools;
static PyObject *__pyx_n_s__join;
static PyObject *__pyx_n_s__l_aux;
static PyObject *__pyx_n_s__l_qname;
static PyObject *__pyx_n_s__l_qseq;
static PyObject *__pyx_n_s__l_text;
static PyObject *__pyx_n_s__level;
static PyObject *__pyx_n_s__m_data;
static PyObject *__pyx_n_s__map;
static PyObject *__pyx_n_s__mapq;
static PyObject *__pyx_n_s__method;
static PyObject *__pyx_n_s__mkstemp;
static PyObject *__pyx_n_s__mode;
static PyObject *__pyx_n_s__mpos;
static PyObject *__pyx_n_s__mtid;
static PyObject *__pyx_n_s__n;
static PyObject *__pyx_n_s__n_cigar;
static PyObject *__pyx_n_s__n_plp;
static PyObject *__pyx_n_s__n_pu;
static PyObject *__pyx_n_s__n_targets;
static PyObject *__pyx_n_s__nreferences;
static PyObject *__pyx_n_s__object;
static PyObject *__pyx_n_s__offset;
static PyObject *__pyx_n_s__open;
static PyObject *__pyx_n_s__opt;
static PyObject *__pyx_n_s__os;
static PyObject *__pyx_n_s__pack_into;
static PyObject *__pyx_n_s__path;
static PyObject *__pyx_n_s__pileup;
static PyObject *__pyx_n_s__pileup_iter;
static PyObject *__pyx_n_s__pileups;
static PyObject *__pyx_n_s__plp;
static PyObject *__pyx_n_s__port;
static PyObject *__pyx_n_s__pos;
static PyObject *__pyx_n_s__qname;
static PyObject *__pyx_n_s__qpos;
static PyObject *__pyx_n_s__qseq;
static PyObject *__pyx_n_s__qual;
static PyObject *__pyx_n_s__r;
static PyObject *__pyx_n_s__raw;
static PyObject *__pyx_n_s__rb;
static PyObject *__pyx_n_s__readAndRelease;
static PyObject *__pyx_n_s__readlines;
static PyObject *__pyx_n_s__record;
static PyObject *__pyx_n_s__reference;
static PyObject *__pyx_n_s__referencelengths;
static PyObject *__pyx_n_s__referencenames;
static PyObject *__pyx_n_s__region;
static PyObject *__pyx_n_s__release;
static PyObject *__pyx_n_s__remove;
static PyObject *__pyx_n_s__restore;
static PyObject *__pyx_n_s__retval;
static PyObject *__pyx_n_s__rg2lib;
static PyObject *__pyx_n_s__rname;
static PyObject *__pyx_n_s__s;
static PyObject *__pyx_n_s__samfile;
static PyObject *__pyx_n_s__seek;
static PyObject *__pyx_n_s__self;
static PyObject *__pyx_n_s__seq;
static PyObject *__pyx_n_s__setdevice;
static PyObject *__pyx_n_s__setfd;
static PyObject *__pyx_n_s__setfile;
static PyObject *__pyx_n_s__split;
static PyObject *__pyx_n_s__start;
static PyObject *__pyx_n_s__startswith;
static PyObject *__pyx_n_s__stderr;
static PyObject *__pyx_n_s__stderr_f;
static PyObject *__pyx_n_s__stderr_h;
static PyObject *__pyx_n_s__stderr_save;
static PyObject *__pyx_n_s__stdout;
static PyObject *__pyx_n_s__streams;
static PyObject *__pyx_n_s__strip;
static PyObject *__pyx_n_s__struct;
static PyObject *__pyx_n_s__sys;
static PyObject *__pyx_n_s__tags;
static PyObject *__pyx_n_s__target_len;
static PyObject *__pyx_n_s__target_name;
static PyObject *__pyx_n_s__tell;
static PyObject *__pyx_n_s__tempfile;
static PyObject *__pyx_n_s__template;
static PyObject *__pyx_n_s__text;
static PyObject *__pyx_n_s__tid;
static PyObject *__pyx_n_s__traceback;
static PyObject *__pyx_n_s__types;
static PyObject *__pyx_n_s__until_eof;
static PyObject *__pyx_n_s__view;
static PyObject *__pyx_n_s__w;
static PyObject *__pyx_n_s__wb;
static PyObject *__pyx_n_s__wbu;
static PyObject *__pyx_n_s__wh;
static PyObject *__pyx_n_s__where;
static PyObject *__pyx_n_s__write;
static PyObject *__pyx_n_s__x;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_8;
static PyObject *__pyx_int_16;
static PyObject *__pyx_int_32;
static PyObject *__pyx_int_64;
static PyObject *__pyx_int_128;
static PyObject *__pyx_int_255;
static PyObject *__pyx_int_256;
static PyObject *__pyx_int_512;
static PyObject *__pyx_int_neg_127;
static PyObject *__pyx_int_0660;
static PyObject *__pyx_int_1024;
static PyObject *__pyx_int_65535;
static PyObject *__pyx_int_neg_32767;
static PyObject *__pyx_int_4294967295;
static PyObject *__pyx_int_neg_2147483648;
static PyObject *__pyx_k_25;

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":57
 * #####################################################################
 * cdef class AlignedRead
 * cdef makeAlignedRead( bam1_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedRead.'''
 *     cdef AlignedRead dest
 */

static  PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(bam1_t *__pyx_v_src) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *__pyx_v_dest;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("makeAlignedRead");
  __Pyx_TraceCall("makeAlignedRead", __pyx_f[0], 57);
  __pyx_v_dest = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":60
 *     '''enter src into AlignedRead.'''
 *     cdef AlignedRead dest
 *     dest = AlignedRead()             # <<<<<<<<<<<<<<
 *     # destroy dummy delegate created in constructor
 *     # to prevent memory leak.
 */
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_AlignedRead)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest));
  __pyx_v_dest = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":63
 *     # destroy dummy delegate created in constructor
 *     # to prevent memory leak.
 *     bam_destroy1(dest._delegate)             # <<<<<<<<<<<<<<
 *     dest._delegate = bam_dup1(src)
 *     return dest
 */
  bam_destroy1(__pyx_v_dest->_delegate);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":64
 *     # to prevent memory leak.
 *     bam_destroy1(dest._delegate)
 *     dest._delegate = bam_dup1(src)             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":65
 *     bam_destroy1(dest._delegate)
 *     dest._delegate = bam_dup1(src)
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupProxy
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.makeAlignedRead");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":68
 * 
 * cdef class PileupProxy
 * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):             # <<<<<<<<<<<<<<
 *      cdef PileupProxy dest
 *      dest = PileupProxy()
 */

static  PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_makePileupProxy(bam_pileup1_t *__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *__pyx_v_dest;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("makePileupProxy");
  __Pyx_TraceCall("makePileupProxy", __pyx_f[0], 68);
  __pyx_v_dest = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":70
 * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):
 *      cdef PileupProxy dest
 *      dest = PileupProxy()             # <<<<<<<<<<<<<<
 *      dest.plp = plp
 *      dest.tid = tid
 */
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_PileupProxy)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest));
  __pyx_v_dest = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":71
 *      cdef PileupProxy dest
 *      dest = PileupProxy()
 *      dest.plp = plp             # <<<<<<<<<<<<<<
 *      dest.tid = tid
 *      dest.pos = pos
 */
  __pyx_v_dest->plp = __pyx_v_plp;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":72
 *      dest = PileupProxy()
 *      dest.plp = plp
 *      dest.tid = tid             # <<<<<<<<<<<<<<
 *      dest.pos = pos
 *      dest.n = n
 */
  __pyx_v_dest->tid = __pyx_v_tid;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":73
 *      dest.plp = plp
 *      dest.tid = tid
 *      dest.pos = pos             # <<<<<<<<<<<<<<
 *      dest.n = n
 *      return dest
 */
  __pyx_v_dest->pos = __pyx_v_pos;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":74
 *      dest.tid = tid
 *      dest.pos = pos
 *      dest.n = n             # <<<<<<<<<<<<<<
 *      return dest
 * 
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(((PyObject *)__pyx_v_dest), __pyx_n_s__n, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":75
 *      dest.pos = pos
 *      dest.n = n
 *      return dest             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupRead
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.makePileupProxy");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":78
 * 
 * cdef class PileupRead
 * cdef makePileupRead( bam_pileup1_t * src ):             # <<<<<<<<<<<<<<
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest
 */

static  PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v_src) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *__pyx_v_dest;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("makePileupRead");
  __Pyx_TraceCall("makePileupRead", __pyx_f[0], 78);
  __pyx_v_dest = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":81
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest
 *     dest = PileupRead()             # <<<<<<<<<<<<<<
 *     dest._alignment = makeAlignedRead( src.b )
 *     dest._qpos = src.qpos
 */
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_PileupRead)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest));
  __pyx_v_dest = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":82
 *     cdef PileupRead dest
 *     dest = PileupRead()
 *     dest._alignment = makeAlignedRead( src.b )             # <<<<<<<<<<<<<<
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 */
  __pyx_t_1 = __pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(__pyx_v_src->b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_11chimerascan_5pysam_9csamtools_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_dest->_alignment);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment));
  __pyx_v_dest->_alignment = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":83
 *     dest = PileupRead()
 *     dest._alignment = makeAlignedRead( src.b )
 *     dest._qpos = src.qpos             # <<<<<<<<<<<<<<
 *     dest._indel = src.indel
 *     dest._level = src.level
 */
  __pyx_v_dest->_qpos = __pyx_v_src->qpos;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":84
 *     dest._alignment = makeAlignedRead( src.b )
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel             # <<<<<<<<<<<<<<
 *     dest._level = src.level
 *     dest._is_del = src.is_del
 */
  __pyx_v_dest->_indel = __pyx_v_src->indel;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":85
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 *     dest._level = src.level             # <<<<<<<<<<<<<<
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head
 */
  __pyx_v_dest->_level = __pyx_v_src->level;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":86
 *     dest._indel = src.indel
 *     dest._level = src.level
 *     dest._is_del = src.is_del             # <<<<<<<<<<<<<<
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 */
  __pyx_v_dest->_is_del = __pyx_v_src->is_del;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":87
 *     dest._level = src.level
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head             # <<<<<<<<<<<<<<
 *     dest._is_tail = src.is_tail
 *     return dest
 */
  __pyx_v_dest->_is_head = __pyx_v_src->is_head;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":88
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_v_dest->_is_tail = __pyx_v_src->is_tail;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":89
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.makePileupRead");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":96
 * ## Generic callbacks for inserting python callbacks.
 * #####################################################################
 * cdef int fetch_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
 *     '''callback for bam_fetch.
 * 
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_fetch_callback(bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
  PyObject *__pyx_v_a;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("fetch_callback");
  __Pyx_TraceCall("fetch_callback", __pyx_f[0], 96);
  __pyx_v_a = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":101
 *     calls function in *f* with a new :class:`AlignedRead` object as parameter.
 *     '''
 *     a = makeAlignedRead( alignment )             # <<<<<<<<<<<<<<
 *     (<object>f)(a)
 * 
 */
  __pyx_t_1 = __pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(__pyx_v_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v_a);
  __pyx_v_a = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":102
 *     '''
 *     a = makeAlignedRead( alignment )
 *     (<object>f)(a)             # <<<<<<<<<<<<<<
 * 
 * class PileupColumn(object):
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_a);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a);
  __Pyx_GIVEREF(__pyx_v_a);
  __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_f), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("chimerascan.pysam.csamtools.fetch_callback");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_a);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":117
 *         list of reads (:class:`pysam.PileupRead`) aligned to this column
 *     '''
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" + "\n".join( map(str, self.pileups) )
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_12PileupColumn___str__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_12PileupColumn___str__[] = "PileupColumn.__str__(self)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_12PileupColumn___str__ = {__Pyx_NAMESTR("__str__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_12PileupColumn___str__, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_12PileupColumn___str__)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_12PileupColumn___str__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__");
  __Pyx_TraceCall("__str__", __pyx_f[0], 117);
  __pyx_self = __pyx_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":118
 *     '''
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
 *             "\n" + "\n".join( map(str, self.pileups) )
 * 
 */
  __Pyx_XDECREF(__pyx_r);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":119
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
 * 
 * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":118
 *     '''
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
 *             "\n" + "\n".join( map(str, self.pileups) )
 * 
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_builtin_map, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":119
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
 * 
 * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
 */
  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_2), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupColumn.__str__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":121
 *             "\n" + "\n".join( map(str, self.pileups) )
 * 
 * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):             # <<<<<<<<<<<<<<
 *     '''callback for pileup.
 * 
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_pileup_callback(uint32_t __pyx_v_tid, uint32_t __pyx_v_pos, int __pyx_v_n, bam_pileup1_t *__pyx_v_pl, void *__pyx_v_f) {
  PyObject *__pyx_v_p;
  PyObject *__pyx_v_pileups;
  int __pyx_v_x;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("pileup_callback");
  __Pyx_TraceCall("pileup_callback", __pyx_f[0], 121);
  __pyx_v_p = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_pileups = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":138
 *     '''
 * 
 *     p = PileupColumn()             # <<<<<<<<<<<<<<
 *     p.tid = tid
 *     p.pos = pos
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__PileupColumn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_p);
  __pyx_v_p = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":139
 * 
 *     p = PileupColumn()
 *     p.tid = tid             # <<<<<<<<<<<<<<
 *     p.pos = pos
 *     p.n = n
 */
  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__tid, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":140
 *     p = PileupColumn()
 *     p.tid = tid
 *     p.pos = pos             # <<<<<<<<<<<<<<
 *     p.n = n
 *     pileups = []
 */
  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pos, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":141
 *     p.tid = tid
 *     p.pos = pos
 *     p.n = n             # <<<<<<<<<<<<<<
 *     pileups = []
 * 
 */
  __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__n, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":142
 *     p.pos = pos
 *     p.n = n
 *     pileups = []             # <<<<<<<<<<<<<<
 * 
 *     cdef int x
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_pileups));
  __pyx_v_pileups = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":145
 * 
 *     cdef int x
 *     for x from 0 <= x < n:             # <<<<<<<<<<<<<<
 *         pileups.append( makePileupRead( &(pl[x]) ) )
 *     p.pileups = pileups
 */
  __pyx_t_3 = __pyx_v_n;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":146
 *     cdef int x
 *     for x from 0 <= x < n:
 *         pileups.append( makePileupRead( &(pl[x]) ) )             # <<<<<<<<<<<<<<
 *     p.pileups = pileups
 * 
 */
    if (unlikely(__pyx_v_pileups == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_makePileupRead((&(__pyx_v_pl[__pyx_v_x]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_pileups), __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":147
 *     for x from 0 <= x < n:
 *         pileups.append( makePileupRead( &(pl[x]) ) )
 *     p.pileups = pileups             # <<<<<<<<<<<<<<
 * 
 *     (<object>f)(p)
 */
  if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pileups, ((PyObject *)__pyx_v_pileups)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":149
 *     p.pileups = pileups
 * 
 *     (<object>f)(p)             # <<<<<<<<<<<<<<
 * 
 * cdef int pileup_fetch_callback( bam1_t *b, void *data):
 */
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_p);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_p);
  __Pyx_GIVEREF(__pyx_v_p);
  __pyx_t_1 = PyObject_Call(((PyObject *)__pyx_v_f), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("chimerascan.pysam.csamtools.pileup_callback");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_p);
  __Pyx_DECREF(__pyx_v_pileups);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":151
 *     (<object>f)(p)
 * 
 * cdef int pileup_fetch_callback( bam1_t *b, void *data):             # <<<<<<<<<<<<<<
 *     '''callback for bam_fetch.
 * 
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_pileup_fetch_callback(bam1_t *__pyx_v_b, void *__pyx_v_data) {
  bam_plbuf_t *__pyx_v_buf;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("pileup_fetch_callback");
  __Pyx_TraceCall("pileup_fetch_callback", __pyx_f[0], 151);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":157
 *     '''
 *     cdef bam_plbuf_t * buf
 *     buf = <bam_plbuf_t*>data             # <<<<<<<<<<<<<<
 *     bam_plbuf_push(b, buf)
 *     return 0
 */
  __pyx_v_buf = ((bam_plbuf_t *)__pyx_v_data);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":158
 *     cdef bam_plbuf_t * buf
 *     buf = <bam_plbuf_t*>data
 *     bam_plbuf_push(b, buf)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
  bam_plbuf_push(__pyx_v_b, __pyx_v_buf);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":159
 *     buf = <bam_plbuf_t*>data
 *     bam_plbuf_push(b, buf)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * class StderrStore():
 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":165
 *     stderr is captured.
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
 *         self.stderr_save = Outs( sys.stderr.fileno() )
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore___init__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore___init__[] = "StderrStore.__init__(self)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore___init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore___init__, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore___init__)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore___init__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__");
  __Pyx_TraceCall("__init__", __pyx_f[0], 165);
  __pyx_self = __pyx_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":166
 *     '''
 *     def __init__(self):
 *         self.stderr_h, self.stderr_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
 *         self.stderr_save = Outs( sys.stderr.fileno() )
 *         self.stderr_save.setfd( self.stderr_h )
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
    PyObject* tuple = __pyx_t_1;
    __pyx_t_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_h, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_f, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_4, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_4, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_EndUnpack(__pyx_t_4, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_h, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_f, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":167
 *     def __init__(self):
 *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
 *         self.stderr_save = Outs( sys.stderr.fileno() )             # <<<<<<<<<<<<<<
 *         self.stderr_save.setfd( self.stderr_h )
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_save, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":168
 *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
 *         self.stderr_save = Outs( sys.stderr.fileno() )
 *         self.stderr_save.setfd( self.stderr_h )             # <<<<<<<<<<<<<<
 * 
 *     def readAndRelease( self ):
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_save); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_h); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.StderrStore.__init__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":170
 *         self.stderr_save.setfd( self.stderr_h )
 * 
 *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
 *         self.stderr_save.restore()
 *         lines = []
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease[] = "StderrStore.readAndRelease(self)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease = {__Pyx_NAMESTR("readAndRelease"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_lines;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("readAndRelease");
  __Pyx_TraceCall("readAndRelease", __pyx_f[0], 170);
  __pyx_self = __pyx_self;
  __pyx_v_lines = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":171
 * 
 *     def readAndRelease( self ):
 *         self.stderr_save.restore()             # <<<<<<<<<<<<<<
 *         lines = []
 *         if os.path.exists(self.stderr_f):
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_save); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__restore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":172
 *     def readAndRelease( self ):
 *         self.stderr_save.restore()
 *         lines = []             # <<<<<<<<<<<<<<
 *         if os.path.exists(self.stderr_f):
 *             lines = open( self.stderr_f, "r" ).readlines()
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(__pyx_v_lines);
  __pyx_v_lines = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":173
 *         self.stderr_save.restore()
 *         lines = []
 *         if os.path.exists(self.stderr_f):             # <<<<<<<<<<<<<<
 *             lines = open( self.stderr_f, "r" ).readlines()
 *             os.remove( self.stderr_f )
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":174
 *         lines = []
 *         if os.path.exists(self.stderr_f):
 *             lines = open( self.stderr_f, "r" ).readlines()             # <<<<<<<<<<<<<<
 *             os.remove( self.stderr_f )
 *         return lines
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__r));
    __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_open, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__readlines); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_lines);
    __pyx_v_lines = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":175
 *         if os.path.exists(self.stderr_f):
 *             lines = open( self.stderr_f, "r" ).readlines()
 *             os.remove( self.stderr_f )             # <<<<<<<<<<<<<<
 *         return lines
 * 
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__remove); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":176
 *             lines = open( self.stderr_f, "r" ).readlines()
 *             os.remove( self.stderr_f )
 *         return lines             # <<<<<<<<<<<<<<
 * 
 *     def release(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_lines);
  __pyx_r = __pyx_v_lines;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.StderrStore.readAndRelease");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_lines);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":178
 *         return lines
 * 
 *     def release(self):             # <<<<<<<<<<<<<<
 *         self.stderr_save.restore()
 *         if os.path.exists(self.stderr_f):
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore_release(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore_release[] = "StderrStore.release(self)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore_release = {__Pyx_NAMESTR("release"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore_release, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore_release)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore_release(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("release");
  __Pyx_TraceCall("release", __pyx_f[0], 178);
  __pyx_self = __pyx_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":179
 * 
 *     def release(self):
 *         self.stderr_save.restore()             # <<<<<<<<<<<<<<
 *         if os.path.exists(self.stderr_f):
 *             os.remove( self.stderr_f )
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_save); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__restore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":180
 *     def release(self):
 *         self.stderr_save.restore()
 *         if os.path.exists(self.stderr_f):             # <<<<<<<<<<<<<<
 *             os.remove( self.stderr_f )
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":181
 *         self.stderr_save.restore()
 *         if os.path.exists(self.stderr_f):
 *             os.remove( self.stderr_f )             # <<<<<<<<<<<<<<
 * 
 *     def __del__(self):
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__remove); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.StderrStore.release");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":183
 *             os.remove( self.stderr_f )
 * 
 *     def __del__(self):             # <<<<<<<<<<<<<<
 *         self.release()
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore___del__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore___del__[] = "StderrStore.__del__(self)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore___del__ = {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore___del__, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11StderrStore___del__)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11StderrStore___del__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__del__");
  __Pyx_TraceCall("__del__", __pyx_f[0], 183);
  __pyx_self = __pyx_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":184
 * 
 *     def __del__(self):
 *         self.release()             # <<<<<<<<<<<<<<
 * 
 * ######################################################################
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.StderrStore.__del__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":263
 *     cdef char * mode
 * 
 *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.samfile = NULL
 *         self.isbam = False
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 263);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":264
 * 
 *     def __cinit__(self, *args, **kwargs ):
 *         self.samfile = NULL             # <<<<<<<<<<<<<<
 *         self.isbam = False
 *         self._open( *args, **kwargs )
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile = NULL;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":265
 *     def __cinit__(self, *args, **kwargs ):
 *         self.samfile = NULL
 *         self.isbam = False             # <<<<<<<<<<<<<<
 *         self._open( *args, **kwargs )
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":266
 *         self.samfile = NULL
 *         self.isbam = False
 *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
 * 
 *         # allocate memory for iterator
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_3 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":269
 * 
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 * 
 *     def _isOpen( self ):
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_kwargs);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":271
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has been opened.'''
 *         return self.samfile != NULL
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__isOpen[] = "Samfile._isOpen(self)\nreturn true if samfile has been opened.";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_isOpen");
  __Pyx_TraceCall("_isOpen", __pyx_f[0], 271);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":273
 *     def _isOpen( self ):
 *         '''return true if samfile has been opened.'''
 *         return self.samfile != NULL             # <<<<<<<<<<<<<<
 * 
 *     def _hasIndex( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._isOpen");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":275
 *         return self.samfile != NULL
 * 
 *     def _hasIndex( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has an existing (and opened) index.'''
 *         return self.index != NULL
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__hasIndex[] = "Samfile._hasIndex(self)\nreturn true if samfile has an existing (and opened) index.";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_hasIndex");
  __Pyx_TraceCall("_hasIndex", __pyx_f[0], 275);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":277
 *     def _hasIndex( self ):
 *         '''return true if samfile has an existing (and opened) index.'''
 *         return self.index != NULL             # <<<<<<<<<<<<<<
 * 
 *     def _open( self,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._hasIndex");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":279
 *         return self.index != NULL
 * 
 *     def _open( self,             # <<<<<<<<<<<<<<
 *                char * filename,
 *                mode = 'r',
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__open[] = "Samfile._open(self, char *filename, mode='r', Samfile template=None, referencenames=None, referencelengths=None, text=None, header=None, port=None)\nopen a sam/bam file.\n\n        If _open is called on an existing bamfile, the current file will be\n        closed and a new file will be opened.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char *__pyx_v_filename;
  PyObject *__pyx_v_mode = 0;
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_template = 0;
  PyObject *__pyx_v_referencenames = 0;
  PyObject *__pyx_v_referencelengths = 0;
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_header = 0;
  PyObject *__pyx_v_port = 0;
  bam_header_t *__pyx_v_header_to_write;
  char *__pyx_v_ctext;
  PyObject *__pyx_v_n;
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_name;
  PyObject *__pyx_v_store;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  size_t __pyx_t_10;
  int32_t __pyx_t_11;
  long __pyx_t_12;
  uint32_t __pyx_t_13;
  char *__pyx_t_14;
  int __pyx_t_15;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__mode,&__pyx_n_s__template,&__pyx_n_s__referencenames,&__pyx_n_s__referencelengths,&__pyx_n_s__text,&__pyx_n_s__header,&__pyx_n_s__port,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_open");
  __Pyx_TraceCall("_open", __pyx_f[0], 279);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[8] = {0,0,0,0,0,0,0,0};
    values[1] = ((PyObject *)__pyx_n_s__r);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":282
 *                char * filename,
 *                mode = 'r',
 *                Samfile template = None,             # <<<<<<<<<<<<<<
 *                referencenames = None,
 *                referencelengths = None,
 */
    values[2] = (PyObject *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":283
 *                mode = 'r',
 *                Samfile template = None,
 *                referencenames = None,             # <<<<<<<<<<<<<<
 *                referencelengths = None,
 *                text = None,
 */
    values[3] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":284
 *                Samfile template = None,
 *                referencenames = None,
 *                referencelengths = None,             # <<<<<<<<<<<<<<
 *                text = None,
 *                header = None,
 */
    values[4] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":285
 *                referencenames = None,
 *                referencelengths = None,
 *                text = None,             # <<<<<<<<<<<<<<
 *                header = None,
 *                port = None,
 */
    values[5] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":286
 *                referencelengths = None,
 *                text = None,
 *                header = None,             # <<<<<<<<<<<<<<
 *                port = None,
 *               ):
 */
    values[6] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":287
 *                text = None,
 *                header = None,
 *                port = None,             # <<<<<<<<<<<<<<
 *               ):
 *         '''open a sam/bam file.
 */
    values[7] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__template);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__referencenames);
        if (value) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__referencelengths);
        if (value) { values[4] = value; kw_args--; }
      }
      case  5:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__text);
        if (value) { values[5] = value; kw_args--; }
      }
      case  6:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__header);
        if (value) { values[6] = value; kw_args--; }
      }
      case  7:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__port);
        if (value) { values[7] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_filename = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_mode = values[1];
    __pyx_v_template = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)values[2]);
    __pyx_v_referencenames = values[3];
    __pyx_v_referencelengths = values[4];
    __pyx_v_text = values[5];
    __pyx_v_header = values[6];
    __pyx_v_port = values[7];
  } else {
    __pyx_v_mode = ((PyObject *)__pyx_n_s__r);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":282
 *                char * filename,
 *                mode = 'r',
 *                Samfile template = None,             # <<<<<<<<<<<<<<
 *                referencenames = None,
 *                referencelengths = None,
 */
    __pyx_v_template = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":283
 *                mode = 'r',
 *                Samfile template = None,
 *                referencenames = None,             # <<<<<<<<<<<<<<
 *                referencelengths = None,
 *                text = None,
 */
    __pyx_v_referencenames = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":284
 *                Samfile template = None,
 *                referencenames = None,
 *                referencelengths = None,             # <<<<<<<<<<<<<<
 *                text = None,
 *                header = None,
 */
    __pyx_v_referencelengths = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":285
 *                referencenames = None,
 *                referencelengths = None,
 *                text = None,             # <<<<<<<<<<<<<<
 *                header = None,
 *                port = None,
 */
    __pyx_v_text = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":286
 *                referencelengths = None,
 *                text = None,
 *                header = None,             # <<<<<<<<<<<<<<
 *                port = None,
 *               ):
 */
    __pyx_v_header = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":287
 *                text = None,
 *                header = None,
 *                port = None,             # <<<<<<<<<<<<<<
 *               ):
 *         '''open a sam/bam file.
 */
    __pyx_v_port = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  8: __pyx_v_port = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: __pyx_v_header = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: __pyx_v_text = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: __pyx_v_referencelengths = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: __pyx_v_referencenames = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_template = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 2));
      case  2: __pyx_v_mode = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_filename = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._open");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_n = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_x = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_name = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_result = Py_None; __Pyx_INCREF(Py_None);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_11chimerascan_5pysam_9csamtools_Samfile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":295
 *         '''
 * 
 *         assert mode in ( "r","w","rb","wb", "wh", "wbu" ), "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
 * 
 *         # close a previously opened file
 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  __Pyx_INCREF(__pyx_v_mode);
  __pyx_t_1 = __pyx_v_mode;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __pyx_t_3;
  if (!__pyx_t_4) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__w), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_3;
    __pyx_t_3 = __pyx_t_5;
  } else {
    __pyx_t_3 = __pyx_t_4;
  }
  if (!__pyx_t_3) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__rb), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_4;
    __pyx_t_4 = __pyx_t_5;
  } else {
    __pyx_t_4 = __pyx_t_3;
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__wb), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_3;
    __pyx_t_3 = __pyx_t_5;
  } else {
    __pyx_t_3 = __pyx_t_4;
  }
  if (!__pyx_t_3) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__wh), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_4;
    __pyx_t_4 = __pyx_t_5;
  } else {
    __pyx_t_4 = __pyx_t_3;
  }
  if (!__pyx_t_4) {
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__wbu), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __pyx_t_3;
    __pyx_t_3 = __pyx_t_5;
  } else {
    __pyx_t_3 = __pyx_t_4;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) {
    __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), __pyx_v_mode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_1));
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":298
 * 
 *         # close a previously opened file
 *         if self.samfile != NULL: self.close()             # <<<<<<<<<<<<<<
 *         self.samfile = NULL
 * 
 */
  __pyx_t_3 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile != NULL);
  if (__pyx_t_3) {
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":299
 *         # close a previously opened file
 *         if self.samfile != NULL: self.close()
 *         self.samfile = NULL             # <<<<<<<<<<<<<<
 * 
 *         cdef bam_header_t * header_to_write
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile = NULL;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":302
 * 
 *         cdef bam_header_t * header_to_write
 *         header_to_write = NULL             # <<<<<<<<<<<<<<
 * 
 *         self.filename = filename
 */
  __pyx_v_header_to_write = NULL;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":304
 *         header_to_write = NULL
 * 
 *         self.filename = filename             # <<<<<<<<<<<<<<
 * 
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->filename = __pyx_v_filename;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":306
 *         self.filename = filename
 * 
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'             # <<<<<<<<<<<<<<
 * 
 *         self.isremote = strncmp(filename,"http:",5) == 0 or \
 */
  __pyx_t_6 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyBool_FromLong((__pyx_t_6 > 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_mode, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__b), Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __pyx_t_7;
    __pyx_t_7 = 0;
  } else {
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam = __pyx_t_8;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":308
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 * 
 *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
 *             strncmp(filename,"ftp:",4) == 0
 * 
 */
  __pyx_t_3 = (strncmp(__pyx_v_filename, __pyx_k_4, 5) == 0);
  if (!__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":309
 * 
 *         self.isremote = strncmp(filename,"http:",5) == 0 or \
 *             strncmp(filename,"ftp:",4) == 0             # <<<<<<<<<<<<<<
 * 
 *         cdef char * ctext
 */
    __pyx_t_4 = (strncmp(__pyx_v_filename, __pyx_k_5, 4) == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_3;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":308
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 * 
 *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
 *             strncmp(filename,"ftp:",4) == 0
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isremote = __pyx_t_5;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":312
 * 
 *         cdef char * ctext
 *         ctext = NULL             # <<<<<<<<<<<<<<
 * 
 *         if mode[0] == 'w':
 */
  __pyx_v_ctext = NULL;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":314
 *         ctext = NULL
 * 
 *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
 *             # open file for writing
 * 
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__w), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":318
 * 
 *             # header structure (used for writing)
 *             if template:             # <<<<<<<<<<<<<<
 *                 # copy header from another file
 *                 header_to_write = template.samfile.header
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":320
 *             if template:
 *                 # copy header from another file
 *                 header_to_write = template.samfile.header             # <<<<<<<<<<<<<<
 * 
 *             elif header:
 */
      __pyx_v_header_to_write = __pyx_v_template->samfile->header;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":322
 *                 header_to_write = template.samfile.header
 * 
 *             elif header:             # <<<<<<<<<<<<<<
 *                 header_to_write = self._buildHeader( header )
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":323
 * 
 *             elif header:
 *                 header_to_write = self._buildHeader( header )             # <<<<<<<<<<<<<<
 * 
 *             else:
 */
      __pyx_v_header_to_write = ((struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_Samfile *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->__pyx_vtab)->_buildHeader(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self), __pyx_v_header);
      goto __pyx_L8;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":327
 *             else:
 *                 # build header from a target names and lengths
 *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"             # <<<<<<<<<<<<<<
 *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"
 * 
 */
      #ifndef PYREX_WITHOUT_ASSERTIONS
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_referencenames); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_5) {
        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_referencelengths); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_4 = __pyx_t_3;
      } else {
        __pyx_t_4 = __pyx_t_5;
      }
      if (unlikely(!__pyx_t_4)) {
        PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_6));
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":328
 *                 # build header from a target names and lengths
 *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"
 *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"             # <<<<<<<<<<<<<<
 * 
 *                 # allocate and fill header
 */
      #ifndef PYREX_WITHOUT_ASSERTIONS
      __pyx_t_6 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_9 = PyObject_Length(__pyx_v_referencelengths); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (unlikely(!(__pyx_t_6 == __pyx_t_9))) {
        PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_7));
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":331
 * 
 *                 # allocate and fill header
 *                 header_to_write = bam_header_init()             # <<<<<<<<<<<<<<
 *                 header_to_write.n_targets = len(referencenames)
 *                 n = 0
 */
      __pyx_v_header_to_write = bam_header_init();

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":332
 *                 # allocate and fill header
 *                 header_to_write = bam_header_init()
 *                 header_to_write.n_targets = len(referencenames)             # <<<<<<<<<<<<<<
 *                 n = 0
 *                 for x in referencenames: n += len(x) + 1
 */
      __pyx_t_9 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_header_to_write->n_targets = __pyx_t_9;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":333
 *                 header_to_write = bam_header_init()
 *                 header_to_write.n_targets = len(referencenames)
 *                 n = 0             # <<<<<<<<<<<<<<
 *                 for x in referencenames: n += len(x) + 1
 *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
 */
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_DECREF(__pyx_v_n);
      __pyx_v_n = __pyx_int_0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":334
 *                 header_to_write.n_targets = len(referencenames)
 *                 n = 0
 *                 for x in referencenames: n += len(x) + 1             # <<<<<<<<<<<<<<
 *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
 *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 */
      if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
        __pyx_t_9 = 0; __pyx_t_2 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_2);
      } else {
        __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
      }
      for (;;) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_2)) break;
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++;
        } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++;
        } else {
          __pyx_t_1 = PyIter_Next(__pyx_t_2);
          if (!__pyx_t_1) {
            if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            break;
          }
          __Pyx_GOTREF(__pyx_t_1);
        }
        __Pyx_DECREF(__pyx_v_x);
        __pyx_v_x = __pyx_t_1;
        __pyx_t_1 = 0;
        __pyx_t_6 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_1 = PyInt_FromSsize_t((__pyx_t_6 + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_v_n);
        __pyx_v_n = __pyx_t_7;
        __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":335
 *                 n = 0
 *                 for x in referencenames: n += len(x) + 1
 *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
 *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < header_to_write.n_targets:
 */
      __pyx_t_10 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_10 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_header_to_write->target_name = ((char **)calloc(__pyx_t_10, (sizeof(char *))));

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":336
 *                 for x in referencenames: n += len(x) + 1
 *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
 *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
 *                 for x from 0 <= x < header_to_write.n_targets:
 *                     header_to_write.target_len[x] = referencelengths[x]
 */
      __pyx_t_10 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_10 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_header_to_write->target_len = ((uint32_t *)calloc(__pyx_t_10, (sizeof(uint32_t))));

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":337
 *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
 *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
 *                     header_to_write.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]
 */
      __pyx_t_11 = __pyx_v_header_to_write->n_targets;
      for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12++) {
        __pyx_t_2 = PyInt_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_v_x);
        __pyx_v_x = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":338
 *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < header_to_write.n_targets:
 *                     header_to_write.target_len[x] = referencelengths[x]             # <<<<<<<<<<<<<<
 *                     name = referencenames[x]
 *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
 */
        __pyx_t_2 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_13 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_13 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        (__pyx_v_header_to_write->target_len[__pyx_t_9]) = __pyx_t_13;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":339
 *                 for x from 0 <= x < header_to_write.n_targets:
 *                     header_to_write.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]             # <<<<<<<<<<<<<<
 *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
 *                     strncpy( header_to_write.target_name[x], name, len(name) )
 */
        __pyx_t_2 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_v_name);
        __pyx_v_name = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":340
 *                     header_to_write.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]
 *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))             # <<<<<<<<<<<<<<
 *                     strncpy( header_to_write.target_name[x], name, len(name) )
 * 
 */
        __pyx_t_9 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        (__pyx_v_header_to_write->target_name[__pyx_t_6]) = ((char *)calloc((__pyx_t_9 + 1), (sizeof(char))));

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":341
 *                     name = referencenames[x]
 *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
 *                     strncpy( header_to_write.target_name[x], name, len(name) )             # <<<<<<<<<<<<<<
 * 
 *                 if text != None:
 */
        __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_14 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_6 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        strncpy((__pyx_v_header_to_write->target_name[__pyx_t_9]), __pyx_t_14, __pyx_t_6);
        __pyx_t_12 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":337
 *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
 *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
 *                     header_to_write.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]
 */
      __pyx_t_2 = PyInt_FromLong(__pyx_t_12); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_x);
      __pyx_v_x = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":343
 *                     strncpy( header_to_write.target_name[x], name, len(name) )
 * 
 *                 if text != None:             # <<<<<<<<<<<<<<
 *                     # copy without \0
 *                     ctext = text
 */
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_text, Py_None, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_4) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":345
 *                 if text != None:
 *                     # copy without \0
 *                     ctext = text             # <<<<<<<<<<<<<<
 *                     header_to_write.l_text = strlen(ctext)
 *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
 */
        __pyx_t_14 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_ctext = __pyx_t_14;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":346
 *                     # copy without \0
 *                     ctext = text
 *                     header_to_write.l_text = strlen(ctext)             # <<<<<<<<<<<<<<
 *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
 *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
 */
        __pyx_v_header_to_write->l_text = strlen(__pyx_v_ctext);

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":347
 *                     ctext = text
 *                     header_to_write.l_text = strlen(ctext)
 *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )             # <<<<<<<<<<<<<<
 *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
 * 
 */
        __pyx_v_header_to_write->text = ((char *)calloc(strlen(__pyx_v_ctext), (sizeof(char))));

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":348
 *                     header_to_write.l_text = strlen(ctext)
 *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
 *                     memcpy( header_to_write.text, ctext, strlen(ctext) )             # <<<<<<<<<<<<<<
 * 
 *                 header_to_write.hash = NULL
 */
        memcpy(__pyx_v_header_to_write->text, __pyx_v_ctext, strlen(__pyx_v_ctext));
        goto __pyx_L13;
      }
      __pyx_L13:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":350
 *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
 * 
 *                 header_to_write.hash = NULL             # <<<<<<<<<<<<<<
 *                 header_to_write.rg2lib = NULL
 * 
 */
      __pyx_v_header_to_write->hash = NULL;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":351
 * 
 *                 header_to_write.hash = NULL
 *                 header_to_write.rg2lib = NULL             # <<<<<<<<<<<<<<
 * 
 *             # open file. Header gets written to file at the same time for bam files
 */
      __pyx_v_header_to_write->rg2lib = NULL;
    }
    __pyx_L8:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":355
 *             # open file. Header gets written to file at the same time for bam files
 *             # and sam files (in the latter case, the mode needs to be wh)
 *             store = StderrStore()             # <<<<<<<<<<<<<<
 *             self.samfile = samopen( filename, mode, header_to_write )
 *             store.release()
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_store);
    __pyx_v_store = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":356
 *             # and sam files (in the latter case, the mode needs to be wh)
 *             store = StderrStore()
 *             self.samfile = samopen( filename, mode, header_to_write )             # <<<<<<<<<<<<<<
 *             store.release()
 * 
 */
    __pyx_t_14 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile = samopen(__pyx_v_filename, __pyx_t_14, __pyx_v_header_to_write);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":357
 *             store = StderrStore()
 *             self.samfile = samopen( filename, mode, header_to_write )
 *             store.release()             # <<<<<<<<<<<<<<
 * 
 *             # bam_header_destroy takes care of cleaning up of all the members
 */
    __pyx_t_7 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":360
 * 
 *             # bam_header_destroy takes care of cleaning up of all the members
 *             if not template and header_to_write != NULL:             # <<<<<<<<<<<<<<
 *                 bam_header_destroy( header_to_write )
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = (!__pyx_t_4);
    if (__pyx_t_5) {
      __pyx_t_4 = (__pyx_v_header_to_write != NULL);
      __pyx_t_3 = __pyx_t_4;
    } else {
      __pyx_t_3 = __pyx_t_5;
    }
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":361
 *             # bam_header_destroy takes care of cleaning up of all the members
 *             if not template and header_to_write != NULL:
 *                 bam_header_destroy( header_to_write )             # <<<<<<<<<<<<<<
 * 
 *         elif mode[0] == "r":
 */
      bam_header_destroy(__pyx_v_header_to_write);
      goto __pyx_L14;
    }
    __pyx_L14:;
    goto __pyx_L7;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":363
 *                 bam_header_destroy( header_to_write )
 * 
 *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
 *             # open file for reading
 *             if strncmp( filename, "-", 1) != 0 and \
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":365
 *         elif mode[0] == "r":
 *             # open file for reading
 *             if strncmp( filename, "-", 1) != 0 and \             # <<<<<<<<<<<<<<
 *                     not self.isremote and \
 *                     not os.path.exists( filename ):
 */
    __pyx_t_3 = (strncmp(__pyx_v_filename, __pyx_k_8, 1) != 0);
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":366
 *             # open file for reading
 *             if strncmp( filename, "-", 1) != 0 and \
 *                     not self.isremote and \             # <<<<<<<<<<<<<<
 *                     not os.path.exists( filename ):
 *                 raise IOError( "file `%s` not found" % filename)
 */
      __pyx_t_5 = (!((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isremote);
      if (__pyx_t_5) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":367
 *             if strncmp( filename, "-", 1) != 0 and \
 *                     not self.isremote and \
 *                     not os.path.exists( filename ):             # <<<<<<<<<<<<<<
 *                 raise IOError( "file `%s` not found" % filename)
 * 
 */
        __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_2 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_2));
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
        __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_15 = (!__pyx_t_4);
        __pyx_t_4 = __pyx_t_15;
      } else {
        __pyx_t_4 = __pyx_t_5;
      }
      __pyx_t_5 = __pyx_t_4;
    } else {
      __pyx_t_5 = __pyx_t_3;
    }
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":368
 *                     not self.isremote and \
 *                     not os.path.exists( filename ):
 *                 raise IOError( "file `%s` not found" % filename)             # <<<<<<<<<<<<<<
 * 
 *             store = StderrStore()
 */
      __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_builtin_IOError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L15;
    }
    __pyx_L15:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":370
 *                 raise IOError( "file `%s` not found" % filename)
 * 
 *             store = StderrStore()             # <<<<<<<<<<<<<<
 *             self.samfile = samopen( filename, mode, NULL )
 *             result = store.readAndRelease()
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_v_store);
    __pyx_v_store = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":371
 * 
 *             store = StderrStore()
 *             self.samfile = samopen( filename, mode, NULL )             # <<<<<<<<<<<<<<
 *             result = store.readAndRelease()
 *             # test for specific messages as open also outputs status messages
 */
    __pyx_t_14 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile = samopen(__pyx_v_filename, __pyx_t_14, NULL);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":372
 *             store = StderrStore()
 *             self.samfile = samopen( filename, mode, NULL )
 *             result = store.readAndRelease()             # <<<<<<<<<<<<<<
 *             # test for specific messages as open also outputs status messages
 *             # that can be ignored.
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__readAndRelease); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_result);
    __pyx_v_result = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":375
 *             # test for specific messages as open also outputs status messages
 *             # that can be ignored.
 *             if "[bam_header_read] invalid BAM binary header (this is not a BAM file).\n" in result:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "invalid BAM binary header (is this a BAM file?)" )
 *             elif '[samopen] no @SQ lines in the header.\n' in result:
 */
    __pyx_t_5 = ((PySequence_Contains(__pyx_v_result, ((PyObject *)__pyx_kp_s_10)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":376
 *             # that can be ignored.
 *             if "[bam_header_read] invalid BAM binary header (this is not a BAM file).\n" in result:
 *                 raise ValueError( "invalid BAM binary header (is this a BAM file?)" )             # <<<<<<<<<<<<<<
 *             elif '[samopen] no @SQ lines in the header.\n' in result:
 *                 raise ValueError( "no @SQ lines in the header (is this a SAM file?)")
 */
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_11));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_11));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11));
      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L16;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":377
 *             if "[bam_header_read] invalid BAM binary header (this is not a BAM file).\n" in result:
 *                 raise ValueError( "invalid BAM binary header (is this a BAM file?)" )
 *             elif '[samopen] no @SQ lines in the header.\n' in result:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "no @SQ lines in the header (is this a SAM file?)")
 * 
 */
    __pyx_t_5 = ((PySequence_Contains(__pyx_v_result, ((PyObject *)__pyx_kp_s_12)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":378
 *                 raise ValueError( "invalid BAM binary header (is this a BAM file?)" )
 *             elif '[samopen] no @SQ lines in the header.\n' in result:
 *                 raise ValueError( "no @SQ lines in the header (is this a SAM file?)")             # <<<<<<<<<<<<<<
 * 
 *         if self.samfile == NULL:
 */
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_13));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L16;
    }
    __pyx_L16:;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":380
 *                 raise ValueError( "no @SQ lines in the header (is this a SAM file?)")
 * 
 *         if self.samfile == NULL:             # <<<<<<<<<<<<<<
 *             raise IOError("could not open file `%s`" % filename )
 * 
 */
  __pyx_t_5 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile == NULL);
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":381
 * 
 *         if self.samfile == NULL:
 *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
 * 
 *         # check for index and open if present
 */
    __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L17;
  }
  __pyx_L17:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":384
 * 
 *         # check for index and open if present
 *         if mode[0] == "r" and self.isbam:             # <<<<<<<<<<<<<<
 * 
 *             if not self.isremote:
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_5) {
    __pyx_t_3 = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam;
  } else {
    __pyx_t_3 = __pyx_t_5;
  }
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":386
 *         if mode[0] == "r" and self.isbam:
 * 
 *             if not self.isremote:             # <<<<<<<<<<<<<<
 *                 if not os.path.exists(filename +".bai"):
 *                     self.index = NULL
 */
    __pyx_t_3 = (!((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isremote);
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":387
 * 
 *             if not self.isremote:
 *                 if not os.path.exists(filename +".bai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 else:
 */
      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_kp_s_15)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_5 = (!__pyx_t_3);
      if (__pyx_t_5) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":388
 *             if not self.isremote:
 *                 if not os.path.exists(filename +".bai"):
 *                     self.index = NULL             # <<<<<<<<<<<<<<
 *                 else:
 *                     # returns NULL if there is no index or index could not be opened
 */
        ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index = NULL;
        goto __pyx_L20;
      }
      /*else*/ {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":391
 *                 else:
 *                     # returns NULL if there is no index or index could not be opened
 *                     self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
 *                     if self.index == NULL:
 *                         raise IOError("error while opening index `%s` " % filename )
 */
        ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index = bam_index_load(__pyx_v_filename);

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":392
 *                     # returns NULL if there is no index or index could not be opened
 *                     self.index = bam_index_load(filename)
 *                     if self.index == NULL:             # <<<<<<<<<<<<<<
 *                         raise IOError("error while opening index `%s` " % filename )
 *             else:
 */
        __pyx_t_5 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index == NULL);
        if (__pyx_t_5) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":393
 *                     self.index = bam_index_load(filename)
 *                     if self.index == NULL:
 *                         raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
 *             else:
 *                 self.index = bam_index_load(filename)
 */
          __pyx_t_7 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_7));
          __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_2));
          __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_2));
          __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
          __pyx_t_2 = 0;
          __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_Raise(__pyx_t_2, 0, 0);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L21;
        }
        __pyx_L21:;
      }
      __pyx_L20:;
      goto __pyx_L19;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":395
 *                         raise IOError("error while opening index `%s` " % filename )
 *             else:
 *                 self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
 *                 if self.index == NULL:
 *                     raise IOError("error while opening index `%s` " % filename )
 */
      ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index = bam_index_load(__pyx_v_filename);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":396
 *             else:
 *                 self.index = bam_index_load(filename)
 *                 if self.index == NULL:             # <<<<<<<<<<<<<<
 *                     raise IOError("error while opening index `%s` " % filename )
 * 
 */
      __pyx_t_5 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index == NULL);
      if (__pyx_t_5) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":397
 *                 self.index = bam_index_load(filename)
 *                 if self.index == NULL:
 *                     raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
 * 
 *     def getrname( self, tid ):
 */
        __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_2));
        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_7));
        __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_7));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
        __pyx_t_7 = 0;
        __pyx_t_7 = PyObject_Call(__pyx_builtin_IOError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_7, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L22;
      }
      __pyx_L22:;
    }
    __pyx_L19:;
    goto __pyx_L18;
  }
  __pyx_L18:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._open");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_n);
  __Pyx_DECREF(__pyx_v_x);
  __Pyx_DECREF(__pyx_v_name);
  __Pyx_DECREF(__pyx_v_store);
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":399
 *                     raise IOError("error while opening index `%s` " % filename )
 * 
 *     def getrname( self, tid ):             # <<<<<<<<<<<<<<
 *         '''(tid )
 *         convert numerical :term:`tid` into :ref:`reference` name.'''
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_getrname[] = "Samfile.getrname(self, tid)\n(tid )\n        convert numerical :term:`tid` into :ref:`reference` name.";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getrname");
  __Pyx_TraceCall("getrname", __pyx_f[0], 399);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":402
 *         '''(tid )
 *         convert numerical :term:`tid` into :ref:`reference` name.'''
 *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         if not 0 <= tid < self.samfile.header.n_targets:
 *             raise ValueError( "tid out of range 0<=tid<%i" % self.samfile.header.n_targets )
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":403
 *         convert numerical :term:`tid` into :ref:`reference` name.'''
 *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError( "tid out of range 0<=tid<%i" % self.samfile.header.n_targets )
 *         return self.samfile.header.target_name[tid]
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_4);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":404
 *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *         if not 0 <= tid < self.samfile.header.n_targets:
 *             raise ValueError( "tid out of range 0<=tid<%i" % self.samfile.header.n_targets )             # <<<<<<<<<<<<<<
 *         return self.samfile.header.target_name[tid]
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":405
 *         if not 0 <= tid < self.samfile.header.n_targets:
 *             raise ValueError( "tid out of range 0<=tid<%i" % self.samfile.header.n_targets )
 *         return self.samfile.header.target_name[tid]             # <<<<<<<<<<<<<<
 * 
 *     def _parseRegion( self,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyBytes_FromString((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->target_name[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.getrname");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":407
 *         return self.samfile.header.target_name[tid]
 * 
 *     def _parseRegion( self,             # <<<<<<<<<<<<<<
 *                       reference = None,
 *                       start = None,
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__parseRegion[] = "Samfile._parseRegion(self, reference=None, start=None, end=None, region=None)\nparse region information.\n\n        raise Value for for invalid regions.\n\n        returns a tuple of region, tid, start and end. Region\n        is a valid samtools :term:`region` or None if the region\n        extends over the whole file.\n\n        Note that regions are 1-based, while start,end are python coordinates.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  int __pyx_v_max_pos;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  char *__pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_parseRegion");
  __Pyx_TraceCall("_parseRegion", __pyx_f[0], 407);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":408
 * 
 *     def _parseRegion( self,
 *                       reference = None,             # <<<<<<<<<<<<<<
 *                       start = None,
 *                       end = None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":409
 *     def _parseRegion( self,
 *                       reference = None,
 *                       start = None,             # <<<<<<<<<<<<<<
 *                       end = None,
 *                       region = None ):
 */
    values[1] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":410
 *                       reference = None,
 *                       start = None,
 *                       end = None,             # <<<<<<<<<<<<<<
 *                       region = None ):
 *         '''parse region information.
 */
    values[2] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":411
 *                       start = None,
 *                       end = None,
 *                       region = None ):             # <<<<<<<<<<<<<<
 *         '''parse region information.
 * 
 */
    values[3] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
        if (value) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
        if (value) { values[3] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
  } else {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":408
 * 
 *     def _parseRegion( self,
 *                       reference = None,             # <<<<<<<<<<<<<<
 *                       start = None,
 *                       end = None,
 */
    __pyx_v_reference = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":409
 *     def _parseRegion( self,
 *                       reference = None,
 *                       start = None,             # <<<<<<<<<<<<<<
 *                       end = None,
 *                       region = None ):
 */
    __pyx_v_start = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":410
 *                       reference = None,
 *                       start = None,
 *                       end = None,             # <<<<<<<<<<<<<<
 *                       region = None ):
 *         '''parse region information.
 */
    __pyx_v_end = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":411
 *                       start = None,
 *                       end = None,
 *                       region = None ):             # <<<<<<<<<<<<<<
 *         '''parse region information.
 * 
 */
    __pyx_v_region = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._parseRegion");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_region);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":430
 *         cdef int rend
 *         cdef int max_pos
 *         max_pos = 2 << 29             # <<<<<<<<<<<<<<
 * 
 *         rtid = rstart = rend = 0
 */
  __pyx_v_max_pos = 1073741824;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":432
 *         max_pos = 2 << 29
 * 
 *         rtid = rstart = rend = 0             # <<<<<<<<<<<<<<
 * 
 *         # translate to a region
 */
  __pyx_v_rtid = 0;
  __pyx_v_rstart = 0;
  __pyx_v_rend = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":435
 * 
 *         # translate to a region
 *         if reference:             # <<<<<<<<<<<<<<
 *             if start != None and end != None:
 *                 if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":436
 *         # translate to a region
 *         if reference:
 *             if start != None and end != None:             # <<<<<<<<<<<<<<
 *                 if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
 *                 region = "%s:%i-%i" % (reference, start+1, end)
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_1) {
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = __pyx_t_3;
    } else {
      __pyx_t_4 = __pyx_t_1;
    }
    if (__pyx_t_4) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":437
 *         if reference:
 *             if start != None and end != None:
 *                 if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )             # <<<<<<<<<<<<<<
 *                 region = "%s:%i-%i" % (reference, start+1, end)
 *             else:
 */
      __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_4) {
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_start);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start);
        __Pyx_GIVEREF(__pyx_v_start);
        __Pyx_INCREF(__pyx_v_end);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_end);
        __Pyx_GIVEREF(__pyx_v_end);
        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_5));
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_5));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
        __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_5, 0, 0);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":438
 *             if start != None and end != None:
 *                 if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
 *                 region = "%s:%i-%i" % (reference, start+1, end)             # <<<<<<<<<<<<<<
 *             else:
 *                 region = reference
 */
      __pyx_t_5 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_reference);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
      __Pyx_GIVEREF(__pyx_v_reference);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_end);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
      __Pyx_GIVEREF(__pyx_v_end);
      __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_20), __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_v_region);
      __pyx_v_region = ((PyObject *)__pyx_t_5);
      __pyx_t_5 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":440
 *                 region = "%s:%i-%i" % (reference, start+1, end)
 *             else:
 *                 region = reference             # <<<<<<<<<<<<<<
 * 
 *         if region:
 */
      __Pyx_INCREF(__pyx_v_reference);
      __Pyx_DECREF(__pyx_v_region);
      __pyx_v_region = __pyx_v_reference;
    }
    __pyx_L7:;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":442
 *                 region = reference
 * 
 *         if region:             # <<<<<<<<<<<<<<
 *             # this function might be called often (multiprocessing)
 *             # thus avoid using StderrStore, see issue 46.
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":445
 *             # this function might be called often (multiprocessing)
 *             # thus avoid using StderrStore, see issue 46.
 *             bam_parse_region( self.samfile.header, region, &rtid, &rstart, &rend)             # <<<<<<<<<<<<<<
 *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
 *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
 */
    __pyx_t_6 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    bam_parse_region(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header, __pyx_t_6, (&__pyx_v_rtid), (&__pyx_v_rstart), (&__pyx_v_rend));

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":446
 *             # thus avoid using StderrStore, see issue 46.
 *             bam_parse_region( self.samfile.header, region, &rtid, &rstart, &rend)
 *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )             # <<<<<<<<<<<<<<
 *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
 *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
 */
    __pyx_t_4 = (__pyx_v_rtid < 0);
    if (__pyx_t_4) {
      __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_region); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_5));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_5));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
      __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":447
 *             bam_parse_region( self.samfile.header, region, &rtid, &rstart, &rend)
 *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
 *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )             # <<<<<<<<<<<<<<
 *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
 *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
 */
    __pyx_t_4 = (__pyx_v_rstart > __pyx_v_rend);
    if (__pyx_t_4) {
      __pyx_t_5 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_5 = 0;
      __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_2));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":448
 *             if rtid < 0: raise ValueError( "invalid region `%s`" % region )
 *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
 *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )             # <<<<<<<<<<<<<<
 *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
 * 
 */
    __pyx_t_4 = (0 <= __pyx_v_rstart);
    if (__pyx_t_4) {
      __pyx_t_4 = (__pyx_v_rstart < __pyx_v_max_pos);
    }
    __pyx_t_1 = (!__pyx_t_4);
    if (__pyx_t_1) {
      __pyx_t_2 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), __pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_7));
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_7));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
      __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":449
 *             if rstart > rend: raise ValueError( 'invalid region: start (%i) > end (%i)' % (rstart, rend) )
 *             if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
 *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )             # <<<<<<<<<<<<<<
 * 
 *         return region, rtid, rstart, rend
 */
    __pyx_t_1 = (0 <= __pyx_v_rend);
    if (__pyx_t_1) {
      __pyx_t_1 = (__pyx_v_rend < __pyx_v_max_pos);
    }
    __pyx_t_4 = (!__pyx_t_1);
    if (__pyx_t_4) {
      __pyx_t_7 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_2));
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_2));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
      __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L13;
    }
    __pyx_L13:;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":451
 *             if not 0 <= rend < max_pos: raise ValueError( 'end out of range (%i)' % rend )
 * 
 *         return region, rtid, rstart, rend             # <<<<<<<<<<<<<<
 * 
 *     def seek( self, uint64_t offset, int where = 0):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_2 = 0;
  __pyx_t_7 = 0;
  __pyx_t_5 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._parseRegion");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_region);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":453
 *         return region, rtid, rstart, rend
 * 
 *     def seek( self, uint64_t offset, int where = 0):             # <<<<<<<<<<<<<<
 *         '''move to current file to position *offset*'''
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_seek[] = "Samfile.seek(self, uint64_t offset, int where=0)\nmove to current file to position *offset*";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  uint64_t __pyx_v_offset;
  int __pyx_v_where;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__offset,&__pyx_n_s__where,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("seek");
  __Pyx_TraceCall("seek", __pyx_f[0], 453);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__where);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_offset = __Pyx_PyInt_from_py_uint64_t(values[0]); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[1]) {
      __pyx_v_where = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_where = ((int)0);
    }
  } else {
    __pyx_v_where = ((int)0);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_where = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  1: __pyx_v_offset = __Pyx_PyInt_from_py_uint64_t(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.seek");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":456
 *         '''move to current file to position *offset*'''
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":457
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":458
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError("seek only available in bam files")
 *         return bam_seek( self.samfile.x.bam, offset, where )
 */
  __pyx_t_4 = (!((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":459
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
 *         return bam_seek( self.samfile.x.bam, offset, where )
 * 
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_24));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":460
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")
 *         return bam_seek( self.samfile.x.bam, offset, where )             # <<<<<<<<<<<<<<
 * 
 *     def tell( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_seek(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, __pyx_v_offset, __pyx_v_where)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.seek");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":462
 *         return bam_seek( self.samfile.x.bam, offset, where )
 * 
 *     def tell( self ):             # <<<<<<<<<<<<<<
 *         '''return current file position'''
 *         if not self._isOpen():
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_tell[] = "Samfile.tell(self)\nreturn current file position";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("tell");
  __Pyx_TraceCall("tell", __pyx_f[0], 462);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":464
 *     def tell( self ):
 *         '''return current file position'''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":465
 *         '''return current file position'''
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":466
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError("seek only available in bam files")
 * 
 */
  __pyx_t_4 = (!((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":467
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
 * 
 *         return bam_tell( self.samfile.x.bam )
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_24));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
    __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":469
 *             raise NotImplementedError("seek only available in bam files")
 * 
 *         return bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
 * 
 *     def fetch( self,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_tell(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.tell");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":471
 *         return bam_tell( self.samfile.x.bam )
 * 
 *     def fetch( self,             # <<<<<<<<<<<<<<
 *                reference = None,
 *                start = None,
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_fetch[] = "Samfile.fetch(self, reference=None, start=None, end=None, region=None, callback=None, until_eof=False)\n*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*\n               \n        fetch :meth:`AlignedRead` objects in a :term:`region` using 0-based indexing. The region is specified by\n        :term:`reference`, *start* and *end*. Alternatively, a samtools :term:`region` string can be supplied.\n\n        Without *reference* or *region* all reads will be fetched. The reads will be returned\n        ordered by reference sequence, which will not necessarily be the order within the file.\n        If *until_eof* is given, all reads from the current file position will be returned\n        *as they are sorted within the file*.  \n        \n        If only *reference* is set, all reads matching on *reference* will be fetched.\n\n        The method returns an iterator of type :class:`pysam.IteratorRow` unless\n        a *callback is provided. If *callback* is given, the callback will be executed \n        for each position within the :term:`region`. Note that callbacks currently work\n        only, if *region* or *reference* is given.\n\n        Note that a :term:`TAM` file does not allow random access. If *region* or *reference* are given,\n        an exception is raised.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_until_eof = 0;
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_t_13;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,&__pyx_n_s__callback,&__pyx_n_s__until_eof,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("fetch");
  __Pyx_TraceCall("fetch", __pyx_f[0], 471);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":472
 * 
 *     def fetch( self,
 *                reference = None,             # <<<<<<<<<<<<<<
 *                start = None,
 *                end = None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":473
 *     def fetch( self,
 *                reference = None,
 *                start = None,             # <<<<<<<<<<<<<<
 *                end = None,
 *                region = None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":474
 *                reference = None,
 *                start = None,
 *                end = None,             # <<<<<<<<<<<<<<
 *                region = None,
 *                callback = None,
 */
    values[2] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":475
 *                start = None,
 *                end = None,
 *                region = None,             # <<<<<<<<<<<<<<
 *                callback = None,
 *                until_eof = False ):
 */
    values[3] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":476
 *                end = None,
 *                region = None,
 *                callback = None,             # <<<<<<<<<<<<<<
 *                until_eof = False ):
 *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
 */
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_25;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
        if (value) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
        if (value) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
        if (value) { values[4] = value; kw_args--; }
      }
      case  5:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__until_eof);
        if (value) { values[5] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_callback = values[4];
    __pyx_v_until_eof = values[5];
  } else {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":472
 * 
 *     def fetch( self,
 *                reference = None,             # <<<<<<<<<<<<<<
 *                start = None,
 *                end = None,
 */
    __pyx_v_reference = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":473
 *     def fetch( self,
 *                reference = None,
 *                start = None,             # <<<<<<<<<<<<<<
 *                end = None,
 *                region = None,
 */
    __pyx_v_start = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":474
 *                reference = None,
 *                start = None,
 *                end = None,             # <<<<<<<<<<<<<<
 *                region = None,
 *                callback = None,
 */
    __pyx_v_end = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":475
 *                start = None,
 *                end = None,
 *                region = None,             # <<<<<<<<<<<<<<
 *                callback = None,
 *                until_eof = False ):
 */
    __pyx_v_region = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":476
 *                end = None,
 *                region = None,
 *                callback = None,             # <<<<<<<<<<<<<<
 *                until_eof = False ):
 *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
 */
    __pyx_v_callback = ((PyObject *)Py_None);
    __pyx_v_until_eof = __pyx_k_25;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  6: __pyx_v_until_eof = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.fetch");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_region);
  __pyx_v_i = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":502
 *         cdef int rend
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":503
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":505
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
 * 
 *         if self.isbam:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_reference);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
  __Pyx_GIVEREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  __pyx_t_5 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyTuple_CheckExact(__pyx_t_5) && likely(PyTuple_GET_SIZE(__pyx_t_5) == 4)) {
    PyObject* tuple = __pyx_t_5;
    __pyx_t_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = PyTuple_GET_ITEM(tuple, 3); __Pyx_INCREF(__pyx_t_7);
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_v_region);
    __pyx_v_region = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_v_rtid = __pyx_t_8;
    __pyx_v_rstart = __pyx_t_9;
    __pyx_v_rend = __pyx_t_10;
  } else {
    __pyx_t_11 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_11, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_11, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_11, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_11, 3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__Pyx_EndUnpack(__pyx_t_11, 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_v_region);
    __pyx_v_region = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_v_rtid = __pyx_t_10;
    __pyx_v_rstart = __pyx_t_9;
    __pyx_v_rend = __pyx_t_8;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":507
 *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
 * 
 *         if self.isbam:             # <<<<<<<<<<<<<<
 *             if not until_eof and not self._hasIndex() and not self.isremote:
 *                 raise ValueError( "fetch called on bamfile without index" )
 */
  if (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":508
 * 
 *         if self.isbam:
 *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "fetch called on bamfile without index" )
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = (!__pyx_t_4);
    if (__pyx_t_3) {
      __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = (!__pyx_t_4);
      if (__pyx_t_12) {
        __pyx_t_4 = (!((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isremote);
        __pyx_t_13 = __pyx_t_4;
      } else {
        __pyx_t_13 = __pyx_t_12;
      }
      __pyx_t_12 = __pyx_t_13;
    } else {
      __pyx_t_12 = __pyx_t_3;
    }
    if (__pyx_t_12) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":509
 *         if self.isbam:
 *             if not until_eof and not self._hasIndex() and not self.isremote:
 *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
 * 
 *             if callback:
 */
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_26));
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_26));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_26));
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":511
 *                 raise ValueError( "fetch called on bamfile without index" )
 * 
 *             if callback:             # <<<<<<<<<<<<<<
 *                 if not region:
 *                     raise ValueError( "callback functionality requires a region/reference" )
 */
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_12) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":512
 * 
 *             if callback:
 *                 if not region:             # <<<<<<<<<<<<<<
 *                     raise ValueError( "callback functionality requires a region/reference" )
 *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
 */
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = (!__pyx_t_12);
      if (__pyx_t_3) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":513
 *             if callback:
 *                 if not region:
 *                     raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
 *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
 *                 return bam_fetch(self.samfile.x.bam,
 */
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(((PyObject *)__pyx_kp_s_27));
        PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_27));
        __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27));
        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_7, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":514
 *                 if not region:
 *                     raise ValueError( "callback functionality requires a region/reference" )
 *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
 *                 return bam_fetch(self.samfile.x.bam,
 *                                  self.index,
 */
      __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_5 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_12 = (!__pyx_t_3);
      if (__pyx_t_12) {
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(((PyObject *)__pyx_kp_s_28));
        PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_28));
        __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28));
        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_7, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":515
 *                     raise ValueError( "callback functionality requires a region/reference" )
 *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
 *                 return bam_fetch(self.samfile.x.bam,             # <<<<<<<<<<<<<<
 *                                  self.index,
 *                                  rtid,
 */
      __Pyx_XDECREF(__pyx_r);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":521
 *                                  rend,
 *                                  <void*>callback,
 *                                  fetch_callback )             # <<<<<<<<<<<<<<
 *             else:
 *                 if region:
 */
      __pyx_t_7 = PyInt_FromLong(bam_fetch(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, ((void *)__pyx_v_callback), __pyx_f_11chimerascan_5pysam_9csamtools_fetch_callback)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;
      goto __pyx_L9;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":523
 *                                  fetch_callback )
 *             else:
 *                 if region:             # <<<<<<<<<<<<<<
 *                     return IteratorRow( self, rtid, rstart, rend )
 *                 else:
 */
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_12) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":524
 *             else:
 *                 if region:
 *                     return IteratorRow( self, rtid, rstart, rend )             # <<<<<<<<<<<<<<
 *                 else:
 *                     if until_eof:
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_7 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_5 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
        __Pyx_GIVEREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_7 = 0;
        __pyx_t_5 = 0;
        __pyx_t_6 = 0;
        __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRow)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_6;
        __pyx_t_6 = 0;
        goto __pyx_L0;
        goto __pyx_L12;
      }
      /*else*/ {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":526
 *                     return IteratorRow( self, rtid, rstart, rend )
 *                 else:
 *                     if until_eof:             # <<<<<<<<<<<<<<
 *                         return IteratorRowAll( self )
 *                     else:
 */
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_12) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":527
 *                 else:
 *                     if until_eof:
 *                         return IteratorRowAll( self )             # <<<<<<<<<<<<<<
 *                     else:
 *                         # return all targets by chaining the individual targets together.
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_v_self);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_self);
          __Pyx_GIVEREF(__pyx_v_self);
          __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRowAll)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_r = __pyx_t_1;
          __pyx_t_1 = 0;
          goto __pyx_L0;
          goto __pyx_L13;
        }
        /*else*/ {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":530
 *                     else:
 *                         # return all targets by chaining the individual targets together.
 *                         if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
 *                         i = []
 *                         rstart = 0
 */
          __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_3 = (!__pyx_t_12);
          if (__pyx_t_3) {
            __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_INCREF(((PyObject *)__pyx_kp_s_28));
            PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_28));
            __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28));
            __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_Raise(__pyx_t_1, 0, 0);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            goto __pyx_L14;
          }
          __pyx_L14:;

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":531
 *                         # return all targets by chaining the individual targets together.
 *                         if not self._hasIndex(): raise ValueError( "no index available for fetch" )
 *                         i = []             # <<<<<<<<<<<<<<
 *                         rstart = 0
 *                         rend = 1<<29
 */
          __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_1));
          __Pyx_DECREF(((PyObject *)__pyx_v_i));
          __pyx_v_i = __pyx_t_1;
          __pyx_t_1 = 0;

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":532
 *                         if not self._hasIndex(): raise ValueError( "no index available for fetch" )
 *                         i = []
 *                         rstart = 0             # <<<<<<<<<<<<<<
 *                         rend = 1<<29
 *                         for rtid from 0 <= rtid < self.nreferences:
 */
          __pyx_v_rstart = 0;

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":533
 *                         i = []
 *                         rstart = 0
 *                         rend = 1<<29             # <<<<<<<<<<<<<<
 *                         for rtid from 0 <= rtid < self.nreferences:
 *                             i.append( IteratorRow( self, rtid, rstart, rend))
 */
          __pyx_v_rend = 536870912;

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":534
 *                         rstart = 0
 *                         rend = 1<<29
 *                         for rtid from 0 <= rtid < self.nreferences:             # <<<<<<<<<<<<<<
 *                             i.append( IteratorRow( self, rtid, rstart, rend))
 *                         return itertools.chain( *i )
 */
          __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__nreferences); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          for (__pyx_v_rtid = 0; __pyx_v_rtid < __pyx_t_8; __pyx_v_rtid++) {

            /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":535
 *                         rend = 1<<29
 *                         for rtid from 0 <= rtid < self.nreferences:
 *                             i.append( IteratorRow( self, rtid, rstart, rend))             # <<<<<<<<<<<<<<
 *                         return itertools.chain( *i )
 *         else:
 */
            if (unlikely(__pyx_v_i == Py_None)) {
              PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
            }
            __pyx_t_1 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_5 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_INCREF(__pyx_v_self);
            PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_self);
            __Pyx_GIVEREF(__pyx_v_self);
            PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_6);
            __Pyx_GIVEREF(__pyx_t_6);
            PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_5);
            __pyx_t_1 = 0;
            __pyx_t_6 = 0;
            __pyx_t_5 = 0;
            __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRow)), __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __pyx_t_9 = PyList_Append(((PyObject *)__pyx_v_i), __pyx_t_5); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":536
 *                         for rtid from 0 <= rtid < self.nreferences:
 *                             i.append( IteratorRow( self, rtid, rstart, rend))
 *                         return itertools.chain( *i )             # <<<<<<<<<<<<<<
 *         else:
 *             # check if header is present - otherwise sam_read1 aborts
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__itertools); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_7 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__chain); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = PySequence_Tuple(((PyObject *)__pyx_v_i)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_5));
          __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
          __pyx_r = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L0;
        }
        __pyx_L13:;
      }
      __pyx_L12:;
    }
    __pyx_L9:;
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":540
 *             # check if header is present - otherwise sam_read1 aborts
 *             # this happens if a bamfile is opened with mode 'r'
 *             if self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError( "fetch called for samfile without header")
 * 
 */
    __pyx_t_3 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets == 0);
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":541
 *             # this happens if a bamfile is opened with mode 'r'
 *             if self.samfile.header.n_targets == 0:
 *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
 * 
 *             if region != None:
 */
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_29));
      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_29));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_29));
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L17;
    }
    __pyx_L17:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":543
 *                 raise ValueError( "fetch called for samfile without header")
 * 
 *             if region != None:             # <<<<<<<<<<<<<<
 *                 raise ValueError ("fetch for a region is not available for sam files" )
 *             if callback:
 */
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_region, Py_None, Py_NE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":544
 * 
 *             if region != None:
 *                 raise ValueError ("fetch for a region is not available for sam files" )             # <<<<<<<<<<<<<<
 *             if callback:
 *                 raise NotImplementedError( "callback not implemented yet" )
 */
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_30));
      PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_30));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_30));
      __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_6, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L18;
    }
    __pyx_L18:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":545
 *             if region != None:
 *                 raise ValueError ("fetch for a region is not available for sam files" )
 *             if callback:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError( "callback not implemented yet" )
 *             else:
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":546
 *                 raise ValueError ("fetch for a region is not available for sam files" )
 *             if callback:
 *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
 *             else:
 *                 return IteratorRowAll( self )
 */
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_31));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
      __pyx_t_5 = PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L19;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":548
 *                 raise NotImplementedError( "callback not implemented yet" )
 *             else:
 *                 return IteratorRowAll( self )             # <<<<<<<<<<<<<<
 * 
 *     def pileup( self, reference = None, start = None, end = None, region = None, callback = None ):
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_self);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_self);
      __Pyx_GIVEREF(__pyx_v_self);
      __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRowAll)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;
    }
    __pyx_L19:;
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.fetch");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF(__pyx_v_region);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":550
 *                 return IteratorRowAll( self )
 * 
 *     def pileup( self, reference = None, start = None, end = None, region = None, callback = None ):             # <<<<<<<<<<<<<<
 *         '''run a pileup within a :term:`region` using 0-based indexing. The region is specified by
 *         :term:`reference`, *start* and *end*. Alternatively, a samtools *region* string can be supplied.
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_pileup[] = "Samfile.pileup(self, reference=None, start=None, end=None, region=None, callback=None)\nrun a pileup within a :term:`region` using 0-based indexing. The region is specified by\n        :term:`reference`, *start* and *end*. Alternatively, a samtools *region* string can be supplied.\n\n        Without *reference* or *region* all reads will be fetched. The reads will be returned\n        ordered by :term:`reference` sequence, which will not necessarily be the order within the file.\n\n        The method returns an iterator of type :class:`pysam.IteratorColumn` unless\n        a *callback is provided. If *callback* is given, the callback will be executed \n        for each position within the :term:`region`. \n\n        Note that samfiles do not allow random access. If *region* or *reference* are given,\n        an exception is raised.\n        \n        .. Note::\n\n            *all* reads which overlap the region are returned. The first base returned will be the \n            first base of the first read *not* necessarily the first base of the region used in the query.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_callback = 0;
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  bam_plbuf_t *__pyx_v_buf;
  PyObject *__pyx_v_i;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,&__pyx_n_s__callback,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("pileup");
  __Pyx_TraceCall("pileup", __pyx_f[0], 550);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
        if (value) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
        if (value) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
        if (value) { values[4] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_callback = values[4];
  } else {
    __pyx_v_reference = ((PyObject *)Py_None);
    __pyx_v_start = ((PyObject *)Py_None);
    __pyx_v_end = ((PyObject *)Py_None);
    __pyx_v_region = ((PyObject *)Py_None);
    __pyx_v_callback = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.pileup");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_region);
  __pyx_v_i = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":574
 *         cdef bam_plbuf_t *buf
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":575
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":577
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
 * 
 *         if self.isbam:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_reference);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
  __Pyx_GIVEREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  __pyx_t_5 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyTuple_CheckExact(__pyx_t_5) && likely(PyTuple_GET_SIZE(__pyx_t_5) == 4)) {
    PyObject* tuple = __pyx_t_5;
    __pyx_t_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = PyTuple_GET_ITEM(tuple, 3); __Pyx_INCREF(__pyx_t_7);
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_v_region);
    __pyx_v_region = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_v_rtid = __pyx_t_8;
    __pyx_v_rstart = __pyx_t_9;
    __pyx_v_rend = __pyx_t_10;
  } else {
    __pyx_t_11 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_11, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_11, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_11, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_11, 3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__Pyx_EndUnpack(__pyx_t_11, 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_v_region);
    __pyx_v_region = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_v_rtid = __pyx_t_10;
    __pyx_v_rstart = __pyx_t_9;
    __pyx_v_rend = __pyx_t_8;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":579
 *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
 * 
 *         if self.isbam:             # <<<<<<<<<<<<<<
 *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
 * 
 */
  if (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->isbam) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":580
 * 
 *         if self.isbam:
 *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
 * 
 *             if callback:
 */
    __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_3 = (!__pyx_t_4);
    if (__pyx_t_3) {
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_32));
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_32));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_32));
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":582
 *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
 * 
 *             if callback:             # <<<<<<<<<<<<<<
 *                 if not region:
 *                     raise ValueError( "callback functionality requires a region/reference" )
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_3) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":583
 * 
 *             if callback:
 *                 if not region:             # <<<<<<<<<<<<<<
 *                     raise ValueError( "callback functionality requires a region/reference" )
 * 
 */
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = (!__pyx_t_3);
      if (__pyx_t_4) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":584
 *             if callback:
 *                 if not region:
 *                     raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
 * 
 *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )
 */
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(((PyObject *)__pyx_kp_s_27));
        PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_27));
        __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27));
        __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_7, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":586
 *                     raise ValueError( "callback functionality requires a region/reference" )
 * 
 *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )             # <<<<<<<<<<<<<<
 *                 bam_fetch(self.samfile.x.bam,
 *                           self.index, rtid, rstart, rend,
 */
      __pyx_v_buf = bam_plbuf_init(((bam_pileup_f)__pyx_f_11chimerascan_5pysam_9csamtools_pileup_callback), ((void *)__pyx_v_callback));

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":589
 *                 bam_fetch(self.samfile.x.bam,
 *                           self.index, rtid, rstart, rend,
 *                           buf, pileup_fetch_callback )             # <<<<<<<<<<<<<<
 * 
 *                 # finalize pileup
 */
      bam_fetch(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, __pyx_v_buf, __pyx_f_11chimerascan_5pysam_9csamtools_pileup_fetch_callback);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":592
 * 
 *                 # finalize pileup
 *                 bam_plbuf_push( NULL, buf)             # <<<<<<<<<<<<<<
 *                 bam_plbuf_destroy(buf)
 *             else:
 */
      bam_plbuf_push(NULL, __pyx_v_buf);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":593
 *                 # finalize pileup
 *                 bam_plbuf_push( NULL, buf)
 *                 bam_plbuf_destroy(buf)             # <<<<<<<<<<<<<<
 *             else:
 *                 if region:
 */
      bam_plbuf_destroy(__pyx_v_buf);
      goto __pyx_L9;
    }
    /*else*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":595
 *                 bam_plbuf_destroy(buf)
 *             else:
 *                 if region:             # <<<<<<<<<<<<<<
 *                     return IteratorColumn( self, rtid, rstart, rend )
 *                 else:
 */
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_4) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":596
 *             else:
 *                 if region:
 *                     return IteratorColumn( self, rtid, rstart, rend )             # <<<<<<<<<<<<<<
 *                 else:
 *                     # return all targets by chaining the individual targets together.
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_7 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_5 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
        __Pyx_GIVEREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_7 = 0;
        __pyx_t_5 = 0;
        __pyx_t_6 = 0;
        __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorColumn)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_6;
        __pyx_t_6 = 0;
        goto __pyx_L0;
        goto __pyx_L11;
      }
      /*else*/ {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":599
 *                 else:
 *                     # return all targets by chaining the individual targets together.
 *                     i = []             # <<<<<<<<<<<<<<
 *                     rstart = 0
 *                     rend = 1<<29
 */
        __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_6));
        __Pyx_DECREF(((PyObject *)__pyx_v_i));
        __pyx_v_i = __pyx_t_6;
        __pyx_t_6 = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":600
 *                     # return all targets by chaining the individual targets together.
 *                     i = []
 *                     rstart = 0             # <<<<<<<<<<<<<<
 *                     rend = 1<<29
 *                     for rtid from 0 <= rtid < self.nreferences:
 */
        __pyx_v_rstart = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":601
 *                     i = []
 *                     rstart = 0
 *                     rend = 1<<29             # <<<<<<<<<<<<<<
 *                     for rtid from 0 <= rtid < self.nreferences:
 *                         i.append( IteratorColumn( self, rtid, rstart, rend))
 */
        __pyx_v_rend = 536870912;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":602
 *                     rstart = 0
 *                     rend = 1<<29
 *                     for rtid from 0 <= rtid < self.nreferences:             # <<<<<<<<<<<<<<
 *                         i.append( IteratorColumn( self, rtid, rstart, rend))
 *                     return itertools.chain( *i )
 */
        __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__nreferences); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        for (__pyx_v_rtid = 0; __pyx_v_rtid < __pyx_t_8; __pyx_v_rtid++) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":603
 *                     rend = 1<<29
 *                     for rtid from 0 <= rtid < self.nreferences:
 *                         i.append( IteratorColumn( self, rtid, rstart, rend))             # <<<<<<<<<<<<<<
 *                     return itertools.chain( *i )
 * 
 */
          if (unlikely(__pyx_v_i == Py_None)) {
            PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
          }
          __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_1 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_5 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_INCREF(__pyx_v_self);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_self);
          __Pyx_GIVEREF(__pyx_v_self);
          PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_5);
          __pyx_t_6 = 0;
          __pyx_t_1 = 0;
          __pyx_t_5 = 0;
          __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorColumn)), __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_9 = PyList_Append(((PyObject *)__pyx_v_i), __pyx_t_5); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":604
 *                     for rtid from 0 <= rtid < self.nreferences:
 *                         i.append( IteratorColumn( self, rtid, rstart, rend))
 *                     return itertools.chain( *i )             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__itertools); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__chain); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PySequence_Tuple(((PyObject *)__pyx_v_i)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_5));
        __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
        __pyx_r = __pyx_t_1;
        __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      __pyx_L11:;
    }
    __pyx_L9:;
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":607
 * 
 *         else:
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
 * 
 *     def close( self ):
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_33));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_33));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_33));
    __pyx_t_5 = PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.pileup");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_i);
  __Pyx_DECREF(__pyx_v_region);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":609
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         '''closes file.'''
 *         if self.samfile != NULL:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_close[] = "Samfile.close(self)\ncloses file.";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("close");
  __Pyx_TraceCall("close", __pyx_f[0], 609);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":611
 *     def close( self ):
 *         '''closes file.'''
 *         if self.samfile != NULL:             # <<<<<<<<<<<<<<
 *             samclose( self.samfile )
 *             bam_index_destroy(self.index);
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile != NULL);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":612
 *         '''closes file.'''
 *         if self.samfile != NULL:
 *             samclose( self.samfile )             # <<<<<<<<<<<<<<
 *             bam_index_destroy(self.index);
 *             self.samfile = NULL
 */
    samclose(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":613
 *         if self.samfile != NULL:
 *             samclose( self.samfile )
 *             bam_index_destroy(self.index);             # <<<<<<<<<<<<<<
 *             self.samfile = NULL
 * 
 */
    bam_index_destroy(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->index);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":614
 *             samclose( self.samfile )
 *             bam_index_destroy(self.index);
 *             self.samfile = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__( self ):
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile = NULL;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":616
 *             self.samfile = NULL
 * 
 *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
 *         # remember: dealloc cannot call other methods
 *         # note: no doc string
 */

static void __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___dealloc__(PyObject *__pyx_v_self) {
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 616);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":620
 *         # note: no doc string
 *         # note: __del__ is not called.
 *         self.close()             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":621
 *         # note: __del__ is not called.
 *         self.close()
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 * 
 *     def write( self, AlignedRead read ):
 */
  bam_destroy1(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->b);

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.__dealloc__");
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":623
 *         bam_destroy1(self.b)
 * 
 *     def write( self, AlignedRead read ):             # <<<<<<<<<<<<<<
 *         '''(AlignedRead read )
 *         write a single :class:`pysam.AlignedRead`..
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_write[] = "Samfile.write(self, AlignedRead read)\n(AlignedRead read )\n        write a single :class:`pysam.AlignedRead`..\n\n        return the number of bytes written.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("write");
  __Pyx_TraceCall("write", __pyx_f[0], 623);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_11chimerascan_5pysam_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":629
 *         return the number of bytes written.
 *         '''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":630
 *         '''
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         return samwrite( self.samfile, read._delegate )
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":632
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         return samwrite( self.samfile, read._delegate )             # <<<<<<<<<<<<<<
 * 
 *     def __enter__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(samwrite(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_read)->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":634
 *         return samwrite( self.samfile, read._delegate )
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___enter__[] = "Samfile.__enter__(self)";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__enter__");
  __Pyx_TraceCall("__enter__", __pyx_f[0], 634);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":635
 * 
 *     def __enter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":637
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___exit__[] = "Samfile.__exit__(self, exc_type, exc_value, traceback)";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_exc_type = 0;
  PyObject *__pyx_v_exc_value = 0;
  PyObject *__pyx_v_traceback = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__exc_type,&__pyx_n_s__exc_value,&__pyx_n_s__traceback,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__exit__");
  __Pyx_TraceCall("__exit__", __pyx_f[0], 637);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_type);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_value);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__traceback);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_exc_type = values[0];
    __pyx_v_exc_value = values[1];
    __pyx_v_traceback = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_exc_type = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_exc_value = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_traceback = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.__exit__");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":638
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()             # <<<<<<<<<<<<<<
 *         return False
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":639
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()
 *         return False             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.__exit__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":643
 *     property nreferences:
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             return self.samfile.header.n_targets
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_11nreferences___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_11nreferences___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 643);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":644
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             return self.samfile.header.n_targets
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":645
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             return self.samfile.header.n_targets             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.nreferences.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":649
 *     property references:
 *         """tuple with the names of :term:`reference` sequences."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_10references___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_10references___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_t;
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int32_t __pyx_t_5;
  int __pyx_t_6;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 649);
  __pyx_v_t = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":650
 *         """tuple with the names of :term:`reference` sequences."""
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.samfile.header.n_targets:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":651
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []             # <<<<<<<<<<<<<<
 *             for x from 0 <= x < self.samfile.header.n_targets:
 *                 t.append( self.samfile.header.target_name[x] )
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_t));
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":652
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
 *                 t.append( self.samfile.header.target_name[x] )
 *             return tuple(t)
 */
  __pyx_t_5 = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":653
 *             t = []
 *             for x from 0 <= x < self.samfile.header.n_targets:
 *                 t.append( self.samfile.header.target_name[x] )             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    if (unlikely(__pyx_v_t == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_1 = PyBytes_FromString((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __pyx_t_6 = PyList_Append(((PyObject *)__pyx_v_t), ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":654
 *             for x from 0 <= x < self.samfile.header.n_targets:
 *                 t.append( self.samfile.header.target_name[x] )
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(__pyx_v_t == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.references.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":659
 *         """tuple of the lengths of the :term:`reference` sequences. The lengths are in the same order as :attr:`pysam.Samfile.reference`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_7lengths___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_7lengths___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_t;
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int32_t __pyx_t_5;
  int __pyx_t_6;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 659);
  __pyx_v_t = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":660
 *         """
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.samfile.header.n_targets:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":661
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []             # <<<<<<<<<<<<<<
 *             for x from 0 <= x < self.samfile.header.n_targets:
 *                 t.append( self.samfile.header.target_len[x] )
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_t));
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":662
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
 *                 t.append( self.samfile.header.target_len[x] )
 *             return tuple(t)
 */
  __pyx_t_5 = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":663
 *             t = []
 *             for x from 0 <= x < self.samfile.header.n_targets:
 *                 t.append( self.samfile.header.target_len[x] )             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    if (unlikely(__pyx_v_t == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = PyList_Append(((PyObject *)__pyx_v_t), __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":664
 *             for x from 0 <= x < self.samfile.header.n_targets:
 *                 t.append( self.samfile.header.target_len[x] )
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     property text:
 */
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(__pyx_v_t == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
  }
  __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.lengths.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":668
 *     property text:
 *         '''full contents of the :term:`sam file` header as a string.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_4text___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_4text___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 668);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":669
 *         '''full contents of the :term:`sam file` header as a string.'''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":670
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)             # <<<<<<<<<<<<<<
 * 
 *     property header:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyString_FromStringAndSize(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->text, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->l_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.text.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":676
 *         a two-level dictionary.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_6header___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_6header___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_v_result;
  PyObject *__pyx_v_t;
  PyObject *__pyx_v_line;
  PyObject *__pyx_v_fields;
  PyObject *__pyx_v_record;
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_field;
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_value;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 676);
  __pyx_v_result = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_line = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_fields = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_record = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_x = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_field = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":677
 *         '''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *             result = {}
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":679
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 * 
 *             result = {}             # <<<<<<<<<<<<<<
 * 
 *             if self.samfile.header.text != NULL:
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_result));
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":681
 *             result = {}
 * 
 *             if self.samfile.header.text != NULL:             # <<<<<<<<<<<<<<
 *                 # convert to python string (note: call self.text to create 0-terminated string)
 *                 t = self.text
 */
  __pyx_t_4 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile->header->text != NULL);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":683
 *             if self.samfile.header.text != NULL:
 *                 # convert to python string (note: call self.text to create 0-terminated string)
 *                 t = self.text             # <<<<<<<<<<<<<<
 *                 for line in t.split("\n"):
 *                     if not line.strip(): continue
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_v_t);
    __pyx_v_t = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":684
 *                 # convert to python string (note: call self.text to create 0-terminated string)
 *                 t = self.text
 *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), "header line without '@': '%s'" % line
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_t, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_2));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2));
    __pyx_t_6 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
      __pyx_t_5 = 0; __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2);
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++;
      } else {
        __pyx_t_6 = PyIter_Next(__pyx_t_2);
        if (!__pyx_t_6) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_DECREF(__pyx_v_line);
      __pyx_v_line = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":685
 *                 t = self.text
 *                 for line in t.split("\n"):
 *                     if not line.strip(): continue             # <<<<<<<<<<<<<<
 *                     assert line.startswith("@"), "header line without '@': '%s'" % line
 *                     fields = line[1:].split("\t")
 */
      __pyx_t_6 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_3 = (!__pyx_t_4);
      if (__pyx_t_3) {
        goto __pyx_L7_continue;
        goto __pyx_L9;
      }
      __pyx_L9:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":686
 *                 for line in t.split("\n"):
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
 *                     fields = line[1:].split("\t")
 *                     record = fields[0]
 */
      #ifndef PYREX_WITHOUT_ASSERTIONS
      __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_34));
      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_34));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_34));
      __pyx_t_7 = PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_3)) {
        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_35), __pyx_v_line); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_7));
        PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_7));
        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":687
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), "header line without '@': '%s'" % line
 *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
 *                     record = fields[0]
 *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
 */
      __pyx_t_7 = PySequence_GetSlice(__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__split); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
      __pyx_t_1 = PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_v_fields);
      __pyx_v_fields = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":688
 *                     assert line.startswith("@"), "header line without '@': '%s'" % line
 *                     fields = line[1:].split("\t")
 *                     record = fields[0]             # <<<<<<<<<<<<<<
 *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
 * 
 */
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_fields, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_v_record);
      __pyx_v_record = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":689
 *                     fields = line[1:].split("\t")
 *                     record = fields[0]
 *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
 * 
 *                     # treat comments
 */
      #ifndef PYREX_WITHOUT_ASSERTIONS
      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = ((PySequence_Contains(__pyx_t_1, __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_3)) {
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __Pyx_INCREF(__pyx_v_line);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_line);
        __Pyx_GIVEREF(__pyx_v_line);
        __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_36), __pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_7));
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_7));
        __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #endif

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":692
 * 
 *                     # treat comments
 *                     if record == "CO":             # <<<<<<<<<<<<<<
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )
 */
      __pyx_t_7 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_3) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":693
 *                     # treat comments
 *                     if record == "CO":
 *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                         result[record].append( "\t".join( fields[1:] ) )
 *                         continue
 */
        if (unlikely(((PyObject *)__pyx_v_result) == Py_None)) {
          __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        } else {
          __pyx_t_3 = (__Pyx_NegateNonNeg(PyDict_Contains(((PyObject *)__pyx_v_result), __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        if (__pyx_t_3) {
          __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_7));
          if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_7)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
          goto __pyx_L11;
        }
        __pyx_L11:;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":694
 *                     if record == "CO":
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )             # <<<<<<<<<<<<<<
 *                         continue
 * 
 */
        __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_6 = PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_6 = PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":695
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )
 *                         continue             # <<<<<<<<<<<<<<
 * 
 *                     # the following is clumsy as generators do not work?
 */
        goto __pyx_L7_continue;
        goto __pyx_L10;
      }
      __pyx_L10:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":698
 * 
 *                     # the following is clumsy as generators do not work?
 *                     x = {}             # <<<<<<<<<<<<<<
 *                     for field in fields[1:]:
 *                         key, value = field.split(":",1)
 */
      __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      __Pyx_DECREF(((PyObject *)__pyx_v_x));
      __pyx_v_x = __pyx_t_8;
      __pyx_t_8 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":699
 *                     # the following is clumsy as generators do not work?
 *                     x = {}
 *                     for field in fields[1:]:             # <<<<<<<<<<<<<<
 *                         key, value = field.split(":",1)
 *                         if key not in VALID_HEADER_FIELDS[record]:
 */
      __pyx_t_8 = PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      if (PyList_CheckExact(__pyx_t_8) || PyTuple_CheckExact(__pyx_t_8)) {
        __pyx_t_9 = 0; __pyx_t_6 = __pyx_t_8; __Pyx_INCREF(__pyx_t_6);
      } else {
        __pyx_t_9 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (;;) {
        if (likely(PyList_CheckExact(__pyx_t_6))) {
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_6)) break;
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_8); __pyx_t_9++;
        } else if (likely(PyTuple_CheckExact(__pyx_t_6))) {
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_8); __pyx_t_9++;
        } else {
          __pyx_t_8 = PyIter_Next(__pyx_t_6);
          if (!__pyx_t_8) {
            if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            break;
          }
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_DECREF(__pyx_v_field);
        __pyx_v_field = __pyx_t_8;
        __pyx_t_8 = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":700
 *                     x = {}
 *                     for field in fields[1:]:
 *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
 *                         if key not in VALID_HEADER_FIELDS[record]:
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
 */
        __pyx_t_8 = PyObject_GetAttr(__pyx_v_field, __pyx_n_s__split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(((PyObject *)__pyx_kp_s_37));
        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_37));
        __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_37));
        __Pyx_INCREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        __pyx_t_1 = PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
          PyObject* tuple = __pyx_t_1;
          __pyx_t_7 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_7);
          __pyx_t_8 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_v_key);
          __pyx_v_key = __pyx_t_7;
          __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_v_value);
          __pyx_v_value = __pyx_t_8;
          __pyx_t_8 = 0;
        } else {
          __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_10, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_10, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          if (__Pyx_EndUnpack(__pyx_t_10, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_v_key);
          __pyx_v_key = __pyx_t_7;
          __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_v_value);
          __pyx_v_value = __pyx_t_8;
          __pyx_t_8 = 0;
        }

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":701
 *                     for field in fields[1:]:
 *                         key, value = field.split(":",1)
 *                         if key not in VALID_HEADER_FIELDS[record]:             # <<<<<<<<<<<<<<
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
 *                         x[key] = VALID_HEADER_FIELDS[record][key](value)
 */
        __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_3 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_t_8, __pyx_v_key))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__pyx_t_3) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":702
 *                         key, value = field.split(":",1)
 *                         if key not in VALID_HEADER_FIELDS[record]:
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )             # <<<<<<<<<<<<<<
 *                         x[key] = VALID_HEADER_FIELDS[record][key](value)
 * 
 */
          __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_INCREF(__pyx_v_key);
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_key);
          __Pyx_GIVEREF(__pyx_v_key);
          __Pyx_INCREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_38), __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_1));
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_1));
          __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
          __pyx_t_1 = 0;
          __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_Raise(__pyx_t_1, 0, 0);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L14;
        }
        __pyx_L14:;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":703
 *                         if key not in VALID_HEADER_FIELDS[record]:
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
 *                         x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:
 */
        __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyObject_GetItem(__pyx_t_8, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        __pyx_t_7 = PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":705
 *                         x[key] = VALID_HEADER_FIELDS[record][key](value)
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:             # <<<<<<<<<<<<<<
 *                         if record in result:
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
 */
      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyObject_GetItem(__pyx_t_6, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_7, ((PyObject *)((PyObject*)&PyDict_Type)), Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_3) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":706
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:
 *                         if record in result:             # <<<<<<<<<<<<<<
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
 *                         result[record] = x
 */
        if (unlikely(((PyObject *)__pyx_v_result) == Py_None)) {
          __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        } else {
          __pyx_t_3 = ((PyDict_Contains(((PyObject *)__pyx_v_result), __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        if (__pyx_t_3) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":707
 *                     if VALID_HEADER_TYPES[record] == dict:
 *                         if record in result:
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )             # <<<<<<<<<<<<<<
 *                         result[record] = x
 *                     elif VALID_HEADER_TYPES[record] == list:
 */
          __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), __pyx_v_record); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_6));
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6));
          __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
          __pyx_t_6 = 0;
          __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_Raise(__pyx_t_6, 0, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L16;
        }
        __pyx_L16:;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":708
 *                         if record in result:
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
 *                         result[record] = x             # <<<<<<<<<<<<<<
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []
 */
        if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_v_x)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L15;
      }

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":709
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
 *                         result[record] = x
 *                     elif VALID_HEADER_TYPES[record] == list:             # <<<<<<<<<<<<<<
 *                         if record not in result: result[record] = []
 *                         result[record].append( x )
 */
      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyObject_GetItem(__pyx_t_6, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_7, ((PyObject *)((PyObject*)&PyList_Type)), Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_3) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":710
 *                         result[record] = x
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                         result[record].append( x )
 * 
 */
        if (unlikely(((PyObject *)__pyx_v_result) == Py_None)) {
          __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        } else {
          __pyx_t_3 = (__Pyx_NegateNonNeg(PyDict_Contains(((PyObject *)__pyx_v_result), __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        if (__pyx_t_3) {
          __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_6));
          if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_6)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
          goto __pyx_L17;
        }
        __pyx_L17:;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":711
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []
 *                         result[record].append( x )             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
        __pyx_t_6 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_Append(__pyx_t_6, ((PyObject *)__pyx_v_x)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L15;
      }
      __pyx_L15:;
      __pyx_L7_continue:;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":713
 *                         result[record].append( x )
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     def _buildLine( self, fields, record ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.header.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_DECREF(__pyx_v_line);
  __Pyx_DECREF(__pyx_v_fields);
  __Pyx_DECREF(__pyx_v_record);
  __Pyx_DECREF(__pyx_v_x);
  __Pyx_DECREF(__pyx_v_field);
  __Pyx_DECREF(__pyx_v_key);
  __Pyx_DECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":715
 *             return result
 * 
 *     def _buildLine( self, fields, record ):             # <<<<<<<<<<<<<<
 *         '''build a header line from *fields* dictionary for *record*'''
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__buildLine[] = "Samfile._buildLine(self, fields, record)\nbuild a header line from *fields* dictionary for *record*";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_record = 0;
  PyObject *__pyx_v_line;
  PyObject *__pyx_v_key;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fields,&__pyx_n_s__record,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_buildLine");
  __Pyx_TraceCall("_buildLine", __pyx_f[0], 715);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fields);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__record);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_fields = values[0];
    __pyx_v_record = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_fields = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_record = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._buildLine");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_line = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":719
 * 
 *         # TODO: add checking for field and sort order
 *         line = ["@%s" % record ]             # <<<<<<<<<<<<<<
 *         if record == "CO":
 *             line.append( fields )
 */
  __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
  __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_v_line));
  __pyx_v_line = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":720
 *         # TODO: add checking for field and sort order
 *         line = ["@%s" % record ]
 *         if record == "CO":             # <<<<<<<<<<<<<<
 *             line.append( fields )
 *         else:
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":721
 *         line = ["@%s" % record ]
 *         if record == "CO":
 *             line.append( fields )             # <<<<<<<<<<<<<<
 *         else:
 *             for key in VALID_HEADER_ORDER[record]:
 */
    if (unlikely(__pyx_v_line == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_line), __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":723
 *             line.append( fields )
 *         else:
 *             for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
 *                 if key in fields:
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_5 = 0; __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
      } else {
        __pyx_t_1 = PyIter_Next(__pyx_t_2);
        if (!__pyx_t_1) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_v_key);
      __pyx_v_key = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":724
 *         else:
 *             for key in VALID_HEADER_ORDER[record]:
 *                 if key in fields:             # <<<<<<<<<<<<<<
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 *         return "\t".join( line )
 */
      __pyx_t_3 = ((PySequence_Contains(__pyx_v_fields, __pyx_v_key))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_3) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":725
 *             for key in VALID_HEADER_ORDER[record]:
 *                 if key in fields:
 *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *         return "\t".join( line )
 * 
 */
        if (unlikely(__pyx_v_line == Py_None)) {
          PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
        }
        __pyx_t_1 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)&PyString_Type)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_41), __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_line), ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
        goto __pyx_L9;
      }
      __pyx_L9:;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":726
 *                 if key in fields:
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 *         return "\t".join( line )             # <<<<<<<<<<<<<<
 * 
 *     cdef bam_header_t * _buildHeader( self, new_header ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_line));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_line));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_line));
  __pyx_t_6 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._buildLine");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_line);
  __Pyx_DECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":728
 *         return "\t".join( line )
 * 
 *     cdef bam_header_t * _buildHeader( self, new_header ):             # <<<<<<<<<<<<<<
 *         '''return a new header built from a dictionary in *new_header*.
 * 
 */

static  bam_header_t *__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile__buildHeader(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_new_header) {
  PyObject *__pyx_v_lines;
  bam_header_t *__pyx_v_dest;
  PyObject *__pyx_v_record;
  PyObject *__pyx_v_ttype;
  PyObject *__pyx_v_data;
  PyObject *__pyx_v_fields;
  PyObject *__pyx_v_text;
  PyObject *__pyx_v_seqs;
  long __pyx_v_x;
  PyObject *__pyx_v_seqname;
  PyObject *__pyx_v_seqlen;
  bam_header_t *__pyx_r;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  char *__pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int32_t __pyx_t_12;
  uint32_t __pyx_t_13;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_buildHeader");
  __Pyx_TraceCall("_buildHeader", __pyx_f[0], 728);
  __pyx_v_lines = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_record = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_ttype = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_data = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_fields = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_text = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_seqs = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_seqname = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_seqlen = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":734
 *         '''
 * 
 *         lines = []             # <<<<<<<<<<<<<<
 * 
 *         # check if hash exists
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_lines));
  __pyx_v_lines = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":741
 *         cdef bam_header_t * dest
 * 
 *         dest = bam_header_init()             # <<<<<<<<<<<<<<
 * 
 *         for record in VALID_HEADERS:
 */
  __pyx_v_dest = bam_header_init();

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":743
 *         dest = bam_header_init()
 * 
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = 0; __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3);
  } else {
    __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_3))) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break;
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_3))) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
    } else {
      __pyx_t_1 = PyIter_Next(__pyx_t_3);
      if (!__pyx_t_1) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_v_record);
    __pyx_v_record = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":744
 * 
 *         for record in VALID_HEADERS:
 *             if record in new_header:             # <<<<<<<<<<<<<<
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]
 */
    __pyx_t_4 = ((PySequence_Contains(__pyx_v_new_header, __pyx_v_record))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_4) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":745
 *         for record in VALID_HEADERS:
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]             # <<<<<<<<<<<<<<
 *                 data = new_header[record]
 *                 if type( data ) != type( ttype() ):
 */
      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_ttype);
      __pyx_v_ttype = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":746
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]             # <<<<<<<<<<<<<<
 *                 if type( data ) != type( ttype() ):
 *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
 */
      __pyx_t_5 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_v_data);
      __pyx_v_data = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":747
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]
 *                 if type( data ) != type( ttype() ):             # <<<<<<<<<<<<<<
 *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
 *                 if type( data ) == types.DictType:
 */
      __pyx_t_5 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_5)), Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_4) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":748
 *                 data = new_header[record]
 *                 if type( data ) != type( ttype() ):
 *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )             # <<<<<<<<<<<<<<
 *                 if type( data ) == types.DictType:
 *                     lines.append( self._buildLine( data, record ) )
 */
        __pyx_t_1 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data)));
        PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)Py_TYPE(__pyx_v_data)));
        __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data)));
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_1)));
        PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)Py_TYPE(__pyx_t_1)));
        __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1)));
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_1));
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
        __pyx_t_1 = 0;
        __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":749
 *                 if type( data ) != type( ttype() ):
 *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
 *                 if type( data ) == types.DictType:             # <<<<<<<<<<<<<<
 *                     lines.append( self._buildLine( data, record ) )
 *                 else:
 */
      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__types); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__DictType); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_4) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":750
 *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
 *                 if type( data ) == types.DictType:
 *                     lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
 *                 else:
 *                     for fields in new_header[record]:
 */
        if (unlikely(__pyx_v_lines == Py_None)) {
          PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
        }
        __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_v_data);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_data);
        __Pyx_GIVEREF(__pyx_v_data);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __pyx_t_6 = PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = PyList_Append(((PyObject *)__pyx_v_lines), __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L7;
      }
      /*else*/ {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":752
 *                     lines.append( self._buildLine( data, record ) )
 *                 else:
 *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                         lines.append( self._buildLine( fields, record ) )
 * 
 */
        __pyx_t_6 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
          __pyx_t_8 = 0; __pyx_t_5 = __pyx_t_6; __Pyx_INCREF(__pyx_t_5);
        } else {
          __pyx_t_8 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_5);
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        for (;;) {
          if (likely(PyList_CheckExact(__pyx_t_5))) {
            if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_5)) break;
            __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++;
          } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
            if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
            __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++;
          } else {
            __pyx_t_6 = PyIter_Next(__pyx_t_5);
            if (!__pyx_t_6) {
              if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              break;
            }
            __Pyx_GOTREF(__pyx_t_6);
          }
          __Pyx_DECREF(__pyx_v_fields);
          __pyx_v_fields = __pyx_t_6;
          __pyx_t_6 = 0;

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":753
 *                 else:
 *                     for fields in new_header[record]:
 *                         lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
 * 
 *         text = "\n".join(lines) + "\n"
 */
          if (unlikely(__pyx_v_lines == Py_None)) {
            PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
          }
          __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___buildLine); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_INCREF(__pyx_v_fields);
          PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fields);
          __Pyx_GIVEREF(__pyx_v_fields);
          __Pyx_INCREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          __pyx_t_9 = PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_7 = PyList_Append(((PyObject *)__pyx_v_lines), __pyx_t_9); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_L7:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":755
 *                         lines.append( self._buildLine( fields, record ) )
 * 
 *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_2), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_lines));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_lines));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lines));
  __pyx_t_9 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Add(__pyx_t_9, ((PyObject *)__pyx_kp_s_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_v_text);
  __pyx_v_text = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":756
 * 
 *         text = "\n".join(lines) + "\n"
 *         if dest.text != NULL: free( dest.text )             # <<<<<<<<<<<<<<
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 */
  __pyx_t_4 = (__pyx_v_dest->text != NULL);
  if (__pyx_t_4) {
    free(__pyx_v_dest->text);
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":757
 *         text = "\n".join(lines) + "\n"
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))             # <<<<<<<<<<<<<<
 *         dest.l_text = len(text)
 *         strncpy( dest.text, text, dest.l_text )
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest->text = ((char *)calloc(__pyx_t_2, (sizeof(char))));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":758
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)             # <<<<<<<<<<<<<<
 *         strncpy( dest.text, text, dest.l_text )
 * 
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest->l_text = __pyx_t_2;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":759
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 *         strncpy( dest.text, text, dest.l_text )             # <<<<<<<<<<<<<<
 * 
 *         # collect targets
 */
  __pyx_t_10 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_dest->text, __pyx_t_10, __pyx_v_dest->l_text);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":762
 * 
 *         # collect targets
 *         if "SQ" in new_header:             # <<<<<<<<<<<<<<
 *             seqs = []
 *             for fields in new_header["SQ"]:
 */
  __pyx_t_4 = ((PySequence_Contains(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":763
 *         # collect targets
 *         if "SQ" in new_header:
 *             seqs = []             # <<<<<<<<<<<<<<
 *             for fields in new_header["SQ"]:
 *                 try:
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_DECREF(((PyObject *)__pyx_v_seqs));
    __pyx_v_seqs = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":764
 *         if "SQ" in new_header:
 *             seqs = []
 *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 */
    __pyx_t_5 = PyObject_GetItem(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (PyList_CheckExact(__pyx_t_5) || PyTuple_CheckExact(__pyx_t_5)) {
      __pyx_t_2 = 0; __pyx_t_9 = __pyx_t_5; __Pyx_INCREF(__pyx_t_9);
    } else {
      __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_9))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_9)) break;
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_9))) {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++;
      } else {
        __pyx_t_5 = PyIter_Next(__pyx_t_9);
        if (!__pyx_t_5) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_DECREF(__pyx_v_fields);
      __pyx_v_fields = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":765
 *             seqs = []
 *             for fields in new_header["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:
 */
      {
        PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
        __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
        __Pyx_XGOTREF(__pyx_save_exc_type);
        __Pyx_XGOTREF(__pyx_save_exc_value);
        __Pyx_XGOTREF(__pyx_save_exc_tb);
        /*try:*/ {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":766
 *             for fields in new_header["SQ"]:
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 */
          if (unlikely(__pyx_v_seqs == Py_None)) {
            PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L14_error;} 
          }
          __pyx_t_5 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__SN)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_3 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__LN)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_GOTREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_3);
          __pyx_t_5 = 0;
          __pyx_t_3 = 0;
          __pyx_t_7 = PyList_Append(((PyObject *)__pyx_v_seqs), __pyx_t_1); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
        __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
        __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
        goto __pyx_L21_try_end;
        __pyx_L14_error:;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":767
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_7) {
          __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile._buildHeader");
          if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_5);

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":768
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *             dest.n_targets = len(seqs)
 */
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_v_fields);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fields);
          __Pyx_GIVEREF(__pyx_v_fields);
          __pyx_t_11 = PyObject_Call(((PyObject *)((PyObject*)&PyString_Type)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), __pyx_t_11); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_6));
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_11);
          PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_6));
          __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
          __pyx_t_6 = 0;
          __pyx_t_6 = PyObject_Call(__pyx_builtin_KeyError, __pyx_t_11, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_Raise(__pyx_t_6, 0, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          goto __pyx_L15_exception_handled;
        }
        __pyx_L16_except_error:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        goto __pyx_L1_error;
        __pyx_L15_exception_handled:;
        __Pyx_XGIVEREF(__pyx_save_exc_type);
        __Pyx_XGIVEREF(__pyx_save_exc_value);
        __Pyx_XGIVEREF(__pyx_save_exc_tb);
        __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
        __pyx_L21_try_end:;
      }
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":770
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 * 
 *             dest.n_targets = len(seqs)             # <<<<<<<<<<<<<<
 *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
 *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
 */
    if (unlikely(__pyx_v_seqs == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_2 = PyList_GET_SIZE(((PyObject *)__pyx_v_seqs)); 
    __pyx_v_dest->n_targets = __pyx_t_2;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":771
 * 
 *             dest.n_targets = len(seqs)
 *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )             # <<<<<<<<<<<<<<
 *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
 * 
 */
    __pyx_v_dest->target_name = ((char **)calloc(__pyx_v_dest->n_targets, (sizeof(char *))));

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":772
 *             dest.n_targets = len(seqs)
 *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
 *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )             # <<<<<<<<<<<<<<
 * 
 *             for x from 0 <= x < dest.n_targets:
 */
    __pyx_v_dest->target_len = ((uint32_t *)calloc(__pyx_v_dest->n_targets, (sizeof(uint32_t))));

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":774
 *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
 * 
 *             for x from 0 <= x < dest.n_targets:             # <<<<<<<<<<<<<<
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 */
    __pyx_t_12 = __pyx_v_dest->n_targets;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_12; __pyx_v_x++) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":775
 * 
 *             for x from 0 <= x < dest.n_targets:
 *                 seqname, seqlen = seqs[x]             # <<<<<<<<<<<<<<
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )
 */
      __pyx_t_9 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_seqs), __pyx_v_x, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      if (PyTuple_CheckExact(__pyx_t_9) && likely(PyTuple_GET_SIZE(__pyx_t_9) == 2)) {
        PyObject* tuple = __pyx_t_9;
        __pyx_t_5 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_5);
        __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_v_seqname);
        __pyx_v_seqname = __pyx_t_5;
        __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_v_seqlen);
        __pyx_v_seqlen = __pyx_t_3;
        __pyx_t_3 = 0;
      } else {
        __pyx_t_1 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_5 = __Pyx_UnpackItem(__pyx_t_1, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        if (__Pyx_EndUnpack(__pyx_t_1, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_v_seqname);
        __pyx_v_seqname = __pyx_t_5;
        __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_v_seqlen);
        __pyx_v_seqlen = __pyx_t_3;
        __pyx_t_3 = 0;
      }

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":776
 *             for x from 0 <= x < dest.n_targets:
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )             # <<<<<<<<<<<<<<
 *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )
 *                 dest.target_len[x] = seqlen
 */
      __pyx_t_2 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_2 + 1), (sizeof(char))));

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":777
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )             # <<<<<<<<<<<<<<
 *                 dest.target_len[x] = seqlen
 * 
 */
      __pyx_t_10 = PyBytes_AsString(__pyx_v_seqname); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_10, (__pyx_t_2 + 1));

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":778
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )
 *                 dest.target_len[x] = seqlen             # <<<<<<<<<<<<<<
 * 
 *         return dest
 */
      __pyx_t_13 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_13 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_13;
    }
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":780
 *                 dest.target_len[x] = seqlen
 * 
 *         return dest             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_r = __pyx_v_dest;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_WriteUnraisable("chimerascan.pysam.csamtools.Samfile._buildHeader");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_lines);
  __Pyx_DECREF(__pyx_v_record);
  __Pyx_DECREF(__pyx_v_ttype);
  __Pyx_DECREF(__pyx_v_data);
  __Pyx_DECREF(__pyx_v_fields);
  __Pyx_DECREF(__pyx_v_text);
  __Pyx_DECREF(__pyx_v_seqs);
  __Pyx_DECREF(__pyx_v_seqname);
  __Pyx_DECREF(__pyx_v_seqlen);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":782
 *         return dest
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *         return self
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__");
  __Pyx_TraceCall("__iter__", __pyx_f[0], 782);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":783
 * 
 *     def __iter__(self):
 *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":784
 *     def __iter__(self):
 *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.__iter__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":786
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static  bam1_t *__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile_getCurrent(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent");
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 786);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":787
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":789
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_7Samfile_cnext(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext");
  __Pyx_TraceCall("cnext", __pyx_f[0], 789);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":792
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 *         return samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = samread(__pyx_v_self->samfile, __pyx_v_self->b);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":794
 *         return samread(self.samfile, self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
struct wrapperbase __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_7Samfile___next__;
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___next__(PyObject *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__");
  __Pyx_TraceCall("__next__", __pyx_f[0], 794);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":800
 *         """
 *         cdef int ret
 *         ret = samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
 *         if (ret > 0):
 *             return makeAlignedRead( self.b )
 */
  __pyx_v_ret = samread(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->samfile, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->b);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":801
 *         cdef int ret
 *         ret = samread(self.samfile, self.b)
 *         if (ret > 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedRead( self.b )
 *         else:
 */
  __pyx_t_1 = (__pyx_v_ret > 0);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":802
 *         ret = samread(self.samfile, self.b)
 *         if (ret > 0):
 *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":804
 *             return makeAlignedRead( self.b )
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * cdef class Fastafile:
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Samfile.__next__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":822
 *     cdef faidx_t * fastafile
 * 
 *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.fastafile = NULL
 *         self._open( *args, **kwargs )
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 822);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":823
 * 
 *     def __cinit__(self, *args, **kwargs ):
 *         self.fastafile = NULL             # <<<<<<<<<<<<<<
 *         self._open( *args, **kwargs )
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile = NULL;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":824
 *     def __cinit__(self, *args, **kwargs ):
 *         self.fastafile = NULL
 *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
 * 
 *     def _isOpen( self ):
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_3 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_kwargs);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":826
 *         self._open( *args, **kwargs )
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if samfile has been opened.'''
 *         return self.fastafile != NULL
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile__isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile__isOpen[] = "Fastafile._isOpen(self)\nreturn true if samfile has been opened.";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile__isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_isOpen");
  __Pyx_TraceCall("_isOpen", __pyx_f[0], 826);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":828
 *     def _isOpen( self ):
 *         '''return true if samfile has been opened.'''
 *         return self.fastafile != NULL             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile._isOpen");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":830
 *         return self.fastafile != NULL
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         if self.fastafile == NULL:
 *             raise ValueError( "calling len() on closed file" )
 */

static Py_ssize_t __pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__len__");
  __Pyx_TraceCall("__len__", __pyx_f[0], 830);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":831
 * 
 *     def __len__(self):
 *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError( "calling len() on closed file" )
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile == NULL);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":832
 *     def __len__(self):
 *         if self.fastafile == NULL:
 *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         return faidx_fetch_nseq(self.fastafile)
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_44));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_44));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_44));
    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":834
 *             raise ValueError( "calling len() on closed file" )
 * 
 *         return faidx_fetch_nseq(self.fastafile)             # <<<<<<<<<<<<<<
 * 
 *     def _open( self,
 */
  __pyx_r = faidx_fetch_nseq(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile.__len__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":836
 *         return faidx_fetch_nseq(self.fastafile)
 * 
 *     def _open( self,             # <<<<<<<<<<<<<<
 *                char * filename ):
 *         '''open an indexed fasta file.
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile__open(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile__open[] = "Fastafile._open(self, char *filename)\nopen an indexed fasta file.\n\n        This method expects an indexed fasta file.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile__open(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) {
  char *__pyx_v_filename;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_open");
  __Pyx_TraceCall("_open", __pyx_f[0], 836);
  assert(__pyx_arg_filename); {
    __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile._open");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":844
 * 
 *         # close a previously opened file
 *         if self.fastafile != NULL: self.close()             # <<<<<<<<<<<<<<
 *         self.filename = filename
 *         self.fastafile = fai_load( filename )
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile != NULL);
  if (__pyx_t_1) {
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":845
 *         # close a previously opened file
 *         if self.fastafile != NULL: self.close()
 *         self.filename = filename             # <<<<<<<<<<<<<<
 *         self.fastafile = fai_load( filename )
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->filename = __pyx_v_filename;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":846
 *         if self.fastafile != NULL: self.close()
 *         self.filename = filename
 *         self.fastafile = fai_load( filename )             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile == NULL:
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile = fai_load(__pyx_v_filename);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":848
 *         self.fastafile = fai_load( filename )
 * 
 *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
 *             raise IOError("could not open file `%s`" % filename )
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile == NULL);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":849
 * 
 *         if self.fastafile == NULL:
 *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
 * 
 *     def close( self ):
 */
    __pyx_t_3 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile._open");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":851
 *             raise IOError("could not open file `%s`" % filename )
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile_close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile_close[] = "Fastafile.close(self)";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile_close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("close");
  __Pyx_TraceCall("close", __pyx_f[0], 851);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":852
 * 
 *     def close( self ):
 *         if self.fastafile != NULL:             # <<<<<<<<<<<<<<
 *             fai_destroy( self.fastafile )
 *             self.fastafile = NULL
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile != NULL);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":853
 *     def close( self ):
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )             # <<<<<<<<<<<<<<
 *             self.fastafile = NULL
 * 
 */
    fai_destroy(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":854
 *         if self.fastafile != NULL:
 *             fai_destroy( self.fastafile )
 *             self.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *     def fetch( self,
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile = NULL;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":856
 *             self.fastafile = NULL
 * 
 *     def fetch( self,             # <<<<<<<<<<<<<<
 *                reference = None,
 *                start = None,
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile_fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile_fetch[] = "Fastafile.fetch(self, reference=None, start=None, end=None, region=None)\n*(reference = None, start = None, end = None, region = None)*\n               \n        fetch :meth:`AlignedRead` objects in a :term:`region` using 0-based indexing. \n        The region is specified by :term:`reference`, *start* and *end*. \n\n        If *reference* is given and *start* is None, the sequence from the \n        first base is returned. Similarly, if *end* is None, the sequence \n        until the last base is returned.\n        \n        Alternatively, a samtools :term:`region` string can be supplied.\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile_fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  int __pyx_v_length;
  int __pyx_v_max_pos;
  char *__pyx_v_seq;
  PyObject *__pyx_v_py_seq;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("fetch");
  __Pyx_TraceCall("fetch", __pyx_f[0], 856);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":857
 * 
 *     def fetch( self,
 *                reference = None,             # <<<<<<<<<<<<<<
 *                start = None,
 *                end = None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":858
 *     def fetch( self,
 *                reference = None,
 *                start = None,             # <<<<<<<<<<<<<<
 *                end = None,
 *                region = None):
 */
    values[1] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":859
 *                reference = None,
 *                start = None,
 *                end = None,             # <<<<<<<<<<<<<<
 *                region = None):
 * 
 */
    values[2] = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":860
 *                start = None,
 *                end = None,
 *                region = None):             # <<<<<<<<<<<<<<
 * 
 *         '''*(reference = None, start = None, end = None, region = None)*
 */
    values[3] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
        if (value) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (value) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
        if (value) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
        if (value) { values[3] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
  } else {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":857
 * 
 *     def fetch( self,
 *                reference = None,             # <<<<<<<<<<<<<<
 *                start = None,
 *                end = None,
 */
    __pyx_v_reference = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":858
 *     def fetch( self,
 *                reference = None,
 *                start = None,             # <<<<<<<<<<<<<<
 *                end = None,
 *                region = None):
 */
    __pyx_v_start = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":859
 *                reference = None,
 *                start = None,
 *                end = None,             # <<<<<<<<<<<<<<
 *                region = None):
 * 
 */
    __pyx_v_end = ((PyObject *)Py_None);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":860
 *                start = None,
 *                end = None,
 *                region = None):             # <<<<<<<<<<<<<<
 * 
 *         '''*(reference = None, start = None, end = None, region = None)*
 */
    __pyx_v_region = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile.fetch");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  __pyx_v_py_seq = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":874
 *         '''
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":875
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         cdef int length, max_pos
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":879
 *         cdef int length, max_pos
 *         cdef char * seq
 *         max_pos = 2 << 29             # <<<<<<<<<<<<<<
 * 
 *         if not region:
 */
  __pyx_v_max_pos = 1073741824;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":881
 *         max_pos = 2 << 29
 * 
 *         if not region:             # <<<<<<<<<<<<<<
 *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
 *             if start is None: start = 0
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = (!__pyx_t_4);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":882
 * 
 *         if not region:
 *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
 *             if start is None: start = 0
 *             if end is None: end = max_pos -1
 */
    __pyx_t_3 = (__pyx_v_reference == Py_None);
    if (__pyx_t_3) {
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_45));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_45));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_45));
      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":883
 *         if not region:
 *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
 *             if start is None: start = 0             # <<<<<<<<<<<<<<
 *             if end is None: end = max_pos -1
 * 
 */
    __pyx_t_3 = (__pyx_v_start == Py_None);
    if (__pyx_t_3) {
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_DECREF(__pyx_v_start);
      __pyx_v_start = __pyx_int_0;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":884
 *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
 *             if start is None: start = 0
 *             if end is None: end = max_pos -1             # <<<<<<<<<<<<<<
 * 
 *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
 */
    __pyx_t_3 = (__pyx_v_end == Py_None);
    if (__pyx_t_3) {
      __pyx_t_2 = PyInt_FromLong((__pyx_v_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_end);
      __pyx_v_end = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":886
 *             if end is None: end = max_pos -1
 * 
 *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )             # <<<<<<<<<<<<<<
 *             if start == end: return ""
 *             # valid ranges are from 0 to 2^29-1
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_3) {
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_start);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start);
      __Pyx_GIVEREF(__pyx_v_start);
      __Pyx_INCREF(__pyx_v_end);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_end);
      __Pyx_GIVEREF(__pyx_v_end);
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_19), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":887
 * 
 *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
 *             if start == end: return ""             # <<<<<<<<<<<<<<
 *             # valid ranges are from 0 to 2^29-1
 *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
      __pyx_r = ((PyObject *)__pyx_kp_s_46);
      goto __pyx_L0;
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":889
 *             if start == end: return ""
 *             # valid ranges are from 0 to 2^29-1
 *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
 *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )
 *             seq = faidx_fetch_seq(self.fastafile,
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_start, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
      __Pyx_DECREF(__pyx_t_1);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = (!__pyx_t_3);
    if (__pyx_t_4) {
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), __pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":890
 *             # valid ranges are from 0 to 2^29-1
 *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
 *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
 *             seq = faidx_fetch_seq(self.fastafile,
 *                                   reference,
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_end, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
      __Pyx_DECREF(__pyx_t_1);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_end, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = (!__pyx_t_4);
    if (__pyx_t_3) {
      __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), __pyx_v_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_Raise(__pyx_t_1, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":892
 *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )
 *             seq = faidx_fetch_seq(self.fastafile,
 *                                   reference,             # <<<<<<<<<<<<<<
 *                                   start,
 *                                   end-1,
 */
    __pyx_t_5 = PyBytes_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":893
 *             seq = faidx_fetch_seq(self.fastafile,
 *                                   reference,
 *                                   start,             # <<<<<<<<<<<<<<
 *                                   end-1,
 *                                   &length)
 */
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_start); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":894
 *                                   reference,
 *                                   start,
 *                                   end-1,             # <<<<<<<<<<<<<<
 *                                   &length)
 *         else:
 */
    __pyx_t_1 = PyNumber_Subtract(__pyx_v_end, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":895
 *                                   start,
 *                                   end-1,
 *                                   &length)             # <<<<<<<<<<<<<<
 *         else:
 *             # samtools adds a '\0' at the end
 */
    __pyx_v_seq = faidx_fetch_seq(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile, __pyx_t_5, __pyx_t_6, __pyx_t_7, (&__pyx_v_length));
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":898
 *         else:
 *             # samtools adds a '\0' at the end
 *             seq = fai_fetch( self.fastafile, region, &length )             # <<<<<<<<<<<<<<
 * 
 *         # copy to python
 */
    __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_seq = fai_fetch(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile *)__pyx_v_self)->fastafile, __pyx_t_5, (&__pyx_v_length));
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":901
 * 
 *         # copy to python
 *         if seq == NULL:             # <<<<<<<<<<<<<<
 *             return ""
 *         else:
 */
  __pyx_t_3 = (__pyx_v_seq == NULL);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":902
 *         # copy to python
 *         if seq == NULL:
 *             return ""             # <<<<<<<<<<<<<<
 *         else:
 *             try:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
    __pyx_r = ((PyObject *)__pyx_kp_s_46);
    goto __pyx_L0;
    goto __pyx_L15;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":904
 *             return ""
 *         else:
 *             try:             # <<<<<<<<<<<<<<
 *                 py_seq = PyString_FromStringAndSize(seq, length)
 *             finally:
 */
    /*try:*/ {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":905
 *         else:
 *             try:
 *                 py_seq = PyString_FromStringAndSize(seq, length)             # <<<<<<<<<<<<<<
 *             finally:
 *                 free(seq)
 */
      __pyx_t_1 = PyString_FromStringAndSize(__pyx_v_seq, __pyx_v_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L17;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_v_py_seq);
      __pyx_v_py_seq = __pyx_t_1;
      __pyx_t_1 = 0;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":907
 *                 py_seq = PyString_FromStringAndSize(seq, length)
 *             finally:
 *                 free(seq)             # <<<<<<<<<<<<<<
 * 
 *         return py_seq
 */
    /*finally:*/ {
      int __pyx_why;
      PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
      int __pyx_exc_lineno;
      __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
      __pyx_why = 0; goto __pyx_L18;
      __pyx_L17: {
        __pyx_why = 4;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
        __pyx_exc_lineno = __pyx_lineno;
        goto __pyx_L18;
      }
      __pyx_L18:;
      free(__pyx_v_seq);
      switch (__pyx_why) {
        case 4: {
          __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
          __pyx_lineno = __pyx_exc_lineno;
          __pyx_exc_type = 0;
          __pyx_exc_value = 0;
          __pyx_exc_tb = 0;
          goto __pyx_L1_error;
        }
      }
    }
  }
  __pyx_L15:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":909
 *                 free(seq)
 * 
 *         return py_seq             # <<<<<<<<<<<<<<
 * 
 * ###########################################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_py_seq);
  __pyx_r = __pyx_v_py_seq;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Fastafile.fetch");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_py_seq);
  __Pyx_DECREF(__pyx_v_start);
  __Pyx_DECREF(__pyx_v_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":939
 *     cdef samfile_t              * fp
 * 
 *     def __cinit__(self, Samfile samfile, int tid, int beg, int end ):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._isOpen():
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_beg;
  int __pyx_v_end;
  PyObject *__pyx_v_mode;
  PyObject *__pyx_v_store;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  char *__pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__tid,&__pyx_n_s__beg,&__pyx_n_s__end,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 939);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beg);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_beg = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
    __pyx_v_tid = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_beg = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorRow.__cinit__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_mode = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_11chimerascan_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":941
 *     def __cinit__(self, Samfile samfile, int tid, int beg, int end ):
 * 
 *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":942
 * 
 *         if not samfile._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._hasIndex():
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":944
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
 *             raise ValueError( "no index available for pileup" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = (!__pyx_t_4);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":945
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as the
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_32));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_32));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_32));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":949
 *         # makes sure that samfile stays alive as long as the
 *         # iterator is alive
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 * 
 *         if samfile.isbam: mode = "rb"
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->samfile);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->samfile));
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->samfile = __pyx_v_samfile;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":951
 *         self.samfile = samfile
 * 
 *         if samfile.isbam: mode = "rb"             # <<<<<<<<<<<<<<
 *         else: mode = "r"
 * 
 */
  if (__pyx_v_samfile->isbam) {
    __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
    __Pyx_DECREF(__pyx_v_mode);
    __pyx_v_mode = ((PyObject *)__pyx_n_s__rb);
    goto __pyx_L8;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":952
 * 
 *         if samfile.isbam: mode = "rb"
 *         else: mode = "r"             # <<<<<<<<<<<<<<
 * 
 *         # reopen the file
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
    __Pyx_DECREF(__pyx_v_mode);
    __pyx_v_mode = ((PyObject *)__pyx_n_s__r);
  }
  __pyx_L8:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":955
 * 
 *         # reopen the file
 *         store = StderrStore()             # <<<<<<<<<<<<<<
 *         self.fp = samopen( samfile.filename, mode, NULL )
 *         store.release()
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_store);
  __pyx_v_store = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":956
 *         # reopen the file
 *         store = StderrStore()
 *         self.fp = samopen( samfile.filename, mode, NULL )             # <<<<<<<<<<<<<<
 *         store.release()
 * 
 */
  __pyx_t_5 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->fp = samopen(__pyx_v_samfile->filename, __pyx_t_5, NULL);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":957
 *         store = StderrStore()
 *         self.fp = samopen( samfile.filename, mode, NULL )
 *         store.release()             # <<<<<<<<<<<<<<
 * 
 *         self.retval = 0
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":959
 *         store.release()
 * 
 *         self.retval = 0             # <<<<<<<<<<<<<<
 * 
 *         self.iter = bam_iter_query(self.samfile.index,
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->retval = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":961
 *         self.retval = 0
 * 
 *         self.iter = bam_iter_query(self.samfile.index,             # <<<<<<<<<<<<<<
 *                                    tid,
 *                                    beg,
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->iter = bam_iter_query(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":965
 *                                    beg,
 *                                    end)
 *         self.b = bam_init1()             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->b = bam_init1();

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorRow.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_mode);
  __Pyx_DECREF(__pyx_v_store);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":967
 *         self.b = bam_init1()
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__");
  __Pyx_TraceCall("__iter__", __pyx_f[0], 967);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":968
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":970
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static  bam1_t *__pyx_f_11chimerascan_5pysam_9csamtools_11IteratorRow_getCurrent(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent");
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 970);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":971
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":973
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = bam_iter_read( self.fp.x.bam,
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_11IteratorRow_cnext(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext");
  __Pyx_TraceCall("cnext", __pyx_f[0], 973);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":975
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = bam_iter_read( self.fp.x.bam,             # <<<<<<<<<<<<<<
 *                                      self.iter,
 *                                      self.b)
 */
  __pyx_v_self->retval = bam_iter_read(__pyx_v_self->fp->x.bam, __pyx_v_self->iter, __pyx_v_self->b);

  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":979
 *                                      self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11IteratorRow___next__[] = "python version of next().\n        ";
struct wrapperbase __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11IteratorRow___next__;
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__");
  __Pyx_TraceCall("__next__", __pyx_f[0], 979);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":982
 *         """python version of next().
 *         """
 *         self.cnext()             # <<<<<<<<<<<<<<
 *         if self.retval < 0: raise StopIteration
 *         return makeAlignedRead( self.b )
 */
  ((struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRow *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->__pyx_vtab)->cnext(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":983
 *         """
 *         self.cnext()
 *         if self.retval < 0: raise StopIteration             # <<<<<<<<<<<<<<
 *         return makeAlignedRead( self.b )
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->retval < 0);
  if (__pyx_t_1) {
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":984
 *         self.cnext()
 *         if self.retval < 0: raise StopIteration
 *         return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorRow.__next__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":986
 *         return makeAlignedRead( self.b )
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         samclose( self.fp )
 */

static void __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 986);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":987
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         samclose( self.fp )
 * 
 */
  bam_destroy1(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->b);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":988
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         samclose( self.fp )             # <<<<<<<<<<<<<<
 * 
 * cdef class IteratorRowAll:
 */
  samclose(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_v_self)->fp);

  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":997
 *     cdef samfile_t * fp
 * 
 *     def __cinit__(self, Samfile samfile):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._isOpen():
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_mode;
  PyObject *__pyx_v_store;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  char *__pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 997);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)values[0]);
  } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorRowAll.__cinit__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_mode = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_11chimerascan_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":999
 *     def __cinit__(self, Samfile samfile):
 * 
 *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1000
 * 
 *         if not samfile._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         if samfile.isbam: mode = "rb"
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_17));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_17));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17));
    __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1002
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         if samfile.isbam: mode = "rb"             # <<<<<<<<<<<<<<
 *         else: mode = "r"
 * 
 */
  if (__pyx_v_samfile->isbam) {
    __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
    __Pyx_DECREF(__pyx_v_mode);
    __pyx_v_mode = ((PyObject *)__pyx_n_s__rb);
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1003
 * 
 *         if samfile.isbam: mode = "rb"
 *         else: mode = "r"             # <<<<<<<<<<<<<<
 * 
 *         # reopen the file to avoid iterator conflict
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
    __Pyx_DECREF(__pyx_v_mode);
    __pyx_v_mode = ((PyObject *)__pyx_n_s__r);
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1006
 * 
 *         # reopen the file to avoid iterator conflict
 *         store = StderrStore()             # <<<<<<<<<<<<<<
 *         self.fp = samopen( samfile.filename, mode, NULL )
 *         store.release()
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_store);
  __pyx_v_store = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1007
 *         # reopen the file to avoid iterator conflict
 *         store = StderrStore()
 *         self.fp = samopen( samfile.filename, mode, NULL )             # <<<<<<<<<<<<<<
 *         store.release()
 * 
 */
  __pyx_t_5 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->fp = samopen(__pyx_v_samfile->filename, __pyx_t_5, NULL);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1008
 *         store = StderrStore()
 *         self.fp = samopen( samfile.filename, mode, NULL )
 *         store.release()             # <<<<<<<<<<<<<<
 * 
 *         # allocate memory for alignment
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1011
 * 
 *         # allocate memory for alignment
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorRowAll.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_mode);
  __Pyx_DECREF(__pyx_v_store);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1013
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__");
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1013);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1014
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1016
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static  bam1_t *__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorRowAll_getCurrent(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent");
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1016);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1017
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1019
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_14IteratorRowAll_cnext(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext");
  __Pyx_TraceCall("cnext", __pyx_f[0], 1019);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1022
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = samread(__pyx_v_self->fp, __pyx_v_self->b);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1024
 *         return samread(self.fp, self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
struct wrapperbase __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__;
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__(PyObject *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__");
  __Pyx_TraceCall("__next__", __pyx_f[0], 1024);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1030
 *         """
 *         cdef int ret
 *         ret = samread(self.fp, self.b)             # <<<<<<<<<<<<<<
 *         if (ret > 0):
 *             return makeAlignedRead( self.b )
 */
  __pyx_v_ret = samread(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->fp, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->b);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1031
 *         cdef int ret
 *         ret = samread(self.fp, self.b)
 *         if (ret > 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedRead( self.b )
 *         else:
 */
  __pyx_t_1 = (__pyx_v_ret > 0);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1032
 *         ret = samread(self.fp, self.b)
 *         if (ret > 0):
 *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_makeAlignedRead(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1034
 *             return makeAlignedRead( self.b )
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorRowAll.__next__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1036
 *             raise StopIteration
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         samclose( self.fp )
 */

static void __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1036);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1037
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         samclose( self.fp )
 * 
 */
  bam_destroy1(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->b);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1038
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         samclose( self.fp )             # <<<<<<<<<<<<<<
 * 
 * ctypedef struct __iterdata:
 */
  samclose(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)__pyx_v_self)->fp);

  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1044
 *     bam_iter_t iter
 * 
 * cdef int __advance( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
 *     cdef __iterdata * d
 *     d = <__iterdata*>data
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools___advance(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_11chimerascan_5pysam_9csamtools___iterdata *__pyx_v_d;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__advance");
  __Pyx_TraceCall("__advance", __pyx_f[0], 1044);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1046
 * cdef int __advance( void * data, bam1_t * b ):
 *     cdef __iterdata * d
 *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     return bam_iter_read( d.fp, d.iter, b )
 * 
 */
  __pyx_v_d = ((__pyx_t_11chimerascan_5pysam_9csamtools___iterdata *)__pyx_v_data);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1047
 *     cdef __iterdata * d
 *     d = <__iterdata*>data
 *     return bam_iter_read( d.fp, d.iter, b )             # <<<<<<<<<<<<<<
 * 
 * cdef class IteratorColumn:
 */
  __pyx_r = bam_iter_read(__pyx_v_d->fp, __pyx_v_d->iter, __pyx_v_b);
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1082
 *     cdef bam_plp_t pileup_iter
 *     cdef __iterdata iterdata
 *     def __cinit__(self, Samfile samfile, int tid, int start, int end ):             # <<<<<<<<<<<<<<
 * 
 *         self.iter = IteratorRow( samfile, tid, start, end )
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_start;
  int __pyx_v_end;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__tid,&__pyx_n_s__start,&__pyx_n_s__end,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1082);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
    __pyx_v_tid = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorColumn.__cinit__");
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_11chimerascan_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1084
 *     def __cinit__(self, Samfile samfile, int tid, int start, int end ):
 * 
 *         self.iter = IteratorRow( samfile, tid, start, end )             # <<<<<<<<<<<<<<
 *         self.iterdata.fp = samfile.samfile.x.bam
 *         self.iterdata.iter = self.iter.iter
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRow)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iter);
  __Pyx_DECREF(((PyObject *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iter));
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iter = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1085
 * 
 *         self.iter = IteratorRow( samfile, tid, start, end )
 *         self.iterdata.fp = samfile.samfile.x.bam             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.fp = __pyx_v_samfile->samfile->x.bam;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1086
 *         self.iter = IteratorRow( samfile, tid, start, end )
 *         self.iterdata.fp = samfile.samfile.x.bam
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 * 
 *         self.pileup_iter = bam_plp_init( &__advance, &self.iterdata )
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.iter = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iter->iter;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1088
 *         self.iterdata.iter = self.iter.iter
 * 
 *         self.pileup_iter = bam_plp_init( &__advance, &self.iterdata )             # <<<<<<<<<<<<<<
 *         self.n_plp = 0
 *         self.tid = 0
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter = bam_plp_init((&__pyx_f_11chimerascan_5pysam_9csamtools___advance), (&((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1089
 * 
 *         self.pileup_iter = bam_plp_init( &__advance, &self.iterdata )
 *         self.n_plp = 0             # <<<<<<<<<<<<<<
 *         self.tid = 0
 *         self.pos = 0
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->n_plp = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1090
 *         self.pileup_iter = bam_plp_init( &__advance, &self.iterdata )
 *         self.n_plp = 0
 *         self.tid = 0             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         self.plp = NULL
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->tid = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1091
 *         self.n_plp = 0
 *         self.tid = 0
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         self.plp = NULL
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->pos = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1092
 *         self.tid = 0
 *         self.pos = 0
 *         self.plp = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->plp = NULL;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorColumn.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1094
 *         self.plp = NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__");
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1094);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1095
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self);
  __pyx_r = __pyx_v_self;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1097
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

static  int __pyx_f_11chimerascan_5pysam_9csamtools_14IteratorColumn_cnext(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext");
  __Pyx_TraceCall("cnext", __pyx_f[0], 1097);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1100
 *         '''perform next iteration.
 *         '''
 *         self.plp = bam_plp_auto( self.pileup_iter,             # <<<<<<<<<<<<<<
 *                                  &self.tid,
 *                                  &self.pos,
 */
  __pyx_v_self->plp = bam_plp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp));

  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1105
 *                                  &self.n_plp )
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
struct wrapperbase __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__;
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__");
  __Pyx_TraceCall("__next__", __pyx_f[0], 1105);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1110
 *         pyrex uses this non-standard name instead of next()
 *         """
 *         self.cnext()             # <<<<<<<<<<<<<<
 *         if self.n_plp < 0:
 *             raise ValueError("error during iteration" )
 */
  ((struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorColumn *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->__pyx_vtab)->cnext(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1111
 *         """
 *         self.cnext()
 *         if self.n_plp < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("error during iteration" )
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->n_plp < 0);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1112
 *         self.cnext()
 *         if self.n_plp < 0:
 *             raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *         if self.plp == NULL:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_47));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_47));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_47));
    __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1114
 *             raise ValueError("error during iteration" )
 * 
 *         if self.plp == NULL:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->plp == NULL);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1115
 * 
 *         if self.plp == NULL:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         return makePileupProxy( self.plp, self.tid, self.pos, self.n_plp )
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1117
 *             raise StopIteration
 * 
 *         return makePileupProxy( self.plp, self.tid, self.pos, self.n_plp )             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_11chimerascan_5pysam_9csamtools_makePileupProxy(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->plp, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->tid, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->pos, ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->n_plp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.IteratorColumn.__next__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1119
 *         return makePileupProxy( self.plp, self.tid, self.pos, self.n_plp )
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_plp_destroy(self.pileup_iter)
 * 
 */

static void __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1119);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1120
 * 
 *     def __dealloc__(self):
 *         bam_plp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 * cdef inline int32_t query_start(bam1_t *src) except -1:
 */
  bam_plp_destroy(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter);

  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1122
 *         bam_plp_destroy(self.pileup_iter)
 * 
 * cdef inline int32_t query_start(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p, op
 *     cdef uint32_t k
 */

static CYTHON_INLINE int32_t __pyx_f_11chimerascan_5pysam_9csamtools_query_start(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_start_offset;
  int32_t __pyx_r;
  uint32_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("query_start");
  __Pyx_TraceCall("query_start", __pyx_f[0], 1122);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1125
 *     cdef uint32_t * cigar_p, op
 *     cdef uint32_t k
 *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
 * 
 *     if src.core.n_cigar:
 */
  __pyx_v_start_offset = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1127
 *     cdef uint32_t start_offset = 0
 * 
 *     if src.core.n_cigar:             # <<<<<<<<<<<<<<
 *         cigar_p = bam1_cigar(src);
 *         for k from 0 <= k < src.core.n_cigar:
 */
  if (__pyx_v_src->core.n_cigar) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1128
 * 
 *     if src.core.n_cigar:
 *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < src.core.n_cigar:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1129
 *     if src.core.n_cigar:
 *         cigar_p = bam1_cigar(src);
 *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op==BAM_CHARD_CLIP:
 */
    __pyx_t_1 = __pyx_v_src->core.n_cigar;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_1; __pyx_v_k++) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1130
 *         cigar_p = bam1_cigar(src);
 *         for k from 0 <= k < src.core.n_cigar:
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             if op==BAM_CHARD_CLIP:
 *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1131
 *         for k from 0 <= k < src.core.n_cigar:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 */
      switch (__pyx_v_op) {
        case 5:

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1132
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op==BAM_CHARD_CLIP:
 *                 if start_offset!=0 and start_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 */
        __pyx_t_2 = (__pyx_v_start_offset != 0);
        if (__pyx_t_2) {
          __pyx_t_3 = (__pyx_v_start_offset != __pyx_v_src->core.l_qseq);
          __pyx_t_4 = __pyx_t_3;
        } else {
          __pyx_t_4 = __pyx_t_2;
        }
        if (__pyx_t_4) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1133
 *             if op==BAM_CHARD_CLIP:
 *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
 *                     return -1
 *             elif op==BAM_CSOFT_CLIP:
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_48);

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1134
 *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1             # <<<<<<<<<<<<<<
 *             elif op==BAM_CSOFT_CLIP:
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
          __pyx_r = -1;
          goto __pyx_L0;
          goto __pyx_L6;
        }
        __pyx_L6:;
        break;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1135
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
        case 4:

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1136
 *                     return -1
 *             elif op==BAM_CSOFT_CLIP:
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_start_offset += ((__pyx_v_cigar_p[__pyx_v_k]) >> 4);
        break;
        default:

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1138
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     return start_offset
 */
        goto __pyx_L5_break;
        break;
      }
    }
    __pyx_L5_break:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1140
 *                 break
 * 
 *     return start_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_start_offset;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1143
 * 
 * 
 * cdef inline int32_t query_end(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p, op
 *     cdef uint32_t k
 */

static CYTHON_INLINE int32_t __pyx_f_11chimerascan_5pysam_9csamtools_query_end(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_end_offset;
  int32_t __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("query_end");
  __Pyx_TraceCall("query_end", __pyx_f[0], 1143);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1146
 *     cdef uint32_t * cigar_p, op
 *     cdef uint32_t k
 *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     if src.core.n_cigar>1:
 */
  __pyx_v_end_offset = __pyx_v_src->core.l_qseq;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1148
 *     cdef uint32_t end_offset = src.core.l_qseq
 * 
 *     if src.core.n_cigar>1:             # <<<<<<<<<<<<<<
 *         cigar_p = bam1_cigar(src);
 *         for k from src.core.n_cigar > k >= 1:
 */
  __pyx_t_1 = (__pyx_v_src->core.n_cigar > 1);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1149
 * 
 *     if src.core.n_cigar>1:
 *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from src.core.n_cigar > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1150
 *     if src.core.n_cigar>1:
 *         cigar_p = bam1_cigar(src);
 *         for k from src.core.n_cigar > k >= 1:             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op==BAM_CHARD_CLIP:
 */
    for (__pyx_v_k = __pyx_v_src->core.n_cigar-1; __pyx_v_k >= 1; __pyx_v_k--) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1151
 *         cigar_p = bam1_cigar(src);
 *         for k from src.core.n_cigar > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             if op==BAM_CHARD_CLIP:
 *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1152
 *         for k from src.core.n_cigar > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 */
      switch (__pyx_v_op) {
        case 5:

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1153
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op==BAM_CHARD_CLIP:
 *                 if end_offset!=0 and end_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 */
        __pyx_t_1 = (__pyx_v_end_offset != 0);
        if (__pyx_t_1) {
          __pyx_t_2 = (__pyx_v_end_offset != __pyx_v_src->core.l_qseq);
          __pyx_t_3 = __pyx_t_2;
        } else {
          __pyx_t_3 = __pyx_t_1;
        }
        if (__pyx_t_3) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1154
 *             if op==BAM_CHARD_CLIP:
 *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
 *                     return -1
 *             elif op==BAM_CSOFT_CLIP:
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_48);

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1155
 *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1             # <<<<<<<<<<<<<<
 *             elif op==BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 */
          __pyx_r = -1;
          goto __pyx_L0;
          goto __pyx_L6;
        }
        __pyx_L6:;
        break;

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1156
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
        case 4:

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1157
 *                     return -1
 *             elif op==BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_end_offset -= ((__pyx_v_cigar_p[__pyx_v_k]) >> 4);
        break;
        default:

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1159
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     if end_offset==0:
 */
        goto __pyx_L5_break;
        break;
      }
    }
    __pyx_L5_break:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1161
 *                 break
 * 
 *     if end_offset==0:             # <<<<<<<<<<<<<<
 *         end_offset = src.core.l_qseq
 * 
 */
  __pyx_t_3 = (__pyx_v_end_offset == 0);
  if (__pyx_t_3) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1162
 * 
 *     if end_offset==0:
 *         end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     return end_offset
 */
    __pyx_v_end_offset = __pyx_v_src->core.l_qseq;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1164
 *         end_offset = src.core.l_qseq
 * 
 *     return end_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_end_offset;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1167
 * 
 * 
 * cdef inline object get_seq_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *     cdef uint8_t * p
 *     cdef uint32_t k
 */

static CYTHON_INLINE PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_get_seq_range(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint8_t *__pyx_v_p;
  uint32_t __pyx_v_k;
  char *__pyx_v_s;
  char *__pyx_v_bam_nt16_rev_table;
  PyObject *__pyx_v_seq;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  uint32_t __pyx_t_3;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("get_seq_range");
  __Pyx_TraceCall("get_seq_range", __pyx_f[0], 1167);
  __pyx_v_seq = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1171
 *     cdef uint32_t k
 *     cdef char * s
 *     cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"             # <<<<<<<<<<<<<<
 * 
 *     if not src.core.l_qseq:
 */
  __pyx_v_bam_nt16_rev_table = __pyx_k_49;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1173
 *     cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = (!__pyx_v_src->core.l_qseq);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1174
 * 
 *     if not src.core.l_qseq:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     seq = PyString_FromStringAndSize(NULL, end-start)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1176
 *         return None
 * 
 *     seq = PyString_FromStringAndSize(NULL, end-start)             # <<<<<<<<<<<<<<
 *     s   = PyString_AS_STRING(seq)
 *     p   = bam1_seq(src)
 */
  __pyx_t_2 = PyString_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_v_seq);
  __pyx_v_seq = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1177
 * 
 *     seq = PyString_FromStringAndSize(NULL, end-start)
 *     s   = PyString_AS_STRING(seq)             # <<<<<<<<<<<<<<
 *     p   = bam1_seq(src)
 * 
 */
  __pyx_v_s = PyString_AS_STRING(__pyx_v_seq);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1178
 *     seq = PyString_FromStringAndSize(NULL, end-start)
 *     s   = PyString_AS_STRING(seq)
 *     p   = bam1_seq(src)             # <<<<<<<<<<<<<<
 * 
 *     for k from start <= k < end:
 */
  __pyx_v_p = bam1_seq(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1180
 *     p   = bam1_seq(src)
 * 
 *     for k from start <= k < end:             # <<<<<<<<<<<<<<
 *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
 *         # note: do not use string literal as it will be a python string
 */
  __pyx_t_3 = __pyx_v_end;
  for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1183
 *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
 *         # note: do not use string literal as it will be a python string
 *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]             # <<<<<<<<<<<<<<
 * 
 *     return seq
 */
    (__pyx_v_s[(__pyx_v_k - __pyx_v_start)]) = (__pyx_v_bam_nt16_rev_table[(((__pyx_v_p[__Pyx_div_long(__pyx_v_k, 2)]) >> (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))) & 0xf)]);
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1185
 *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]
 * 
 *     return seq             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_seq);
  __pyx_r = __pyx_v_seq;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.get_seq_range");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1188
 * 
 * 
 * cdef inline object get_qual_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *     cdef uint8_t * p
 *     cdef uint32_t k
 */

static CYTHON_INLINE PyObject *__pyx_f_11chimerascan_5pysam_9csamtools_get_qual_range(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint8_t *__pyx_v_p;
  uint32_t __pyx_v_k;
  char *__pyx_v_q;
  PyObject *__pyx_v_qual;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  uint32_t __pyx_t_3;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("get_qual_range");
  __Pyx_TraceCall("get_qual_range", __pyx_f[0], 1188);
  __pyx_v_qual = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1193
 *     cdef char * q
 * 
 *     p = bam1_qual(src)             # <<<<<<<<<<<<<<
 *     if p[0] == 0xff:
 *         return None
 */
  __pyx_v_p = bam1_qual(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1194
 * 
 *     p = bam1_qual(src)
 *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_p[0]) == 0xff);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1195
 *     p = bam1_qual(src)
 *     if p[0] == 0xff:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     qual = PyString_FromStringAndSize(NULL, end-start)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1197
 *         return None
 * 
 *     qual = PyString_FromStringAndSize(NULL, end-start)             # <<<<<<<<<<<<<<
 *     q    = PyString_AS_STRING(qual)
 * 
 */
  __pyx_t_2 = PyString_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_v_qual);
  __pyx_v_qual = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1198
 * 
 *     qual = PyString_FromStringAndSize(NULL, end-start)
 *     q    = PyString_AS_STRING(qual)             # <<<<<<<<<<<<<<
 * 
 *     for k from start <= k < end:
 */
  __pyx_v_q = PyString_AS_STRING(__pyx_v_qual);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1200
 *     q    = PyString_AS_STRING(qual)
 * 
 *     for k from start <= k < end:             # <<<<<<<<<<<<<<
 *         ## equivalent to t[i] + 33 (see bam.c)
 *         q[k-start] = p[k] + 33
 */
  __pyx_t_3 = __pyx_v_end;
  for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1202
 *     for k from start <= k < end:
 *         ## equivalent to t[i] + 33 (see bam.c)
 *         q[k-start] = p[k] + 33             # <<<<<<<<<<<<<<
 * 
 *     return qual
 */
    (__pyx_v_q[(__pyx_v_k - __pyx_v_start)]) = ((__pyx_v_p[__pyx_v_k]) + 33);
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1204
 *         q[k-start] = p[k] + 33
 * 
 *     return qual             # <<<<<<<<<<<<<<
 * 
 * cdef class AlignedRead:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_qual);
  __pyx_r = __pyx_v_qual;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.get_qual_range");
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_qual);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1229
 *          bam1_t * _delegate
 * 
 *     def __cinit__( self ):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1229);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1231
 *     def __cinit__( self ):
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
 *         # allocate some memory
 *         # If size is 0, calloc does not return a pointer that can be passed to free()
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1235
 *         # If size is 0, calloc does not return a pointer that can be passed to free()
 *         # so allocate 40 bytes for a new read
 *         self._delegate.m_data = 40             # <<<<<<<<<<<<<<
 *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
 *         self._delegate.data_len = 0
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->m_data = 40;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1236
 *         # so allocate 40 bytes for a new read
 *         self._delegate.m_data = 40
 *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )             # <<<<<<<<<<<<<<
 *         self._delegate.data_len = 0
 * 
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->data = ((uint8_t *)calloc(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->m_data, 1));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1237
 *         self._delegate.m_data = 40
 *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
 *         self._delegate.data_len = 0             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->data_len = 0;

  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1239
 *         self._delegate.data_len = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

static void __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1239);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1240
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  bam_destroy1(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate);

  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1242
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """todo"""
 *         return "\t".join(map(str, (self.qname,
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead___str__[] = "todo";
struct wrapperbase __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11AlignedRead___str__;
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__");
  __Pyx_TraceCall("__str__", __pyx_f[0], 1242);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1244
 *     def __str__(self):
 *         """todo"""
 *         return "\t".join(map(str, (self.qname,             # <<<<<<<<<<<<<<
 *                                    self.rname,
 *                                    self.pos,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__qname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1245
 *         """todo"""
 *         return "\t".join(map(str, (self.qname,
 *                                    self.rname,             # <<<<<<<<<<<<<<
 *                                    self.pos,
 *                                    self.cigar,
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__rname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1246
 *         return "\t".join(map(str, (self.qname,
 *                                    self.rname,
 *                                    self.pos,             # <<<<<<<<<<<<<<
 *                                    self.cigar,
 *                                    self.qual,
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1247
 *                                    self.rname,
 *                                    self.pos,
 *                                    self.cigar,             # <<<<<<<<<<<<<<
 *                                    self.qual,
 *                                    self.flag,
 */
  __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__cigar); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1248
 *                                    self.pos,
 *                                    self.cigar,
 *                                    self.qual,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.seq,
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__qual); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1249
 *                                    self.cigar,
 *                                    self.qual,
 *                                    self.flag,             # <<<<<<<<<<<<<<
 *                                    self.seq,
 *                                    self.mapq,
 */
  __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1250
 *                                    self.qual,
 *                                    self.flag,
 *                                    self.seq,             # <<<<<<<<<<<<<<
 *                                    self.mapq,
 *                                    self.tags)))
 */
  __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__seq); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1251
 *                                    self.flag,
 *                                    self.seq,
 *                                    self.mapq,             # <<<<<<<<<<<<<<
 *                                    self.tags)))
 * 
 */
  __pyx_t_9 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__mapq); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1252
 *                                    self.seq,
 *                                    self.mapq,
 *                                    self.tags)))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_10 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tags); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = PyTuple_New(9); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_11, 3, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_11, 4, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_11, 5, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_11, 6, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_11, 7, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_11, 8, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_9 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_11 = 0;
  __pyx_t_11 = PyObject_Call(__pyx_builtin_map, __pyx_t_10, NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_11 = 0;
  __pyx_t_11 = PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_r = __pyx_t_11;
  __pyx_t_11 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.__str__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1255
 * 
 * 
 *     def compare(self, AlignedRead other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary <,=,> to *other*'''
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead_compare[] = "AlignedRead.compare(self, AlignedRead other)\nreturn -1,0,1, if contents in this are binary <,=,> to *other*";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_v_retval;
  bam1_t *__pyx_v_t;
  bam1_t *__pyx_v_o;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("compare");
  __Pyx_TraceCall("compare", __pyx_f[0], 1255);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_11chimerascan_5pysam_9csamtools_AlignedRead, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1261
 *         cdef bam1_t *t, *o
 * 
 *         t = self._delegate             # <<<<<<<<<<<<<<
 *         o = other._delegate
 * 
 */
  __pyx_v_t = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1262
 * 
 *         t = self._delegate
 *         o = other._delegate             # <<<<<<<<<<<<<<
 * 
 *         # uncomment for debugging purposes
 */
  __pyx_v_o = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_other)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1274
 * 
 *         # Fast-path test for object identity
 *         if t==o:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = (__pyx_v_t == __pyx_v_o);
  if (__pyx_t_1) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1275
 *         # Fast-path test for object identity
 *         if t==o:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1277
 *             return 0
 * 
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))             # <<<<<<<<<<<<<<
 * 
 *         if retval: return retval
 */
  __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t)));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1279
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 * 
 *         if retval: return retval             # <<<<<<<<<<<<<<
 *         retval = cmp(t.data_len, o.data_len)
 *         if retval: return retval
 */
  if (__pyx_v_retval) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1280
 * 
 *         if retval: return retval
 *         retval = cmp(t.data_len, o.data_len)             # <<<<<<<<<<<<<<
 *         if retval: return retval
 *         return memcmp(t.data, o.data, t.data_len)
 */
  __pyx_t_2 = PyInt_FromLong(__pyx_v_t->data_len); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyInt_FromLong(__pyx_v_o->data_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_builtin_cmp, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_retval = __pyx_t_5;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1281
 *         if retval: return retval
 *         retval = cmp(t.data_len, o.data_len)
 *         if retval: return retval             # <<<<<<<<<<<<<<
 *         return memcmp(t.data, o.data, t.data_len)
 * 
 */
  if (__pyx_v_retval) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1282
 *         retval = cmp(t.data_len, o.data_len)
 *         if retval: return retval
 *         return memcmp(t.data, o.data, t.data_len)             # <<<<<<<<<<<<<<
 * 
 *     # Disabled so long as __cmp__ is a special method
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyInt_FromLong(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->data_len)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.compare");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1285
 * 
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return _Py_HashPointer(<void *>self)
 * 
 */

static long __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___hash__(PyObject *__pyx_v_self); /*proto*/
static long __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___hash__(PyObject *__pyx_v_self) {
  long __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__hash__");
  __Pyx_TraceCall("__hash__", __pyx_f[0], 1285);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1286
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):
 *         return _Py_HashPointer(<void *>self)             # <<<<<<<<<<<<<<
 * 
 *     property qname:
 */
  __pyx_r = _Py_HashPointer(((void *)__pyx_v_self));
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1290
 *     property qname:
 *         """the query name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qname___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qname___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1290);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1292
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if src.core.l_qname == 0: return None
 *             return <char *>bam1_qname( src )
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1293
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if src.core.l_qname == 0: return None             # <<<<<<<<<<<<<<
 *             return <char *>bam1_qname( src )
 * 
 */
  __pyx_t_1 = (__pyx_v_src->core.l_qname == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1294
 *             src = self._delegate
 *             if src.core.l_qname == 0: return None
 *             return <char *>bam1_qname( src )             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, qname ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyBytes_FromString(bam1_qname(__pyx_v_src)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qname.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1296
 *             return <char *>bam1_qname( src )
 * 
 *         def __set__(self, qname ):             # <<<<<<<<<<<<<<
 *             if qname == None or len(qname) == 0: return
 *             cdef bam1_t * src
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qname___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qname___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
  bam1_t *__pyx_v_src;
  int __pyx_v_l;
  char *__pyx_v_p;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  char *__pyx_t_6;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1296);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1297
 * 
 *         def __set__(self, qname ):
 *             if qname == None or len(qname) == 0: return             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef int l
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_qname, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_2) {
    __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (__pyx_t_3 == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_2;
  }
  if (__pyx_t_5) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1302
 *             cdef char * p
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = bam1_qname( src )
 * 
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1303
 * 
 *             src = self._delegate
 *             p = bam1_qname( src )             # <<<<<<<<<<<<<<
 * 
 *             # the qname is \0 terminated
 */
  __pyx_v_p = bam1_qname(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1306
 * 
 *             # the qname is \0 terminated
 *             l = len(qname) + 1             # <<<<<<<<<<<<<<
 *             pysam_bam_update( src,
 *                               src.core.l_qname,
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = (__pyx_t_3 + 1);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1310
 *                               src.core.l_qname,
 *                               l,
 *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
 * 
 *             src.core.l_qname = l
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_src->core.l_qname, __pyx_v_l, ((uint8_t *)__pyx_v_p));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1312
 *                               <uint8_t*>p )
 * 
 *             src.core.l_qname = l             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  __pyx_v_src->core.l_qname = __pyx_v_l;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1316
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = bam1_qname(src)             # <<<<<<<<<<<<<<
 * 
 *             strncpy( p, qname, l )
 */
  __pyx_v_p = bam1_qname(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1318
 *             p = bam1_qname(src)
 * 
 *             strncpy( p, qname, l )             # <<<<<<<<<<<<<<
 * 
 *     property cigar:
 */
  __pyx_t_6 = PyBytes_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_p, __pyx_t_6, __pyx_v_l);

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qname.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1323
 *         """the :term:`cigar` alignment (None if not present).
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5cigar___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5cigar___get__(PyObject *__pyx_v_self) {
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_op;
  PyObject *__pyx_v_l;
  PyObject *__pyx_v_cigar;
  int __pyx_v_k;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  uint32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1323);
  __pyx_v_op = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_cigar = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1329
 *             cdef int k
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if src.core.n_cigar == 0: return None
 * 
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1330
 * 
 *             src = self._delegate
 *             if src.core.n_cigar == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             cigar = []
 */
  __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1332
 *             if src.core.n_cigar == 0: return None
 * 
 *             cigar = []             # <<<<<<<<<<<<<<
 *             cigar_p = bam1_cigar(src);
 *             for k from 0 <= k < src.core.n_cigar:
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(__pyx_v_cigar);
  __pyx_v_cigar = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1333
 * 
 *             cigar = []
 *             cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < src.core.n_cigar:
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1334
 *             cigar = []
 *             cigar_p = bam1_cigar(src);
 *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_3 = __pyx_v_src->core.n_cigar;
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1335
 *             cigar_p = bam1_cigar(src);
 *             for k from 0 <= k < src.core.n_cigar:
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 */
    __pyx_t_2 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) & 15)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_op);
    __pyx_v_op = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1336
 *             for k from 0 <= k < src.core.n_cigar:
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 cigar.append((op, l))
 *             return cigar
 */
    __pyx_t_2 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_l);
    __pyx_v_l = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1337
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
 *             return cigar
 * 
 */
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_op);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_op);
    __Pyx_GIVEREF(__pyx_v_op);
    __Pyx_INCREF(__pyx_v_l);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_l);
    __Pyx_GIVEREF(__pyx_v_l);
    __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_cigar, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1338
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 *             return cigar             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, values ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_cigar);
  __pyx_r = __pyx_v_cigar;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.cigar.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_op);
  __Pyx_DECREF(__pyx_v_l);
  __Pyx_DECREF(__pyx_v_cigar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1340
 *             return cigar
 * 
 *         def __set__(self, values ):             # <<<<<<<<<<<<<<
 *             if values == None or len(values) == 0: return
 *             cdef uint32_t * p
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5cigar___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5cigar___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) {
  uint32_t *__pyx_v_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_op;
  PyObject *__pyx_v_l;
  int __pyx_v_k;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  uint32_t __pyx_t_10;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1340);
  __pyx_v_op = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1341
 * 
 *         def __set__(self, values ):
 *             if values == None or len(values) == 0: return             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_values, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_2) {
    __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (__pyx_t_3 == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_2;
  }
  if (__pyx_t_5) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1347
 *             cdef int k
 * 
 *             k = 0             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
  __pyx_v_k = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1349
 *             k = 0
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # get location of cigar string
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1352
 * 
 *             # get location of cigar string
 *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # create space for cigar data within src.data
 */
  __pyx_v_p = bam1_cigar(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1357
 *             pysam_bam_update( src,
 *                               src.core.n_cigar * 4,
 *                               len(values) * 4,             # <<<<<<<<<<<<<<
 *                               p )
 * 
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1358
 *                               src.core.n_cigar * 4,
 *                               len(values) * 4,
 *                               p )             # <<<<<<<<<<<<<<
 * 
 *             # length is number of cigar operations, not bytes
 */
  pysam_bam_update(__pyx_v_src, (__pyx_v_src->core.n_cigar * 4), (__pyx_t_3 * 4), __pyx_v_p);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1361
 * 
 *             # length is number of cigar operations, not bytes
 *             src.core.n_cigar = len(values)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_src->core.n_cigar = __pyx_t_3;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1365
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # insert cigar operations
 */
  __pyx_v_p = bam1_cigar(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1368
 * 
 *             # insert cigar operations
 *             for op, l in values:             # <<<<<<<<<<<<<<
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1
 */
  if (PyList_CheckExact(__pyx_v_values) || PyTuple_CheckExact(__pyx_v_values)) {
    __pyx_t_3 = 0; __pyx_t_1 = __pyx_v_values; __Pyx_INCREF(__pyx_t_1);
  } else {
    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_1))) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
    } else {
      __pyx_t_6 = PyIter_Next(__pyx_t_1);
      if (!__pyx_t_6) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_6);
    }
    if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) {
      PyObject* tuple = __pyx_t_6;
      __pyx_t_7 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_7);
      __pyx_t_8 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_v_op);
      __pyx_v_op = __pyx_t_7;
      __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_v_l);
      __pyx_v_l = __pyx_t_8;
      __pyx_t_8 = 0;
    } else {
      __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_9, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_9, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      if (__Pyx_EndUnpack(__pyx_t_9, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_v_op);
      __pyx_v_op = __pyx_t_7;
      __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_v_l);
      __pyx_v_l = __pyx_t_8;
      __pyx_t_8 = 0;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1369
 *             # insert cigar operations
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
 *                 k += 1
 * 
 */
    __pyx_t_6 = PyNumber_Lshift(__pyx_v_l, __pyx_int_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = PyNumber_Or(__pyx_t_6, __pyx_v_op); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_10 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_10 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    (__pyx_v_p[__pyx_v_k]) = __pyx_t_10;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1370
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1             # <<<<<<<<<<<<<<
 * 
 *             ## setting the cigar string also updates the "bin" attribute
 */
    __pyx_v_k += 1;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1373
 * 
 *             ## setting the cigar string also updates the "bin" attribute
 *             src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, p))             # <<<<<<<<<<<<<<
 * 
 *     property seq:
 */
  __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, bam_calend((&__pyx_v_src->core), __pyx_v_p));

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.cigar.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_op);
  __Pyx_DECREF(__pyx_v_l);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1377
 *     property seq:
 *         """read sequence bases, including :term:`soft clipped` bases (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef char * s
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3seq___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3seq___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1377);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1381
 *             cdef char * s
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1383
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             return get_seq_range(src, 0, src.core.l_qseq)
 */
  __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1385
 *             if src.core.l_qseq == 0: return None
 * 
 *             return get_seq_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self,seq):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_get_seq_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.seq.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1387
 *             return get_seq_range(src, 0, src.core.l_qseq)
 * 
 *         def __set__(self,seq):             # <<<<<<<<<<<<<<
 *             # samtools manages sequence and quality length memory together
 *             # if no quality information is present, the first byte says 0xff.
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3seq___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3seq___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_p;
  char *__pyx_v_s;
  int __pyx_v_l;
  int __pyx_v_k;
  int __pyx_v_nbytes_new;
  int __pyx_v_nbytes_old;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  char *__pyx_t_7;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1387);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1391
 *             # if no quality information is present, the first byte says 0xff.
 * 
 *             if seq == None or len(seq) == 0: return             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint8_t * p
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_2) {
    __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (__pyx_t_3 == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_2;
  }
  if (__pyx_t_5) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1397
 *             cdef int l, k, nbytes_new, nbytes_old
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             l = len(seq)
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1399
 *             src = self._delegate
 * 
 *             l = len(seq)             # <<<<<<<<<<<<<<
 * 
 *             # as the sequence is stored in half-bytes, the total length (sequence
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = __pyx_t_3;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1403
 *             # as the sequence is stored in half-bytes, the total length (sequence
 *             # plus quality scores) is (l+1)/2 + l
 *             nbytes_new = (l+1)/2 + l             # <<<<<<<<<<<<<<
 *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq
 *             # acquire pointer to location in memory
 */
  __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1404
 *             # plus quality scores) is (l+1)/2 + l
 *             nbytes_new = (l+1)/2 + l
 *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq             # <<<<<<<<<<<<<<
 *             # acquire pointer to location in memory
 *             p = bam1_seq( src )
 */
  __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1406
 *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq
 *             # acquire pointer to location in memory
 *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
 *             src.core.l_qseq = l
 * 
 */
  __pyx_v_p = bam1_seq(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1407
 *             # acquire pointer to location in memory
 *             p = bam1_seq( src )
 *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
 * 
 *             pysam_bam_update( src,
 */
  __pyx_v_src->core.l_qseq = __pyx_v_l;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1412
 *                               nbytes_old,
 *                               nbytes_new,
 *                               p)             # <<<<<<<<<<<<<<
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1415
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < nbytes_new: p[k] = 0
 *             # convert to C string
 */
  __pyx_v_p = bam1_seq(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1416
 *             # as it might have moved
 *             p = bam1_seq( src )
 *             for k from 0 <= k < nbytes_new: p[k] = 0             # <<<<<<<<<<<<<<
 *             # convert to C string
 *             s = seq
 */
  __pyx_t_6 = __pyx_v_nbytes_new;
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {
    (__pyx_v_p[__pyx_v_k]) = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1418
 *             for k from 0 <= k < nbytes_new: p[k] = 0
 *             # convert to C string
 *             s = seq             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < l:
 *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
 */
  __pyx_t_7 = PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = __pyx_t_7;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1419
 *             # convert to C string
 *             s = seq
 *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
 *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
 * 
 */
  __pyx_t_6 = __pyx_v_l;
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1420
 *             s = seq
 *             for k from 0 <= k < l:
 *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
 * 
 *             # erase qualities
 */
    (__pyx_v_p[__Pyx_div_long(__pyx_v_k, 2)]) |= (pysam_translate_sequence((__pyx_v_s[__pyx_v_k])) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2))));
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1423
 * 
 *             # erase qualities
 *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
 *             p[0] = 0xff
 * 
 */
  __pyx_v_p = bam1_qual(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1424
 *             # erase qualities
 *             p = bam1_qual( src )
 *             p[0] = 0xff             # <<<<<<<<<<<<<<
 * 
 * 
 */
  (__pyx_v_p[0]) = 0xff;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.seq.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1429
 *     property qual:
 *         """read sequence base qualities, including :term:`soft clipped` bases (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qual___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qual___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1429);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1434
 *             cdef char * q
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1436
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             return get_qual_range(src, 0, src.core.l_qseq)
 */
  __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1438
 *             if src.core.l_qseq == 0: return None
 * 
 *             return get_qual_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self,qual):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_get_qual_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qual.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1440
 *             return get_qual_range(src, 0, src.core.l_qseq)
 * 
 *         def __set__(self,qual):             # <<<<<<<<<<<<<<
 *             # note that space is already allocated via the sequences
 *             cdef bam1_t * src
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qual___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qual___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_p;
  char *__pyx_v_q;
  int __pyx_v_k;
  int __pyx_v_l;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  char *__pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1440);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1447
 *             cdef int k
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = bam1_qual( src )
 *             if qual == None or len(qual) == 0:
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1448
 * 
 *             src = self._delegate
 *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
 *             if qual == None or len(qual) == 0:
 *                 # if absent - set to 0xff
 */
  __pyx_v_p = bam1_qual(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1449
 *             src = self._delegate
 *             p = bam1_qual( src )
 *             if qual == None or len(qual) == 0:             # <<<<<<<<<<<<<<
 *                 # if absent - set to 0xff
 *                 p[0] = 0xff
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_qual, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!__pyx_t_2) {
    __pyx_t_3 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (__pyx_t_3 == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_2;
  }
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1451
 *             if qual == None or len(qual) == 0:
 *                 # if absent - set to 0xff
 *                 p[0] = 0xff             # <<<<<<<<<<<<<<
 *                 return
 *             cdef int l
 */
    (__pyx_v_p[0]) = 0xff;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1452
 *                 # if absent - set to 0xff
 *                 p[0] = 0xff
 *                 return             # <<<<<<<<<<<<<<
 *             cdef int l
 *             # convert to C string
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1455
 *             cdef int l
 *             # convert to C string
 *             q = qual             # <<<<<<<<<<<<<<
 *             l = len(qual)
 *             if src.core.l_qseq != l:
 */
  __pyx_t_6 = PyBytes_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_q = __pyx_t_6;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1456
 *             # convert to C string
 *             q = qual
 *             l = len(qual)             # <<<<<<<<<<<<<<
 *             if src.core.l_qseq != l:
 *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = __pyx_t_3;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1457
 *             q = qual
 *             l = len(qual)
 *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
 *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
 *             assert src.core.l_qseq == l
 */
  __pyx_t_5 = (__pyx_v_src->core.l_qseq != __pyx_v_l);
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1458
 *             l = len(qual)
 *             if src.core.l_qseq != l:
 *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))             # <<<<<<<<<<<<<<
 *             assert src.core.l_qseq == l
 *             for k from 0 <= k < l:
 */
    __pyx_t_1 = PyInt_FromLong(__pyx_v_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyInt_to_py_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_1 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_50), __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1459
 *             if src.core.l_qseq != l:
 *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
 *             assert src.core.l_qseq == l             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < l:
 *                 p[k] = <uint8_t>q[k] - 33
 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  if (unlikely(!(__pyx_v_src->core.l_qseq == __pyx_v_l))) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #endif

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1460
 *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
 *             assert src.core.l_qseq == l
 *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
 *                 p[k] = <uint8_t>q[k] - 33
 * 
 */
  __pyx_t_9 = __pyx_v_l;
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_9; __pyx_v_k++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1461
 *             assert src.core.l_qseq == l
 *             for k from 0 <= k < l:
 *                 p[k] = <uint8_t>q[k] - 33             # <<<<<<<<<<<<<<
 * 
 *     property query:
 */
    (__pyx_v_p[__pyx_v_k]) = (((uint8_t)(__pyx_v_q[__pyx_v_k])) - 33);
  }

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qual.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1473
 *         were not considered for alignment may have been retained."""
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5query___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5query___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int32_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1473);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1478
 *             cdef char * s
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1480
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             start = query_start(src)
 */
  __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1482
 *             if src.core.l_qseq == 0: return None
 * 
 *             start = query_start(src)             # <<<<<<<<<<<<<<
 *             end   = query_end(src)
 * 
 */
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_2;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1483
 * 
 *             start = query_start(src)
 *             end   = query_end(src)             # <<<<<<<<<<<<<<
 * 
 *             return get_seq_range(src, start, end)
 */
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_2;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1485
 *             end   = query_end(src)
 * 
 *             return get_seq_range(src, start, end)             # <<<<<<<<<<<<<<
 * 
 *     property qqual:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_11chimerascan_5pysam_9csamtools_get_seq_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.query.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1489
 *     property qqual:
 *         """aligned query sequence quality values (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qqual___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qqual___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int32_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1489);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1494
 *             cdef char * q
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1496
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             start = query_start(src)
 */
  __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1498
 *             if src.core.l_qseq == 0: return None
 * 
 *             start = query_start(src)             # <<<<<<<<<<<<<<
 *             end   = query_end(src)
 * 
 */
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_2;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1499
 * 
 *             start = query_start(src)
 *             end   = query_end(src)             # <<<<<<<<<<<<<<
 * 
 *             return get_qual_range(src, start, end)
 */
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_2;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1501
 *             end   = query_end(src)
 * 
 *             return get_qual_range(src, start, end)             # <<<<<<<<<<<<<<
 * 
 *     property qstart:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_11chimerascan_5pysam_9csamtools_get_qual_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qqual.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1505
 *     property qstart:
 *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return query_start(self._delegate)
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_6qstart___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_6qstart___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int32_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1505);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1506
 *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
 *         def __get__(self):
 *             return query_start(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property qend:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_11chimerascan_5pysam_9csamtools_query_start(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qstart.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1510
 *     property qend:
 *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return query_end(self._delegate)
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qend___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qend___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  int32_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1510);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1511
 *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
 *         def __get__(self):
 *             return query_end(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property qlen:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_11chimerascan_5pysam_9csamtools_query_end(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qend.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1515
 *     property qlen:
 *         """Length of the aligned query sequence"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qlen___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qlen___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  int32_t __pyx_t_1;
  int32_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1515);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1517
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             return query_end(src)-query_start(src)
 * 
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1518
 *             cdef bam1_t * src
 *             src = self._delegate
 *             return query_end(src)-query_start(src)             # <<<<<<<<<<<<<<
 * 
 *     property tags:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_11chimerascan_5pysam_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_11chimerascan_5pysam_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyInt_to_py_int32_t((__pyx_t_1 - __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.qlen.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1532
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef char * ctag
 *             cdef bam1_t * src
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4tags___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4tags___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char __pyx_v_auxtag[3];
  char __pyx_v_auxtype;
  PyObject *__pyx_v_result;
  PyObject *__pyx_v_value;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  int __pyx_t_8;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1532);
  __pyx_v_result = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1539
 *             cdef char auxtype
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if src.l_aux == 0: return None
 * 
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1540
 * 
 *             src = self._delegate
 *             if src.l_aux == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             s = bam1_aux( src )
 */
  __pyx_t_1 = (__pyx_v_src->l_aux == 0);
  if (__pyx_t_1) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1542
 *             if src.l_aux == 0: return None
 * 
 *             s = bam1_aux( src )             # <<<<<<<<<<<<<<
 *             result = []
 *             auxtag[2] = 0
 */
  __pyx_v_s = bam1_aux(__pyx_v_src);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1543
 * 
 *             s = bam1_aux( src )
 *             result = []             # <<<<<<<<<<<<<<
 *             auxtag[2] = 0
 *             while s < (src.data + src.data_len):
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_DECREF(((PyObject *)__pyx_v_result));
  __pyx_v_result = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1544
 *             s = bam1_aux( src )
 *             result = []
 *             auxtag[2] = 0             # <<<<<<<<<<<<<<
 *             while s < (src.data + src.data_len):
 *                 # get tag
 */
  (__pyx_v_auxtag[2]) = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1545
 *             result = []
 *             auxtag[2] = 0
 *             while s < (src.data + src.data_len):             # <<<<<<<<<<<<<<
 *                 # get tag
 *                 auxtag[0] = s[0]
 */
  while (1) {
    __pyx_t_1 = (__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->data_len));
    if (!__pyx_t_1) break;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1547
 *             while s < (src.data + src.data_len):
 *                 # get tag
 *                 auxtag[0] = s[0]             # <<<<<<<<<<<<<<
 *                 auxtag[1] = s[1]
 *                 s += 2
 */
    (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1548
 *                 # get tag
 *                 auxtag[0] = s[0]
 *                 auxtag[1] = s[1]             # <<<<<<<<<<<<<<
 *                 s += 2
 *                 auxtype = s[0]
 */
    (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1549
 *                 auxtag[0] = s[0]
 *                 auxtag[1] = s[1]
 *                 s += 2             # <<<<<<<<<<<<<<
 *                 auxtype = s[0]
 * 
 */
    __pyx_v_s += 2;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1550
 *                 auxtag[1] = s[1]
 *                 s += 2
 *                 auxtype = s[0]             # <<<<<<<<<<<<<<
 * 
 *                 if auxtype in ('c', 'C'):
 */
    __pyx_v_auxtype = (__pyx_v_s[0]);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1552
 *                 auxtype = s[0]
 * 
 *                 if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
 *                     value = <int>bam_aux2i(s)
 *                     s += 1
 */
    __pyx_t_3 = __pyx_v_auxtype;
    __pyx_t_1 = (__pyx_t_3 == 'c');
    if (!__pyx_t_1) {
      __pyx_t_4 = (__pyx_t_3 == 'C');
      __pyx_t_5 = __pyx_t_4;
    } else {
      __pyx_t_5 = __pyx_t_1;
    }
    __pyx_t_1 = __pyx_t_5;
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1553
 * 
 *                 if auxtype in ('c', 'C'):
 *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                     s += 1
 *                 elif auxtype in ('s', 'S'):
 */
      __pyx_t_2 = PyInt_FromLong(bam_aux2i(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1554
 *                 if auxtype in ('c', 'C'):
 *                     value = <int>bam_aux2i(s)
 *                     s += 1             # <<<<<<<<<<<<<<
 *                 elif auxtype in ('s', 'S'):
 *                     value = <int>bam_aux2i(s)
 */
      __pyx_v_s += 1;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1555
 *                     value = <int>bam_aux2i(s)
 *                     s += 1
 *                 elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
 *                     value = <int>bam_aux2i(s)
 *                     s += 2
 */
    __pyx_t_3 = __pyx_v_auxtype;
    __pyx_t_1 = (__pyx_t_3 == 's');
    if (!__pyx_t_1) {
      __pyx_t_5 = (__pyx_t_3 == 'S');
      __pyx_t_4 = __pyx_t_5;
    } else {
      __pyx_t_4 = __pyx_t_1;
    }
    __pyx_t_1 = __pyx_t_4;
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1556
 *                     s += 1
 *                 elif auxtype in ('s', 'S'):
 *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                     s += 2
 *                 elif auxtype in ('i', 'I'):
 */
      __pyx_t_2 = PyInt_FromLong(bam_aux2i(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1557
 *                 elif auxtype in ('s', 'S'):
 *                     value = <int>bam_aux2i(s)
 *                     s += 2             # <<<<<<<<<<<<<<
 *                 elif auxtype in ('i', 'I'):
 *                     value = <float>bam_aux2i(s)
 */
      __pyx_v_s += 2;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1558
 *                     value = <int>bam_aux2i(s)
 *                     s += 2
 *                 elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
 *                     value = <float>bam_aux2i(s)
 *                     s += 4
 */
    __pyx_t_3 = __pyx_v_auxtype;
    __pyx_t_1 = (__pyx_t_3 == 'i');
    if (!__pyx_t_1) {
      __pyx_t_4 = (__pyx_t_3 == 'I');
      __pyx_t_5 = __pyx_t_4;
    } else {
      __pyx_t_5 = __pyx_t_1;
    }
    __pyx_t_1 = __pyx_t_5;
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1559
 *                     s += 2
 *                 elif auxtype in ('i', 'I'):
 *                     value = <float>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                     s += 4
 *                 elif auxtype == 'f':
 */
      __pyx_t_2 = PyFloat_FromDouble(((float)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1560
 *                 elif auxtype in ('i', 'I'):
 *                     value = <float>bam_aux2i(s)
 *                     s += 4             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'f':
 *                     value = <float>bam_aux2f(s)
 */
      __pyx_v_s += 4;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1561
 *                     value = <float>bam_aux2i(s)
 *                     s += 4
 *                 elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *                     value = <float>bam_aux2f(s)
 *                     s += 4
 */
    __pyx_t_1 = (__pyx_v_auxtype == 'f');
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1562
 *                     s += 4
 *                 elif auxtype == 'f':
 *                     value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                     s += 4
 *                 elif auxtype == 'd':
 */
      __pyx_t_2 = PyFloat_FromDouble(bam_aux2f(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1563
 *                 elif auxtype == 'f':
 *                     value = <float>bam_aux2f(s)
 *                     s += 4             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'd':
 *                     value = <double>bam_aux2d(s)
 */
      __pyx_v_s += 4;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1564
 *                     value = <float>bam_aux2f(s)
 *                     s += 4
 *                 elif auxtype == 'd':             # <<<<<<<<<<<<<<
 *                     value = <double>bam_aux2d(s)
 *                     s += 8
 */
    __pyx_t_1 = (__pyx_v_auxtype == 'd');
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1565
 *                     s += 4
 *                 elif auxtype == 'd':
 *                     value = <double>bam_aux2d(s)             # <<<<<<<<<<<<<<
 *                     s += 8
 *                 elif auxtype == 'A':
 */
      __pyx_t_2 = PyFloat_FromDouble(bam_aux2d(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1566
 *                 elif auxtype == 'd':
 *                     value = <double>bam_aux2d(s)
 *                     s += 8             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'A':
 *                     value = "%c" % <char>bam_aux2A(s)
 */
      __pyx_v_s += 8;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1567
 *                     value = <double>bam_aux2d(s)
 *                     s += 8
 *                 elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *                     value = "%c" % <char>bam_aux2A(s)
 *                     s += 1
 */
    __pyx_t_1 = (__pyx_v_auxtype == 'A');
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1568
 *                     s += 8
 *                 elif auxtype == 'A':
 *                     value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
 *                     s += 1
 *                 elif auxtype in ('Z', 'H'):
 */
      __pyx_t_2 = PyInt_FromLong(bam_aux2A(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_51), __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_6));
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = ((PyObject *)__pyx_t_6);
      __pyx_t_6 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1569
 *                 elif auxtype == 'A':
 *                     value = "%c" % <char>bam_aux2A(s)
 *                     s += 1             # <<<<<<<<<<<<<<
 *                 elif auxtype in ('Z', 'H'):
 *                     value = <char*>bam_aux2Z(s)
 */
      __pyx_v_s += 1;
      goto __pyx_L8;
    }

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1570
 *                     value = "%c" % <char>bam_aux2A(s)
 *                     s += 1
 *                 elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
 *                     value = <char*>bam_aux2Z(s)
 *                     # +1 for NULL terminated string
 */
    __pyx_t_3 = __pyx_v_auxtype;
    __pyx_t_1 = (__pyx_t_3 == 'Z');
    if (!__pyx_t_1) {
      __pyx_t_5 = (__pyx_t_3 == 'H');
      __pyx_t_4 = __pyx_t_5;
    } else {
      __pyx_t_4 = __pyx_t_1;
    }
    __pyx_t_1 = __pyx_t_4;
    if (__pyx_t_1) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1571
 *                     s += 1
 *                 elif auxtype in ('Z', 'H'):
 *                     value = <char*>bam_aux2Z(s)             # <<<<<<<<<<<<<<
 *                     # +1 for NULL terminated string
 *                     s += len(value) + 1
 */
      __pyx_t_6 = PyBytes_FromString(bam_aux2Z(__pyx_v_s)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_6));
      __Pyx_DECREF(__pyx_v_value);
      __pyx_v_value = ((PyObject *)__pyx_t_6);
      __pyx_t_6 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1573
 *                     value = <char*>bam_aux2Z(s)
 *                     # +1 for NULL terminated string
 *                     s += len(value) + 1             # <<<<<<<<<<<<<<
 *                  #
 *                 s += 1
 */
      __pyx_t_7 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_s += (__pyx_t_7 + 1);
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1575
 *                     s += len(value) + 1
 *                  #
 *                 s += 1             # <<<<<<<<<<<<<<
 * 
 *                 result.append( (auxtag, value) )
 */
    __pyx_v_s += 1;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1577
 *                 s += 1
 * 
 *                 result.append( (auxtag, value) )             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
    if (unlikely(__pyx_v_result == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_6 = PyBytes_FromString(__pyx_v_auxtag); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_6));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_6 = 0;
    __pyx_t_8 = PyList_Append(((PyObject *)__pyx_v_result), __pyx_t_2); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1579
 *                 result.append( (auxtag, value) )
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, tags):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.tags.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_result);
  __Pyx_DECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1581
 *             return result
 * 
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             cdef char * ctag
 *             cdef bam1_t * src
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4tags___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4tags___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char *__pyx_v_temp;
  int __pyx_v_max_size;
  int __pyx_v_size;
  int __pyx_v_offset;
  PyObject *__pyx_v_buffer;
  PyObject *__pyx_v_pytag;
  PyObject *__pyx_v_value;
  PyObject *__pyx_v_t;
  PyObject *__pyx_v_fmt;
  PyObject *__pyx_v_pytype;
  PyObject *__pyx_v_ctype;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  char *__pyx_t_11;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1581);
  __pyx_v_buffer = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_pytag = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_t = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_fmt = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_pytype = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_ctype = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1590
 *             cdef int max_size, size, offset
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             max_size = 4000
 *             offset = 0
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1591
 * 
 *             src = self._delegate
 *             max_size = 4000             # <<<<<<<<<<<<<<
 *             offset = 0
 * 
 */
  __pyx_v_max_size = 4000;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1592
 *             src = self._delegate
 *             max_size = 4000
 *             offset = 0             # <<<<<<<<<<<<<<
 * 
 *             if tags != None:
 */
  __pyx_v_offset = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1594
 *             offset = 0
 * 
 *             if tags != None:             # <<<<<<<<<<<<<<
 * 
 *                 # map samtools code to python.struct code and byte size
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_tags, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1597
 * 
 *                 # map samtools code to python.struct code and byte size
 *                 buffer = ctypes.create_string_buffer(max_size)             # <<<<<<<<<<<<<<
 * 
 *                 for pytag, value in tags:
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ctypes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_52); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyInt_FromLong(__pyx_v_max_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_buffer);
    __pyx_v_buffer = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1599
 *                 buffer = ctypes.create_string_buffer(max_size)
 * 
 *                 for pytag, value in tags:             # <<<<<<<<<<<<<<
 *                     t = type(value)
 *                     if t == types.FloatType:
 */
    if (PyList_CheckExact(__pyx_v_tags) || PyTuple_CheckExact(__pyx_v_tags)) {
      __pyx_t_5 = 0; __pyx_t_1 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_1);
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    }
    for (;;) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++;
      } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++;
      } else {
        __pyx_t_4 = PyIter_Next(__pyx_t_1);
        if (!__pyx_t_4) {
          if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      if (PyTuple_CheckExact(__pyx_t_4) && likely(PyTuple_GET_SIZE(__pyx_t_4) == 2)) {
        PyObject* tuple = __pyx_t_4;
        __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3);
        __pyx_t_6 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_v_pytag);
        __pyx_v_pytag = __pyx_t_3;
        __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_v_value);
        __pyx_v_value = __pyx_t_6;
        __pyx_t_6 = 0;
      } else {
        __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_7, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_7, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        if (__Pyx_EndUnpack(__pyx_t_7, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_v_pytag);
        __pyx_v_pytag = __pyx_t_3;
        __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_v_value);
        __pyx_v_value = __pyx_t_6;
        __pyx_t_6 = 0;
      }

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1600
 * 
 *                 for pytag, value in tags:
 *                     t = type(value)             # <<<<<<<<<<<<<<
 *                     if t == types.FloatType:
 *                         fmt = "<cccf"
 */
      __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
      __Pyx_DECREF(((PyObject *)__pyx_v_t));
      __pyx_v_t = ((PyObject *)((PyObject *)Py_TYPE(__pyx_v_value)));

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1601
 *                 for pytag, value in tags:
 *                     t = type(value)
 *                     if t == types.FloatType:             # <<<<<<<<<<<<<<
 *                         fmt = "<cccf"
 *                     elif t == types.IntType:
 */
      __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__types); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__FloatType); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_t), __pyx_t_6, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1602
 *                     t = type(value)
 *                     if t == types.FloatType:
 *                         fmt = "<cccf"             # <<<<<<<<<<<<<<
 *                     elif t == types.IntType:
 *                         if value < 0:
 */
        __Pyx_INCREF(((PyObject *)__pyx_kp_s_53));
        __Pyx_DECREF(__pyx_v_fmt);
        __pyx_v_fmt = ((PyObject *)__pyx_kp_s_53);
        goto __pyx_L8;
      }

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1603
 *                     if t == types.FloatType:
 *                         fmt = "<cccf"
 *                     elif t == types.IntType:             # <<<<<<<<<<<<<<
 *                         if value < 0:
 *                             if value >= -127: fmt, pytype = "<cccb", 'c'
 */
      __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__types); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__IntType); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_t), __pyx_t_6, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1604
 *                         fmt = "<cccf"
 *                     elif t == types.IntType:
 *                         if value < 0:             # <<<<<<<<<<<<<<
 *                             if value >= -127: fmt, pytype = "<cccb", 'c'
 *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
 */
        __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (__pyx_t_2) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1605
 *                     elif t == types.IntType:
 *                         if value < 0:
 *                             if value >= -127: fmt, pytype = "<cccb", 'c'             # <<<<<<<<<<<<<<
 *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
 *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
          __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (__pyx_t_2) {
            __pyx_t_4 = ((PyObject *)__pyx_kp_s_54);
            __Pyx_INCREF(__pyx_t_4);
            __pyx_t_6 = ((PyObject *)__pyx_n_s__c);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_v_fmt);
            __pyx_v_fmt = __pyx_t_4;
            __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_v_pytype);
            __pyx_v_pytype = __pyx_t_6;
            __pyx_t_6 = 0;
            goto __pyx_L10;
          }

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1606
 *                         if value < 0:
 *                             if value >= -127: fmt, pytype = "<cccb", 'c'
 *                             elif value >= -32767: fmt, pytype = "<ccch", 's'             # <<<<<<<<<<<<<<
 *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                             else: fmt, ctype = "<ccci", 'i'[0]
 */
          __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (__pyx_t_2) {
            __pyx_t_6 = ((PyObject *)__pyx_kp_s_55);
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_4 = ((PyObject *)__pyx_n_s__s);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_v_fmt);
            __pyx_v_fmt = __pyx_t_6;
            __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_v_pytype);
            __pyx_v_pytype = __pyx_t_4;
            __pyx_t_4 = 0;
            goto __pyx_L10;
          }

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1607
 *                             if value >= -127: fmt, pytype = "<cccb", 'c'
 *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
 *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                             else: fmt, ctype = "<ccci", 'i'[0]
 *                         else:
 */
          __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (__pyx_t_2) {
            __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_56), __pyx_v_value); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(((PyObject *)__pyx_t_4));
            __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_6);
            PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_4));
            __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
            __pyx_t_4 = 0;
            __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_Raise(__pyx_t_4, 0, 0);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            goto __pyx_L10;
          }
          /*else*/ {

            /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1608
 *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
 *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                             else: fmt, ctype = "<ccci", 'i'[0]             # <<<<<<<<<<<<<<
 *                         else:
 *                             if value <= 255: fmt, pytype = "<cccB", 'C'
 */
            __pyx_t_4 = ((PyObject *)__pyx_kp_s_57);
            __Pyx_INCREF(__pyx_t_4);
            __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_n_s__i), 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_v_fmt);
            __pyx_v_fmt = __pyx_t_4;
            __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_v_ctype);
            __pyx_v_ctype = __pyx_t_6;
            __pyx_t_6 = 0;
          }
          __pyx_L10:;
          goto __pyx_L9;
        }
        /*else*/ {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1610
 *                             else: fmt, ctype = "<ccci", 'i'[0]
 *                         else:
 *                             if value <= 255: fmt, pytype = "<cccB", 'C'             # <<<<<<<<<<<<<<
 *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'
 *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
          __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (__pyx_t_2) {
            __pyx_t_6 = ((PyObject *)__pyx_kp_s_58);
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_4 = ((PyObject *)__pyx_n_s__C);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_v_fmt);
            __pyx_v_fmt = __pyx_t_6;
            __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_v_pytype);
            __pyx_v_pytype = __pyx_t_4;
            __pyx_t_4 = 0;
            goto __pyx_L11;
          }

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1611
 *                         else:
 *                             if value <= 255: fmt, pytype = "<cccB", 'C'
 *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'             # <<<<<<<<<<<<<<
 *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                             else: fmt, pytype = "<cccI", 'I'
 */
          __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (__pyx_t_2) {
            __pyx_t_4 = ((PyObject *)__pyx_kp_s_59);
            __Pyx_INCREF(__pyx_t_4);
            __pyx_t_6 = ((PyObject *)__pyx_n_s__S);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_v_fmt);
            __pyx_v_fmt = __pyx_t_4;
            __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_v_pytype);
            __pyx_v_pytype = __pyx_t_6;
            __pyx_t_6 = 0;
            goto __pyx_L11;
          }

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1612
 *                             if value <= 255: fmt, pytype = "<cccB", 'C'
 *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'
 *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                             else: fmt, pytype = "<cccI", 'I'
 *                     else:
 */
          __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (__pyx_t_2) {
            __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_56), __pyx_v_value); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(((PyObject *)__pyx_t_6));
            __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_4);
            PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6));
            __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
            __pyx_t_6 = 0;
            __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_Raise(__pyx_t_6, 0, 0);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            goto __pyx_L11;
          }
          /*else*/ {

            /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1613
 *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'
 *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                             else: fmt, pytype = "<cccI", 'I'             # <<<<<<<<<<<<<<
 *                     else:
 *                         # Note: hex strings (H) are not supported yet
 */
            __pyx_t_6 = ((PyObject *)__pyx_kp_s_60);
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_4 = ((PyObject *)__pyx_n_s__I);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_v_fmt);
            __pyx_v_fmt = __pyx_t_6;
            __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_v_pytype);
            __pyx_v_pytype = __pyx_t_4;
            __pyx_t_4 = 0;
          }
          __pyx_L11:;
        }
        __pyx_L9:;
        goto __pyx_L8;
      }
      /*else*/ {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1616
 *                     else:
 *                         # Note: hex strings (H) are not supported yet
 *                         if len(value) == 1:             # <<<<<<<<<<<<<<
 *                             fmt, pytype = "<cccc", 'A'
 *                         else:
 */
        __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = (__pyx_t_8 == 1);
        if (__pyx_t_2) {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1617
 *                         # Note: hex strings (H) are not supported yet
 *                         if len(value) == 1:
 *                             fmt, pytype = "<cccc", 'A'             # <<<<<<<<<<<<<<
 *                         else:
 *                             fmt, pytype = "<ccc%is" % (len(value)+1), 'Z'
 */
          __pyx_t_4 = ((PyObject *)__pyx_kp_s_61);
          __Pyx_INCREF(__pyx_t_4);
          __pyx_t_6 = ((PyObject *)__pyx_n_s__A);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_v_fmt);
          __pyx_v_fmt = __pyx_t_4;
          __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_v_pytype);
          __pyx_v_pytype = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L12;
        }
        /*else*/ {

          /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1619
 *                             fmt, pytype = "<cccc", 'A'
 *                         else:
 *                             fmt, pytype = "<ccc%is" % (len(value)+1), 'Z'             # <<<<<<<<<<<<<<
 * 
 *                     size = struct.calcsize(fmt)
 */
          __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_8 + 1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_62), __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(((PyObject *)__pyx_t_4));
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = ((PyObject *)__pyx_n_s__Z);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_v_fmt);
          __pyx_v_fmt = ((PyObject *)__pyx_t_4);
          __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_v_pytype);
          __pyx_v_pytype = __pyx_t_6;
          __pyx_t_6 = 0;
        }
        __pyx_L12:;
      }
      __pyx_L8:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1621
 *                             fmt, pytype = "<ccc%is" % (len(value)+1), 'Z'
 * 
 *                     size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
 *                     if offset + size > max_size:
 *                         raise NotImplementedError("tags field too large")
 */
      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__calcsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_v_fmt);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fmt);
      __Pyx_GIVEREF(__pyx_v_fmt);
      __pyx_t_3 = PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_size = __pyx_t_9;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1622
 * 
 *                     size = struct.calcsize(fmt)
 *                     if offset + size > max_size:             # <<<<<<<<<<<<<<
 *                         raise NotImplementedError("tags field too large")
 * 
 */
      __pyx_t_2 = ((__pyx_v_offset + __pyx_v_size) > __pyx_v_max_size);
      if (__pyx_t_2) {

        /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1623
 *                     size = struct.calcsize(fmt)
 *                     if offset + size > max_size:
 *                         raise NotImplementedError("tags field too large")             # <<<<<<<<<<<<<<
 * 
 *                     struct.pack_into( fmt,
 */
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(((PyObject *)__pyx_kp_s_63));
        PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_63));
        __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_63));
        __pyx_t_6 = PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_Raise(__pyx_t_6, 0, 0);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L13;
      }
      __pyx_L13:;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1625
 *                         raise NotImplementedError("tags field too large")
 * 
 *                     struct.pack_into( fmt,             # <<<<<<<<<<<<<<
 *                                       buffer,
 *                                       offset,
 */
      __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__pack_into); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1627
 *                     struct.pack_into( fmt,
 *                                       buffer,
 *                                       offset,             # <<<<<<<<<<<<<<
 *                                       pytag[0],
 *                                       pytag[1],
 */
      __pyx_t_6 = PyInt_FromLong(__pyx_v_offset); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1628
 *                                       buffer,
 *                                       offset,
 *                                       pytag[0],             # <<<<<<<<<<<<<<
 *                                       pytag[1],
 *                                       pytype,
 */
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_pytag, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1629
 *                                       offset,
 *                                       pytag[0],
 *                                       pytag[1],             # <<<<<<<<<<<<<<
 *                                       pytype,
 *                                       value )
 */
      __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_pytag, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1631
 *                                       pytag[1],
 *                                       pytype,
 *                                       value )             # <<<<<<<<<<<<<<
 *                     offset += size
 * 
 */
      __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_fmt);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_fmt);
      __Pyx_GIVEREF(__pyx_v_fmt);
      __Pyx_INCREF(__pyx_v_buffer);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_buffer);
      __Pyx_GIVEREF(__pyx_v_buffer);
      PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_v_pytype);
      PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_v_pytype);
      __Pyx_GIVEREF(__pyx_v_pytype);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_6 = 0;
      __pyx_t_4 = 0;
      __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1632
 *                                       pytype,
 *                                       value )
 *                     offset += size             # <<<<<<<<<<<<<<
 * 
 *             # delete the old data and allocate new
 */
      __pyx_v_offset += __pyx_v_size;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1640
 *                               src.l_aux,
 *                               offset,
 *                               bam1_aux( src ) )             # <<<<<<<<<<<<<<
 * 
 *             src.l_aux = offset
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_src->l_aux, __pyx_v_offset, bam1_aux(__pyx_v_src));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1642
 *                               bam1_aux( src ) )
 * 
 *             src.l_aux = offset             # <<<<<<<<<<<<<<
 * 
 *             # copy data only if there is any
 */
  __pyx_v_src->l_aux = __pyx_v_offset;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1645
 * 
 *             # copy data only if there is any
 *             if offset != 0:             # <<<<<<<<<<<<<<
 * 
 *                 # get location of new data
 */
  __pyx_t_2 = (__pyx_v_offset != 0);
  if (__pyx_t_2) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1648
 * 
 *                 # get location of new data
 *                 s = bam1_aux( src )             # <<<<<<<<<<<<<<
 * 
 *                 # check if there is direct path from buffer.raw to tmp
 */
    __pyx_v_s = bam1_aux(__pyx_v_src);

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1651
 * 
 *                 # check if there is direct path from buffer.raw to tmp
 *                 temp = buffer.raw             # <<<<<<<<<<<<<<
 *                 memcpy( s, temp, offset )
 * 
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_buffer, __pyx_n_s__raw); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_temp = __pyx_t_11;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1652
 *                 # check if there is direct path from buffer.raw to tmp
 *                 temp = buffer.raw
 *                 memcpy( s, temp, offset )             # <<<<<<<<<<<<<<
 * 
 *     property flag:
 */
    memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_offset);
    goto __pyx_L14;
  }
  __pyx_L14:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.tags.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_buffer);
  __Pyx_DECREF(__pyx_v_pytag);
  __Pyx_DECREF(__pyx_v_value);
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_DECREF(__pyx_v_fmt);
  __Pyx_DECREF(__pyx_v_pytype);
  __Pyx_DECREF(__pyx_v_ctype);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1656
 *     property flag:
 *         """properties flag"""
 *         def __get__(self): return self._delegate.core.flag             # <<<<<<<<<<<<<<
 *         def __set__(self, flag): self._delegate.core.flag = flag
 *     property rname:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4flag___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4flag___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1656);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.flag.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1657
 *         """properties flag"""
 *         def __get__(self): return self._delegate.core.flag
 *         def __set__(self, flag): self._delegate.core.flag = flag             # <<<<<<<<<<<<<<
 *     property rname:
 *         """
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4flag___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4flag___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  uint32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1657);
  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.flag.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1669
 * 
 *         """
 *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
 *         def __set__(self, tid): self._delegate.core.tid = tid
 *     property pos:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5rname___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5rname___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1669);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.rname.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1670
 *         """
 *         def __get__(self): return self._delegate.core.tid
 *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
 *     property pos:
 *         """0-based leftmost coordinate"""
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5rname___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5rname___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  int32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1670);
  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.tid = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.rname.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1673
 *     property pos:
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
 *         def __set__(self, pos):
 *             ## setting the cigar string also updates the "bin" attribute
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3pos___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3pos___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1673);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.pos.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1674
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the cigar string also updates the "bin" attribute
 *             cdef bam1_t * src
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) {
  bam1_t *__pyx_v_src;
  int __pyx_r;
  int32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1674);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1677
 *             ## setting the cigar string also updates the "bin" attribute
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if src.core.n_cigar:
 *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1678
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if src.core.n_cigar:             # <<<<<<<<<<<<<<
 *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
 *             else:
 */
  if (__pyx_v_src->core.n_cigar) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1679
 *             src = self._delegate
 *             if src.core.n_cigar:
 *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )             # <<<<<<<<<<<<<<
 *             else:
 *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
 */
    __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)));
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1681
 *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
 *             else:
 *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)             # <<<<<<<<<<<<<<
 *             self._delegate.core.pos = pos
 *     property bin:
 */
    __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1));
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1682
 *             else:
 *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
 *             self._delegate.core.pos = pos             # <<<<<<<<<<<<<<
 *     property bin:
 *         """properties bin"""
 */
  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.pos = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.pos.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1685
 *     property bin:
 *         """properties bin"""
 *         def __get__(self): return self._delegate.core.bin             # <<<<<<<<<<<<<<
 *         def __set__(self, bin): self._delegate.core.bin = bin
 *     property rlen:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3bin___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3bin___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1685);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.bin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.bin.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1686
 *         """properties bin"""
 *         def __get__(self): return self._delegate.core.bin
 *         def __set__(self, bin): self._delegate.core.bin = bin             # <<<<<<<<<<<<<<
 *     property rlen:
 *         '''length of the read (read only). Returns 0 if not given.'''
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3bin___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3bin___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  uint32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1686);
  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.bin = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.bin.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1689
 *     property rlen:
 *         '''length of the read (read only). Returns 0 if not given.'''
 *         def __get__(self): return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
 *     property aend:
 *         '''aligned end position of the read (read only).  Returns
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4rlen___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4rlen___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1689);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.rlen.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1693
 *         '''aligned end position of the read (read only).  Returns
 *         None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4aend___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4aend___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1693);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1695
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
 *                 return None
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1696
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_calend(&src.core, bam1_cigar(src))
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_3) {
    __pyx_t_4 = (__pyx_v_src->core.n_cigar == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_3;
  }
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1697
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_calend(&src.core, bam1_cigar(src))
 *     property alen:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1698
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
 *                 return None
 *             return bam_calend(&src.core, bam1_cigar(src))             # <<<<<<<<<<<<<<
 *     property alen:
 *         '''aligned length of the read (read only).  Returns None if
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.aend.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1702
 *         '''aligned length of the read (read only).  Returns None if
 *         not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4alen___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4alen___get__(PyObject *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1702);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1704
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
 *                 return None
 */
  __pyx_v_src = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1705
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_calend(&src.core,
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_3) {
    __pyx_t_4 = (__pyx_v_src->core.n_cigar == 0);
    __pyx_t_5 = __pyx_t_4;
  } else {
    __pyx_t_5 = __pyx_t_3;
  }
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1706
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_calend(&src.core,
 *                                bam1_cigar(src)) - \
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1707
 *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
 *                 return None
 *             return bam_calend(&src.core,             # <<<<<<<<<<<<<<
 *                                bam1_cigar(src)) - \
 *                                self._delegate.core.pos
 */
  __Pyx_XDECREF(__pyx_r);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1709
 *             return bam_calend(&src.core,
 *                                bam1_cigar(src)) - \
 *                                self._delegate.core.pos             # <<<<<<<<<<<<<<
 * 
 *     property mapq:
 */
  __pyx_t_2 = __Pyx_PyInt_to_py_int32_t((bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)) - ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.alen.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1713
 *     property mapq:
 *         """mapping quality"""
 *         def __get__(self): return self._delegate.core.qual             # <<<<<<<<<<<<<<
 *         def __set__(self, qual): self._delegate.core.qual = qual
 *     property mrnm:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mapq___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mapq___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1713);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.qual); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mapq.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1714
 *         """mapping quality"""
 *         def __get__(self): return self._delegate.core.qual
 *         def __set__(self, qual): self._delegate.core.qual = qual             # <<<<<<<<<<<<<<
 *     property mrnm:
 *         """the :term:`reference` id of the mate """
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mapq___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mapq___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  uint32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1714);
  __pyx_t_1 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.qual = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mapq.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1717
 *     property mrnm:
 *         """the :term:`reference` id of the mate """
 *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
 *         def __set__(self, mtid): self._delegate.core.mtid = mtid
 *     property mpos:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mrnm___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mrnm___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1717);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mrnm.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1718
 *         """the :term:`reference` id of the mate """
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
 *     property mpos:
 *         """the position of the mate"""
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mrnm___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mrnm___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  int32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1718);
  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mtid = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mrnm.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1721
 *     property mpos:
 *         """the position of the mate"""
 *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
 *         def __set__(self, mpos): self._delegate.core.mpos = mpos
 *     property isize:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mpos___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mpos___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1721);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mpos.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1722
 *         """the position of the mate"""
 *         def __get__(self): return self._delegate.core.mpos
 *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
 *     property isize:
 *         """the insert size"""
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mpos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mpos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  int32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1722);
  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mpos = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mpos.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1725
 *     property isize:
 *         """the insert size"""
 *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
 *         def __set__(self, isize): self._delegate.core.isize = isize
 *     property is_paired:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5isize___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5isize___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1725);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.isize.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1726
 *         """the insert size"""
 *         def __get__(self): return self._delegate.core.isize
 *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5isize___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5isize___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  int32_t __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1726);
  __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.isize = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.isize.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1729
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FPAIRED
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_paired___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_paired___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1729);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(((((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & 1) != 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_paired.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1730
 *         """true if read is paired in sequencing"""
 *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FPAIRED
 *             else: self._delegate.core.flag &= ~BAM_FPAIRED
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_paired___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_paired___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1730);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1731
 *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FPAIRED             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FPAIRED
 *     property is_proper_pair:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 1;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1732
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FPAIRED
 *             else: self._delegate.core.flag &= ~BAM_FPAIRED             # <<<<<<<<<<<<<<
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~1);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_paired.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1735
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_14is_proper_pair___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_14is_proper_pair___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1735);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_proper_pair.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1736
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
 *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_14is_proper_pair___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_14is_proper_pair___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1736);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1737
 *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
 *     property is_unmapped:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 2;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1738
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
 *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~2);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_proper_pair.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1741
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FUNMAP
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_11is_unmapped___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_11is_unmapped___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1741);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_unmapped.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1742
 *         """true if read itself is unmapped"""
 *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FUNMAP
 *             else: self._delegate.core.flag &= ~BAM_FUNMAP
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_11is_unmapped___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_11is_unmapped___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1742);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1743
 *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FUNMAP             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FUNMAP
 *     property mate_is_unmapped:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 4;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1744
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FUNMAP
 *             else: self._delegate.core.flag &= ~BAM_FUNMAP             # <<<<<<<<<<<<<<
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~4);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_unmapped.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1747
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FMUNMAP
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1747);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mate_is_unmapped.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1748
 *         """true if the mate is unmapped"""
 *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FMUNMAP
 *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1748);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1749
 *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FMUNMAP             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
 *     property is_reverse:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 8;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1750
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FMUNMAP
 *             else: self._delegate.core.flag &= ~BAM_FMUNMAP             # <<<<<<<<<<<<<<
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~8);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mate_is_unmapped.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1753
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREVERSE
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_10is_reverse___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_10is_reverse___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1753);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_reverse.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1754
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FREVERSE
 *             else: self._delegate.core.flag &= ~BAM_FREVERSE
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_10is_reverse___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_10is_reverse___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1754);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1755
 *         def __get__(self):return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREVERSE             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FREVERSE
 *     property mate_is_reverse:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 16;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1756
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREVERSE
 *             else: self._delegate.core.flag &= ~BAM_FREVERSE             # <<<<<<<<<<<<<<
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~16);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_reverse.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1759
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FMREVERSE
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1759);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mate_is_reverse.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1760
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FMREVERSE
 *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1760);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1761
 *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FMREVERSE             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
 *     property is_read1:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 32;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1762
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FMREVERSE
 *             else: self._delegate.core.flag &= ~BAM_FMREVERSE             # <<<<<<<<<<<<<<
 *     property is_read1:
 *         """true if this is read1"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~32);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.mate_is_reverse.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1765
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self): return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREAD1
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read1___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read1___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1765);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_read1.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1766
 *         """true if this is read1"""
 *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FREAD1
 *             else: self._delegate.core.flag &= ~BAM_FREAD1
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read1___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read1___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1766);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1767
 *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREAD1             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FREAD1
 *     property is_read2:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 64;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1768
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREAD1
 *             else: self._delegate.core.flag &= ~BAM_FREAD1             # <<<<<<<<<<<<<<
 *     property is_read2:
 *         """true if this is read2"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~64);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_read1.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1771
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self): return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREAD2
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read2___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read2___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1771);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_read2.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1772
 *         """true if this is read2"""
 *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FREAD2
 *             else: self._delegate.core.flag &= ~BAM_FREAD2
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read2___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read2___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1772);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1773
 *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREAD2             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FREAD2
 *     property is_secondary:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 128;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1774
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FREAD2
 *             else: self._delegate.core.flag &= ~BAM_FREAD2             # <<<<<<<<<<<<<<
 *     property is_secondary:
 *         """true if not primary alignment"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~128);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_read2.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1777
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FSECONDARY
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_secondary___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_secondary___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1777);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_secondary.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1778
 *         """true if not primary alignment"""
 *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FSECONDARY
 *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_secondary___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_secondary___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1778);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1779
 *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FSECONDARY             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
 *     property is_qcfail:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 256;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1780
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FSECONDARY
 *             else: self._delegate.core.flag &= ~BAM_FSECONDARY             # <<<<<<<<<<<<<<
 *     property is_qcfail:
 *         """true if QC failure"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~256);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_secondary.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1783
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FQCFAIL
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_qcfail___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_qcfail___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1783);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_512); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_qcfail.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1784
 *         """true if QC failure"""
 *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FQCFAIL
 *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_qcfail___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_qcfail___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1784);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1785
 *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FQCFAIL             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
 *     property is_duplicate:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 512;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1786
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FQCFAIL
 *             else: self._delegate.core.flag &= ~BAM_FQCFAIL             # <<<<<<<<<<<<<<
 *     property is_duplicate:
 *         """ true if optical or PCR duplicate"""
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~512);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_qcfail.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1789
 *     property is_duplicate:
 *         """ true if optical or PCR duplicate"""
 *         def __get__(self): return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FDUP
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_duplicate___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_duplicate___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1789);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_1024); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_duplicate.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1790
 *         """ true if optical or PCR duplicate"""
 *         def __get__(self): return (self.flag & BAM_FDUP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             if val: self._delegate.core.flag |= BAM_FDUP
 *             else: self._delegate.core.flag &= ~BAM_FDUP
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_duplicate___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_duplicate___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1790);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1791
 *         def __get__(self): return (self.flag & BAM_FDUP) != 0
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FDUP             # <<<<<<<<<<<<<<
 *             else: self._delegate.core.flag &= ~BAM_FDUP
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag |= 1024;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1792
 *         def __set__(self,val):
 *             if val: self._delegate.core.flag |= BAM_FDUP
 *             else: self._delegate.core.flag &= ~BAM_FDUP             # <<<<<<<<<<<<<<
 * 
 *     def opt(self, tag):
 */
    ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag &= (~1024);
  }
  __pyx_L5:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.is_duplicate.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1794
 *             else: self._delegate.core.flag &= ~BAM_FDUP
 * 
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         """retrieves optional data given a two-letter *tag*"""
 *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead_opt[] = "AlignedRead.opt(self, tag)\nretrieves optional data given a two-letter *tag*";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  uint8_t *__pyx_v_v;
  PyObject *__pyx_v_type;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("opt");
  __Pyx_TraceCall("opt", __pyx_f[0], 1794);
  __pyx_v_type = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1798
 *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
 *         cdef uint8_t * v
 *         v = bam_aux_get(self._delegate, tag)             # <<<<<<<<<<<<<<
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 *         type = chr(v[0])
 */
  __pyx_t_1 = PyBytes_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_v = bam_aux_get(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)__pyx_v_self)->_delegate, __pyx_t_1);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1799
 *         cdef uint8_t * v
 *         v = bam_aux_get(self._delegate, tag)
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )             # <<<<<<<<<<<<<<
 *         type = chr(v[0])
 *         if type == 'c' or type == 'C' or type == 's' or type == 'S' or type == 'i':
 */
  __pyx_t_2 = (__pyx_v_v == NULL);
  if (__pyx_t_2) {
    __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_64), __pyx_v_tag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1800
 *         v = bam_aux_get(self._delegate, tag)
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 *         type = chr(v[0])             # <<<<<<<<<<<<<<
 *         if type == 'c' or type == 'C' or type == 's' or type == 'S' or type == 'i':
 *             return <int>bam_aux2i(v)
 */
  __pyx_t_3 = __Pyx_PyInt_to_py_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_builtin_chr, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_v_type);
  __pyx_v_type = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1801
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 *         type = chr(v[0])
 *         if type == 'c' or type == 'C' or type == 's' or type == 'S' or type == 'i':             # <<<<<<<<<<<<<<
 *             return <int>bam_aux2i(v)
 *         elif type == 'f':
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__c), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!__pyx_t_2) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__C), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!__pyx_t_5) {
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__s), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_6) {
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__S), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (!__pyx_t_7) {
          __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__i), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_9 = __pyx_t_8;
        } else {
          __pyx_t_9 = __pyx_t_7;
        }
        __pyx_t_7 = __pyx_t_9;
      } else {
        __pyx_t_7 = __pyx_t_6;
      }
      __pyx_t_6 = __pyx_t_7;
    } else {
      __pyx_t_6 = __pyx_t_5;
    }
    __pyx_t_5 = __pyx_t_6;
  } else {
    __pyx_t_5 = __pyx_t_2;
  }
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1802
 *         type = chr(v[0])
 *         if type == 'c' or type == 'C' or type == 's' or type == 'S' or type == 'i':
 *             return <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif type == 'f':
 *             return <float>bam_aux2f(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyInt_FromLong(bam_aux2i(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1803
 *         if type == 'c' or type == 'C' or type == 's' or type == 'S' or type == 'i':
 *             return <int>bam_aux2i(v)
 *         elif type == 'f':             # <<<<<<<<<<<<<<
 *             return <float>bam_aux2f(v)
 *         elif type == 'd':
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__f), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1804
 *             return <int>bam_aux2i(v)
 *         elif type == 'f':
 *             return <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif type == 'd':
 *             return <double>bam_aux2d(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyFloat_FromDouble(bam_aux2f(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1805
 *         elif type == 'f':
 *             return <float>bam_aux2f(v)
 *         elif type == 'd':             # <<<<<<<<<<<<<<
 *             return <double>bam_aux2d(v)
 *         elif type == 'A':
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__d), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1806
 *             return <float>bam_aux2f(v)
 *         elif type == 'd':
 *             return <double>bam_aux2d(v)             # <<<<<<<<<<<<<<
 *         elif type == 'A':
 *             # there might a more efficient way
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyFloat_FromDouble(bam_aux2d(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1807
 *         elif type == 'd':
 *             return <double>bam_aux2d(v)
 *         elif type == 'A':             # <<<<<<<<<<<<<<
 *             # there might a more efficient way
 *             # to convert a char into a string
 */
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__A), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1810
 *             # there might a more efficient way
 *             # to convert a char into a string
 *             return '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
 *         elif type == 'Z':
 *             return <char*>bam_aux2Z(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyInt_FromLong(bam_aux2A(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_51), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1811
 *             # to convert a char into a string
 *             return '%c' % <char>bam_aux2A(v)
 *         elif type == 'Z':             # <<<<<<<<<<<<<<
 *             return <char*>bam_aux2Z(v)
 * 
 */
  __pyx_t_4 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__Z), Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1812
 *             return '%c' % <char>bam_aux2A(v)
 *         elif type == 'Z':
 *             return <char*>bam_aux2Z(v)             # <<<<<<<<<<<<<<
 * 
 *     def fancy_str (self):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = PyBytes_FromString(bam_aux2Z(__pyx_v_v)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __pyx_r = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.opt");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_type);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1814
 *             return <char*>bam_aux2Z(v)
 * 
 *     def fancy_str (self):             # <<<<<<<<<<<<<<
 *         """returns list of fieldnames/values in pretty format for debugging
 *         """
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead_fancy_str[] = "AlignedRead.fancy_str(self)\nreturns list of fieldnames/values in pretty format for debugging\n        ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_v_ret_string;
  PyObject *__pyx_v_field_names;
  PyObject *__pyx_v_fields_names_in_order;
  PyObject *__pyx_v_f;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("fancy_str");
  __Pyx_TraceCall("fancy_str", __pyx_f[0], 1814);
  __pyx_v_ret_string = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_field_names = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_fields_names_in_order = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_f = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1817
 *         """returns list of fieldnames/values in pretty format for debugging
 *         """
 *         ret_string = []             # <<<<<<<<<<<<<<
 *         field_names = {
 *            "tid":           "Contig index",
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_ret_string));
  __pyx_v_ret_string = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1818
 *         """
 *         ret_string = []
 *         field_names = {             # <<<<<<<<<<<<<<
 *            "tid":           "Contig index",
 *            "pos":           "Mapped position on contig",
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__tid), ((PyObject *)__pyx_kp_s_65)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), ((PyObject *)__pyx_kp_s_66)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mtid), ((PyObject *)__pyx_kp_s_67)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mpos), ((PyObject *)__pyx_kp_s_68)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__isize), ((PyObject *)__pyx_kp_s_69)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__flag), ((PyObject *)__pyx_kp_s_70)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__n_cigar), ((PyObject *)__pyx_kp_s_71)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__cigar), ((PyObject *)__pyx_kp_s_72)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qual), ((PyObject *)__pyx_kp_s_73)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bin), ((PyObject *)__pyx_kp_s_74)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qname), ((PyObject *)__pyx_kp_s_75)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qname), ((PyObject *)__pyx_kp_s_76)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qseq), ((PyObject *)__pyx_kp_s_77)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qseq), ((PyObject *)__pyx_kp_s_78)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bqual), ((PyObject *)__pyx_kp_s_79)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_aux), ((PyObject *)__pyx_kp_s_80)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__m_data), ((PyObject *)__pyx_kp_s_81)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__data_len), ((PyObject *)__pyx_kp_s_82)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_v_field_names));
  __pyx_v_field_names = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1838
 *            "data_len":      "Current data length",
 *            }
 *         fields_names_in_order = ["tid", "pos", "mtid", "mpos", "isize", "flag",             # <<<<<<<<<<<<<<
 *                                  "n_cigar", "cigar", "qual", "bin", "l_qname", "qname",
 *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
 */
  __pyx_t_1 = PyList_New(18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__tid));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__tid));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tid));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mtid));
  PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__mtid));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mtid));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mpos));
  PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__mpos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mpos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__isize));
  PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__isize));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isize));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__flag));
  PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__flag));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__flag));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__n_cigar));
  PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__n_cigar));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__n_cigar));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__cigar));
  PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__cigar));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cigar));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__qual));
  PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s__qual));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qual));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bin));
  PyList_SET_ITEM(__pyx_t_1, 9, ((PyObject *)__pyx_n_s__bin));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__l_qname));
  PyList_SET_ITEM(__pyx_t_1, 10, ((PyObject *)__pyx_n_s__l_qname));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_qname));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__qname));
  PyList_SET_ITEM(__pyx_t_1, 11, ((PyObject *)__pyx_n_s__qname));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qname));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__l_qseq));
  PyList_SET_ITEM(__pyx_t_1, 12, ((PyObject *)__pyx_n_s__l_qseq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_qseq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__qseq));
  PyList_SET_ITEM(__pyx_t_1, 13, ((PyObject *)__pyx_n_s__qseq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qseq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bqual));
  PyList_SET_ITEM(__pyx_t_1, 14, ((PyObject *)__pyx_n_s__bqual));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bqual));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__l_aux));
  PyList_SET_ITEM(__pyx_t_1, 15, ((PyObject *)__pyx_n_s__l_aux));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_aux));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__m_data));
  PyList_SET_ITEM(__pyx_t_1, 16, ((PyObject *)__pyx_n_s__m_data));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__m_data));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__data_len));
  PyList_SET_ITEM(__pyx_t_1, 17, ((PyObject *)__pyx_n_s__data_len));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__data_len));
  __Pyx_DECREF(((PyObject *)__pyx_v_fields_names_in_order));
  __pyx_v_fields_names_in_order = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1842
 *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
 * 
 *         for f in fields_names_in_order:             # <<<<<<<<<<<<<<
 *             if not f in self.__dict__:
 *                 continue
 */
  if (likely(((PyObject *)__pyx_v_fields_names_in_order) != Py_None)) {
    __pyx_t_2 = 0; __pyx_t_1 = ((PyObject *)__pyx_v_fields_names_in_order); __Pyx_INCREF(__pyx_t_1);
  } else {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
    __Pyx_DECREF(__pyx_v_f);
    __pyx_v_f = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1843
 * 
 *         for f in fields_names_in_order:
 *             if not f in self.__dict__:             # <<<<<<<<<<<<<<
 *                 continue
 *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____dict__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = ((PySequence_Contains(__pyx_t_3, __pyx_v_f))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = (!__pyx_t_4);
    if (__pyx_t_5) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1844
 *         for f in fields_names_in_order:
 *             if not f in self.__dict__:
 *                 continue             # <<<<<<<<<<<<<<
 *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
 * 
 */
      goto __pyx_L5_continue;
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1845
 *             if not f in self.__dict__:
 *                 continue
 *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
 * 
 *         for f in self.__dict__:
 */
    if (unlikely(__pyx_v_ret_string == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_field_names), __pyx_v_f); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PyNumber_Add(((PyObject *)__pyx_kp_s_84), __pyx_v_f); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyNumber_Add(__pyx_t_6, ((PyObject *)__pyx_kp_s_85)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_f);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
    __Pyx_GIVEREF(__pyx_v_f);
    __pyx_t_9 = PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_3 = 0;
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_83), __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_10 = PyList_Append(((PyObject *)__pyx_v_ret_string), ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __pyx_L5_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1847
 *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
 * 
 *         for f in self.__dict__:             # <<<<<<<<<<<<<<
 *             if not f in field_names:
 *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____dict__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = 0; __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9);
  } else {
    __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_9))) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_9)) break;
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_9))) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
    } else {
      __pyx_t_1 = PyIter_Next(__pyx_t_9);
      if (!__pyx_t_1) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_DECREF(__pyx_v_f);
    __pyx_v_f = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1848
 * 
 *         for f in self.__dict__:
 *             if not f in field_names:             # <<<<<<<<<<<<<<
 *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
 *         return ret_string
 */
    if (unlikely(((PyObject *)__pyx_v_field_names) == Py_None)) {
      __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {
      __pyx_t_5 = ((PyDict_Contains(((PyObject *)__pyx_v_field_names), __pyx_v_f))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = (!__pyx_t_5);
    if (__pyx_t_4) {

      /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1849
 *         for f in self.__dict__:
 *             if not f in field_names:
 *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
 *         return ret_string
 * 
 */
      if (unlikely(__pyx_v_ret_string == Py_None)) {
        PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
      }
      __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_f);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
      __Pyx_GIVEREF(__pyx_v_f);
      __pyx_t_7 = PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_f);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
      __Pyx_GIVEREF(__pyx_v_f);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
      PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_kp_s_46));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46));
      PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_83), __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_7));
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_10 = PyList_Append(((PyObject *)__pyx_v_ret_string), ((PyObject *)__pyx_t_7)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      goto __pyx_L10;
    }
    __pyx_L10:;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1850
 *             if not f in field_names:
 *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
 *         return ret_string             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupProxy:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_ret_string));
  __pyx_r = ((PyObject *)__pyx_v_ret_string);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.AlignedRead.fancy_str");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ret_string);
  __Pyx_DECREF(__pyx_v_field_names);
  __Pyx_DECREF(__pyx_v_fields_names_in_order);
  __Pyx_DECREF(__pyx_v_f);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1874
 *     cdef int n_pu
 * 
 *     def __cinit__(self ):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1874);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;

  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1877
 *         pass
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy___str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy___str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__");
  __Pyx_TraceCall("__str__", __pyx_f[0], 1877);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1878
 * 
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
 *             "\n" +\
 *             "\n".join( map(str, self.pileups) )
 */
  __Pyx_XDECREF(__pyx_r);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1879
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\             # <<<<<<<<<<<<<<
 *             "\n".join( map(str, self.pileups) )
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1878
 * 
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
 *             "\n" +\
 *             "\n".join( map(str, self.pileups) )
 */
  __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_builtin_map, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1880
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\
 *             "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
 * 
 *     property tid:
 */
  __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_2), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupProxy.__str__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1884
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self): return self.tid             # <<<<<<<<<<<<<<
 * 
 *     property n:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_3tid___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_3tid___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1884);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupProxy.tid.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1888
 *     property n:
 *         '''number of reads mapping to this column.'''
 *         def __get__(self): return self.n_pu             # <<<<<<<<<<<<<<
 *         def __set__(self, n): self.n_pu = n
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_1n___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_1n___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1888);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupProxy.n.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1889
 *         '''number of reads mapping to this column.'''
 *         def __get__(self): return self.n_pu
 *         def __set__(self, n): self.n_pu = n             # <<<<<<<<<<<<<<
 * 
 *     property pos:
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_1n___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_1n___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__");
  __Pyx_TraceCall("__set__", __pyx_f[0], 1889);
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->n_pu = __pyx_t_1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupProxy.n.__set__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1892
 * 
 *     property pos:
 *         def __get__(self): return self.pos             # <<<<<<<<<<<<<<
 * 
 *     property pileups:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_3pos___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_3pos___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1892);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupProxy.pos.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1896
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_7pileups___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_7pileups___get__(PyObject *__pyx_v_self) {
  int __pyx_v_x;
  PyObject *__pyx_v_pileups;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1896);
  __pyx_v_pileups = ((PyObject *)Py_None); __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1898
 *         def __get__(self):
 *             cdef int x
 *             pileups = []             # <<<<<<<<<<<<<<
 *             # warning: there could be problems if self.n and self.buf are
 *             # out of sync.
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_DECREF(((PyObject *)__pyx_v_pileups));
  __pyx_v_pileups = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1901
 *             # warning: there could be problems if self.n and self.buf are
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:             # <<<<<<<<<<<<<<
 *                 pileups.append( makePileupRead( &(self.plp[x])) )
 *             return pileups
 */
  __pyx_t_2 = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->n_pu;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1902
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append( makePileupRead( &(self.plp[x])) )             # <<<<<<<<<<<<<<
 *             return pileups
 * 
 */
    if (unlikely(__pyx_v_pileups == Py_None)) {
      PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
    }
    __pyx_t_1 = __pyx_f_11chimerascan_5pysam_9csamtools_makePileupRead((&(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy *)__pyx_v_self)->plp[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyList_Append(((PyObject *)__pyx_v_pileups), __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1903
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append( makePileupRead( &(self.plp[x])) )
 *             return pileups             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupRead:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_pileups));
  __pyx_r = ((PyObject *)__pyx_v_pileups);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupProxy.pileups.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_pileups);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1918
 *          uint32_t _is_tail
 * 
 *     def __cinit__( self ):             # <<<<<<<<<<<<<<
 *         pass
 * 
 */

static int __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__");
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1918);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;

  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1921
 *         pass
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead___str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead___str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__");
  __Pyx_TraceCall("__str__", __pyx_f[0], 1921);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1922
 * 
 *     def __str__(self):
 *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )             # <<<<<<<<<<<<<<
 * 
 *     property alignment:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__alignment); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__qpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__indel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__level); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__is_del); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__is_head); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__is_tail); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)((PyObject*)&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.__str__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1926
 *     property alignment:
 *         """a :class:`pysam.AlignedRead` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 *     property qpos:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_9alignment___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_9alignment___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1926);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1927
 *         """a :class:`pysam.AlignedRead` object of the aligned read"""
 *         def __get__(self):
 *             return self._alignment             # <<<<<<<<<<<<<<
 *     property qpos:
 *         """position of the read base at the pileup site, 0-based"""
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_alignment));
  __pyx_r = ((PyObject *)((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_alignment);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1930
 *     property qpos:
 *         """position of the read base at the pileup site, 0-based"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._qpos
 *     property indel:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_4qpos___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_4qpos___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1930);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1931
 *         """position of the read base at the pileup site, 0-based"""
 *         def __get__(self):
 *             return self._qpos             # <<<<<<<<<<<<<<
 *     property indel:
 *         """indel length; 0 for no indel, positive for ins and negative for del"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.qpos.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1934
 *     property indel:
 *         """indel length; 0 for no indel, positive for ins and negative for del"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 *     property is_del:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_5indel___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_5indel___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1934);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1935
 *         """indel length; 0 for no indel, positive for ins and negative for del"""
 *         def __get__(self):
 *             return self._indel             # <<<<<<<<<<<<<<
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.indel.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1938
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 *     property is_head:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_6is_del___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_6is_del___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1938);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1939
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):
 *             return self._is_del             # <<<<<<<<<<<<<<
 *     property is_head:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.is_del.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1941
 *             return self._is_del
 *     property is_head:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 *     property is_tail:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_7is_head___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_7is_head___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1941);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1942
 *     property is_head:
 *         def __get__(self):
 *             return self._is_head             # <<<<<<<<<<<<<<
 *     property is_tail:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.is_head.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1944
 *             return self._is_head
 *     property is_tail:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 *     property level:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_7is_tail___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_7is_tail___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1944);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1945
 *     property is_tail:
 *         def __get__(self):
 *             return self._is_tail             # <<<<<<<<<<<<<<
 *     property level:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.is_tail.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1947
 *             return self._is_tail
 *     property level:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_5level___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_5level___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__");
  __Pyx_TraceCall("__get__", __pyx_f[0], 1947);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1948
 *     property level:
 *         def __get__(self):
 *             return self._level             # <<<<<<<<<<<<<<
 * 
 * class Outs:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)__pyx_v_self)->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.PileupRead.level.__get__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1952
 * class Outs:
 *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
 *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
 *         self.streams = []
 *         self.id = id
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_4Outs___init__[] = "Outs.__init__(self, id=1)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs___init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs___init__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_4Outs___init__)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__id,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__");
  __Pyx_TraceCall("__init__", __pyx_f[0], 1952);
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__id);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  } else {
    __pyx_v_id = ((PyObject *)__pyx_int_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_id = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.__init__");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1953
 *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
 *     def __init__(self, id = 1):
 *         self.streams = []             # <<<<<<<<<<<<<<
 *         self.id = id
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__streams, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1954
 *     def __init__(self, id = 1):
 *         self.streams = []
 *         self.id = id             # <<<<<<<<<<<<<<
 * 
 *     def setdevice(self, filename):
 */
  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__id, __pyx_v_id) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.__init__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1956
 *         self.id = id
 * 
 *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
 *         '''open an existing file, like "/dev/null"'''
 *         fd = os.open(filename, os.O_WRONLY)
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setdevice(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_setdevice[] = "Outs.setdevice(self, filename)\nopen an existing file, like \"/dev/null\"";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_setdevice = {__Pyx_NAMESTR("setdevice"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setdevice, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_setdevice)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setdevice(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_fd;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__filename,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setdevice");
  __Pyx_TraceCall("setdevice", __pyx_f[0], 1956);
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "setdevice") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_filename = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_filename = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.setdevice");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_fd = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1958
 *     def setdevice(self, filename):
 *         '''open an existing file, like "/dev/null"'''
 *         fd = os.open(filename, os.O_WRONLY)             # <<<<<<<<<<<<<<
 *         self.setfd(fd)
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_WRONLY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_filename);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename);
  __Pyx_GIVEREF(__pyx_v_filename);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_fd);
  __pyx_v_fd = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1959
 *         '''open an existing file, like "/dev/null"'''
 *         fd = os.open(filename, os.O_WRONLY)
 *         self.setfd(fd)             # <<<<<<<<<<<<<<
 * 
 *     def setfile(self, filename):
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_fd);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fd);
  __Pyx_GIVEREF(__pyx_v_fd);
  __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.setdevice");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_fd);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1961
 *         self.setfd(fd)
 * 
 *     def setfile(self, filename):             # <<<<<<<<<<<<<<
 *         '''open a new file.'''
 *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_setfile[] = "Outs.setfile(self, filename)\nopen a new file.";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_setfile = {__Pyx_NAMESTR("setfile"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setfile, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_setfile)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_fd;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__filename,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setfile");
  __Pyx_TraceCall("setfile", __pyx_f[0], 1961);
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "setfile") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_filename = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_filename = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.setfile");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_fd = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1963
 *     def setfile(self, filename):
 *         '''open a new file.'''
 *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);             # <<<<<<<<<<<<<<
 *         self.setfd(fd)
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_WRONLY); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__O_CREAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_filename);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_filename);
  __Pyx_GIVEREF(__pyx_v_filename);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_0660);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0660);
  __Pyx_GIVEREF(__pyx_int_0660);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_v_fd);
  __pyx_v_fd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1964
 *         '''open a new file.'''
 *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
 *         self.setfd(fd)             # <<<<<<<<<<<<<<
 * 
 *     def setfd(self, fd):
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1964; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1964; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_fd);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fd);
  __Pyx_GIVEREF(__pyx_v_fd);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1964; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.setfile");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_fd);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1966
 *         self.setfd(fd)
 * 
 *     def setfd(self, fd):             # <<<<<<<<<<<<<<
 *         ofd = os.dup(self.id)      #  Save old stream on new unit.
 *         self.streams.append(ofd)
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_setfd[] = "Outs.setfd(self, fd)";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_setfd = {__Pyx_NAMESTR("setfd"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setfd, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_setfd)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_setfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_fd = 0;
  PyObject *__pyx_v_ofd;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__fd,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setfd");
  __Pyx_TraceCall("setfd", __pyx_f[0], 1966);
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fd);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "setfd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_fd = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_fd = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.setfd");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_ofd = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1967
 * 
 *     def setfd(self, fd):
 *         ofd = os.dup(self.id)      #  Save old stream on new unit.             # <<<<<<<<<<<<<<
 *         self.streams.append(ofd)
 *         sys.stdout.flush()          #  Buffered data goes to old stream.
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_v_ofd);
  __pyx_v_ofd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1968
 *     def setfd(self, fd):
 *         ofd = os.dup(self.id)      #  Save old stream on new unit.
 *         self.streams.append(ofd)             # <<<<<<<<<<<<<<
 *         sys.stdout.flush()          #  Buffered data goes to old stream.
 *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_ofd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1969
 *         ofd = os.dup(self.id)      #  Save old stream on new unit.
 *         self.streams.append(ofd)
 *         sys.stdout.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
 *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
 *         os.close(fd)                #  Close other unit (look out, caller.)
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1970
 *         self.streams.append(ofd)
 *         sys.stdout.flush()          #  Buffered data goes to old stream.
 *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.             # <<<<<<<<<<<<<<
 *         os.close(fd)                #  Close other unit (look out, caller.)
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_fd);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fd);
  __Pyx_GIVEREF(__pyx_v_fd);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1971
 *         sys.stdout.flush()          #  Buffered data goes to old stream.
 *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
 *         os.close(fd)                #  Close other unit (look out, caller.)             # <<<<<<<<<<<<<<
 * 
 *     def restore(self):
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_fd);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fd);
  __Pyx_GIVEREF(__pyx_v_fd);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1971; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.setfd");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_ofd);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1973
 *         os.close(fd)                #  Close other unit (look out, caller.)
 * 
 *     def restore(self):             # <<<<<<<<<<<<<<
 *         '''restore previous output stream'''
 *         if self.streams:
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_restore(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_restore[] = "Outs.restore(self)\nrestore previous output stream";
static PyMethodDef __pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_restore = {__Pyx_NAMESTR("restore"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_restore, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_4Outs_restore)};
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools_4Outs_restore(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("restore");
  __Pyx_TraceCall("restore", __pyx_f[0], 1973);
  __pyx_self = __pyx_self;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1975
 *     def restore(self):
 *         '''restore previous output stream'''
 *         if self.streams:             # <<<<<<<<<<<<<<
 *             # the following was not sufficient, hence flush both stderr and stdout
 *             # os.fsync( self.id )
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1978
 *             # the following was not sufficient, hence flush both stderr and stdout
 *             # os.fsync( self.id )
 *             sys.stdout.flush()             # <<<<<<<<<<<<<<
 *             sys.stderr.flush()
 *             os.dup2(self.streams[-1], self.id)
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stdout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1979
 *             # os.fsync( self.id )
 *             sys.stdout.flush()
 *             sys.stderr.flush()             # <<<<<<<<<<<<<<
 *             os.dup2(self.streams[-1], self.id)
 *             os.close(self.streams[-1])
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1980
 *             sys.stdout.flush()
 *             sys.stderr.flush()
 *             os.dup2(self.streams[-1], self.id)             # <<<<<<<<<<<<<<
 *             os.close(self.streams[-1])
 *             del self.streams[-1]
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1981
 *             sys.stderr.flush()
 *             os.dup2(self.streams[-1], self.id)
 *             os.close(self.streams[-1])             # <<<<<<<<<<<<<<
 *             del self.streams[-1]
 * 
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_5, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1982
 *             os.dup2(self.streams[-1], self.id)
 *             os.close(self.streams[-1])
 *             del self.streams[-1]             # <<<<<<<<<<<<<<
 * 
 * def _samtools_dispatch( method, args = () ):
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_DelItemInt(__pyx_t_3, -1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools.Outs.restore");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1984
 *             del self.streams[-1]
 * 
 * def _samtools_dispatch( method, args = () ):             # <<<<<<<<<<<<<<
 *     '''call ``method`` in samtools providing arguments in args.
 * 
 */

static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools__samtools_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_11chimerascan_5pysam_9csamtools__samtools_dispatch[] = "_samtools_dispatch(method, args=())\ncall ``method`` in samtools providing arguments in args.\n    \n    .. note:: \n       This method redirects stdout and stderr to capture it \n       from samtools. If for some reason stdout/stderr disappears\n       the reason might be in this method.\n\n    .. note::\n       The current implementation might only work on linux.\n       \n    .. note:: \n       This method captures stdout and stderr using temporary files, \n       which are then read into memory in their entirety. This method\n       is slow and might cause large memory overhead. \n\n    See http://bytes.com/topic/c/answers/487231-how-capture-stdout-temporarily\n    on the topic of redirecting stderr/stdout.\n    ";
static PyObject *__pyx_pf_11chimerascan_5pysam_9csamtools__samtools_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_method = 0;
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_stderr_h;
  PyObject *__pyx_v_stderr_f;
  PyObject *__pyx_v_stdout_h;
  PyObject *__pyx_v_stdout_f;
  PyObject *__pyx_v_stdout_save;
  PyObject *__pyx_v_stderr_save;
  char **__pyx_v_cargs;
  int __pyx_v_i;
  int __pyx_v_n;
  int __pyx_v_retval;
  PyObject *__pyx_v_out_stderr;
  PyObject *__pyx_v_out_stdout;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  char *__pyx_t_7;
  int __pyx_t_8;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__method,&__pyx_n_s__args,0};
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_samtools_dispatch");
  __Pyx_TraceCall("_samtools_dispatch", __pyx_f[0], 1984);
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_empty_tuple);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__method);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__args);
        if (value) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_samtools_dispatch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_method = values[0];
    __pyx_v_args = values[1];
  } else {
    __pyx_v_args = ((PyObject *)__pyx_empty_tuple);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_args = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_method = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_samtools_dispatch", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("chimerascan.pysam.csamtools._samtools_dispatch");
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_args);
  __pyx_v_stderr_h = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_stderr_f = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_stdout_h = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_stdout_f = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_stdout_save = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_stderr_save = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_out_stderr = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_out_stdout = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2010
 * 
 *     # open files and redirect into it
 *     stderr_h, stderr_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
 *     stdout_h, stdout_f = tempfile.mkstemp()
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
    PyObject* tuple = __pyx_t_1;
    __pyx_t_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_v_stderr_h);
    __pyx_v_stderr_h = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_stderr_f);
    __pyx_v_stderr_f = __pyx_t_3;
    __pyx_t_3 = 0;
  } else {
    __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_4, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_4, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_EndUnpack(__pyx_t_4, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_stderr_h);
    __pyx_v_stderr_h = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_stderr_f);
    __pyx_v_stderr_f = __pyx_t_3;
    __pyx_t_3 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2011
 *     # open files and redirect into it
 *     stderr_h, stderr_f = tempfile.mkstemp()
 *     stdout_h, stdout_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
 * 
 *     # patch for `samtools view`
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
    PyObject* tuple = __pyx_t_1;
    __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_v_stdout_h);
    __pyx_v_stdout_h = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_stdout_f);
    __pyx_v_stdout_f = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_4, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_4, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_EndUnpack(__pyx_t_4, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_stdout_h);
    __pyx_v_stdout_h = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_stdout_f);
    __pyx_v_stdout_f = __pyx_t_2;
    __pyx_t_2 = 0;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2016
 *     # samtools `view` closes stdout, from which I can not
 *     # recover. Thus redirect output to file with -o option.
 *     if method == "view":             # <<<<<<<<<<<<<<
 *         if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
 *         args = ( "-o", stdout_f ) + args
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__view), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_5) {

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2017
 *     # recover. Thus redirect output to file with -o option.
 *     if method == "view":
 *         if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
 *         args = ( "-o", stdout_f ) + args
 * 
 */
    __pyx_t_5 = ((PySequence_Contains(__pyx_v_args, ((PyObject *)__pyx_kp_s_86)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_5) {
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_kp_s_87));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_87));
      __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87));
      __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_2, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2018
 *     if method == "view":
 *         if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
 *         args = ( "-o", stdout_f ) + args             # <<<<<<<<<<<<<<
 * 
 *     stdout_save = Outs( sys.stdout.fileno() )
 */
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_86));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_86));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_86));
    __Pyx_INCREF(__pyx_v_stdout_f);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_stdout_f);
    __Pyx_GIVEREF(__pyx_v_stdout_f);
    __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_v_args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_args);
    __pyx_v_args = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2020
 *         args = ( "-o", stdout_f ) + args
 * 
 *     stdout_save = Outs( sys.stdout.fileno() )             # <<<<<<<<<<<<<<
 *     stdout_save.setfd( stdout_h )
 *     stderr_save = Outs( sys.stderr.fileno() )
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__stdout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fileno); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_v_stdout_save);
  __pyx_v_stdout_save = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2021
 * 
 *     stdout_save = Outs( sys.stdout.fileno() )
 *     stdout_save.setfd( stdout_h )             # <<<<<<<<<<<<<<
 *     stderr_save = Outs( sys.stderr.fileno() )
 *     stderr_save.setfd( stderr_h )
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_stdout_h);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_stdout_h);
  __Pyx_GIVEREF(__pyx_v_stdout_h);
  __pyx_t_1 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2022
 *     stdout_save = Outs( sys.stdout.fileno() )
 *     stdout_save.setfd( stdout_h )
 *     stderr_save = Outs( sys.stderr.fileno() )             # <<<<<<<<<<<<<<
 *     stderr_save.setfd( stderr_h )
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fileno); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_v_stderr_save);
  __pyx_v_stderr_save = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2023
 *     stdout_save.setfd( stdout_h )
 *     stderr_save = Outs( sys.stderr.fileno() )
 *     stderr_save.setfd( stderr_h )             # <<<<<<<<<<<<<<
 * 
 *     # do the function call to samtools
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_stderr_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_stderr_h);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_stderr_h);
  __Pyx_GIVEREF(__pyx_v_stderr_h);
  __pyx_t_1 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2029
 *     cdef int i, n, retval
 * 
 *     n = len(args)             # <<<<<<<<<<<<<<
 *     # allocate two more for first (dummy) argument (contains command)
 *     cargs = <char**>calloc( n+2, sizeof( char *) )
 */
  __pyx_t_6 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_n = __pyx_t_6;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2031
 *     n = len(args)
 *     # allocate two more for first (dummy) argument (contains command)
 *     cargs = <char**>calloc( n+2, sizeof( char *) )             # <<<<<<<<<<<<<<
 *     cargs[0] = "samtools"
 *     cargs[1] = method
 */
  __pyx_v_cargs = ((char **)calloc((__pyx_v_n + 2), (sizeof(char *))));

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2032
 *     # allocate two more for first (dummy) argument (contains command)
 *     cargs = <char**>calloc( n+2, sizeof( char *) )
 *     cargs[0] = "samtools"             # <<<<<<<<<<<<<<
 *     cargs[1] = method
 *     for i from 0 <= i < n: cargs[i+2] = args[i]
 */
  (__pyx_v_cargs[0]) = __pyx_k__samtools;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2033
 *     cargs = <char**>calloc( n+2, sizeof( char *) )
 *     cargs[0] = "samtools"
 *     cargs[1] = method             # <<<<<<<<<<<<<<
 *     for i from 0 <= i < n: cargs[i+2] = args[i]
 *     retval = pysam_dispatch(n+2, cargs)
 */
  __pyx_t_7 = PyBytes_AsString(__pyx_v_method); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  (__pyx_v_cargs[1]) = __pyx_t_7;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2034
 *     cargs[0] = "samtools"
 *     cargs[1] = method
 *     for i from 0 <= i < n: cargs[i+2] = args[i]             # <<<<<<<<<<<<<<
 *     retval = pysam_dispatch(n+2, cargs)
 *     free( cargs )
 */
  __pyx_t_8 = __pyx_v_n;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    (__pyx_v_cargs[(__pyx_v_i + 2)]) = __pyx_t_7;
  }

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2035
 *     cargs[1] = method
 *     for i from 0 <= i < n: cargs[i+2] = args[i]
 *     retval = pysam_dispatch(n+2, cargs)             # <<<<<<<<<<<<<<
 *     free( cargs )
 * 
 */
  __pyx_v_retval = pysam_dispatch((__pyx_v_n + 2), __pyx_v_cargs);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2036
 *     for i from 0 <= i < n: cargs[i+2] = args[i]
 *     retval = pysam_dispatch(n+2, cargs)
 *     free( cargs )             # <<<<<<<<<<<<<<
 * 
 *     # restore stdout/stderr. This will also flush, so
 */
  free(__pyx_v_cargs);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2040
 *     # restore stdout/stderr. This will also flush, so
 *     # needs to be before reading back the file contents
 *     stdout_save.restore()             # <<<<<<<<<<<<<<
 *     stderr_save.restore()
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__restore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2041
 *     # needs to be before reading back the file contents
 *     stdout_save.restore()
 *     stderr_save.restore()             # <<<<<<<<<<<<<<
 * 
 *     # capture stderr/stdout.
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_stderr_save, __pyx_n_s__restore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2044
 * 
 *     # capture stderr/stdout.
 *     out_stderr = open( stderr_f, "r").readlines()             # <<<<<<<<<<<<<<
 *     out_stdout = open( stdout_f, "r").readlines()
 * 
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_stderr_f);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stderr_f);
  __Pyx_GIVEREF(__pyx_v_stderr_f);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__r));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
  __pyx_t_2 = PyObject_Call(__pyx_builtin_open, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__readlines); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_v_out_stderr);
  __pyx_v_out_stderr = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2045
 *     # capture stderr/stdout.
 *     out_stderr = open( stderr_f, "r").readlines()
 *     out_stdout = open( stdout_f, "r").readlines()             # <<<<<<<<<<<<<<
 * 
 *     # clean up files
 */
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_stdout_f);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_stdout_f);
  __Pyx_GIVEREF(__pyx_v_stdout_f);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__r));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
  __pyx_t_1 = PyObject_Call(__pyx_builtin_open, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__readlines); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_v_out_stdout);
  __pyx_v_out_stdout = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2048
 * 
 *     # clean up files
 *     os.remove( stderr_f )             # <<<<<<<<<<<<<<
 *     os.remove( stdout_f )
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__remove); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_stderr_f);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stderr_f);
  __Pyx_GIVEREF(__pyx_v_stderr_f);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2049
 *     # clean up files
 *     os.remove( stderr_f )
 *     os.remove( stdout_f )             # <<<<<<<<<<<<<<
 * 
 *     return retval, out_stderr, out_stdout
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__remove); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_stdout_f);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_f);
  __Pyx_GIVEREF(__pyx_v_stdout_f);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2051
 *     os.remove( stdout_f )
 * 
 *     return retval, out_stderr, out_stdout             # <<<<<<<<<<<<<<
 * 
 * __all__ = ["Samfile",
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_out_stderr);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_out_stderr);
  __Pyx_GIVEREF(__pyx_v_out_stderr);
  __Pyx_INCREF(__pyx_v_out_stdout);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_out_stdout);
  __Pyx_GIVEREF(__pyx_v_out_stdout);
  __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("chimerascan.pysam.csamtools._samtools_dispatch");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_stderr_h);
  __Pyx_DECREF(__pyx_v_stderr_f);
  __Pyx_DECREF(__pyx_v_stdout_h);
  __Pyx_DECREF(__pyx_v_stdout_f);
  __Pyx_DECREF(__pyx_v_stdout_save);
  __Pyx_DECREF(__pyx_v_stderr_save);
  __Pyx_DECREF(__pyx_v_out_stderr);
  __Pyx_DECREF(__pyx_v_out_stdout);
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_AlignedRead(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_AlignedRead(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qname(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qname___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qname(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qname___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_cigar(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5cigar___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_cigar(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5cigar___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_seq(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3seq___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_seq(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3seq___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qual(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qual___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qual(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qual___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_query(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5query___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qqual(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5qqual___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qstart(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_6qstart___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qend(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qend___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qlen(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4qlen___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_tags(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4tags___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_tags(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4tags___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_flag(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4flag___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_flag(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4flag___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_rname(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5rname___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_rname(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5rname___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_pos(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3pos___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_pos(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3pos___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_bin(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3bin___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_bin(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_3bin___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_rlen(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4rlen___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_aend(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4aend___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_alen(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4alen___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mapq(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mapq___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mapq(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mapq___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mrnm(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mrnm___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mrnm(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mrnm___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mpos(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mpos___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mpos(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_4mpos___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_isize(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5isize___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_isize(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_5isize___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_paired(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_paired___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_paired(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_paired___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_proper_pair(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_14is_proper_pair___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_proper_pair(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_14is_proper_pair___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_unmapped(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_11is_unmapped___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_unmapped(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_11is_unmapped___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_unmapped(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_unmapped(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_16mate_is_unmapped___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_reverse(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_10is_reverse___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_reverse(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_10is_reverse___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_reverse(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_reverse(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_15mate_is_reverse___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read1(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read1___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read1(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read1___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read2(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read2___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read2(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_8is_read2___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_secondary(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_secondary___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_secondary(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_secondary___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_qcfail(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_qcfail___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_qcfail(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_9is_qcfail___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_duplicate(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_duplicate___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_duplicate(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_12is_duplicate___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_AlignedRead[] = {
  {__Pyx_NAMESTR("compare"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_compare, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead_compare)},
  {__Pyx_NAMESTR("opt"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_opt, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead_opt)},
  {__Pyx_NAMESTR("fancy_str"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead_fancy_str, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead_fancy_str)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_11chimerascan_5pysam_9csamtools_AlignedRead[] = {
  {(char *)"qname", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qname, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qname, __Pyx_DOCSTR(__pyx_k_88), 0},
  {(char *)"cigar", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_cigar, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_cigar, __Pyx_DOCSTR(__pyx_k_89), 0},
  {(char *)"seq", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_seq, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_seq, __Pyx_DOCSTR(__pyx_k_90), 0},
  {(char *)"qual", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qual, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qual, __Pyx_DOCSTR(__pyx_k_91), 0},
  {(char *)"query", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_query, 0, __Pyx_DOCSTR(__pyx_k_92), 0},
  {(char *)"qqual", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qqual, 0, __Pyx_DOCSTR(__pyx_k_93), 0},
  {(char *)"qstart", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qstart, 0, __Pyx_DOCSTR(__pyx_k_94), 0},
  {(char *)"qend", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qend, 0, __Pyx_DOCSTR(__pyx_k_95), 0},
  {(char *)"qlen", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_qlen, 0, __Pyx_DOCSTR(__pyx_k_96), 0},
  {(char *)"tags", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_tags, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_tags, __Pyx_DOCSTR(__pyx_k_97), 0},
  {(char *)"flag", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_flag, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_flag, __Pyx_DOCSTR(__pyx_k_98), 0},
  {(char *)"rname", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_rname, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_rname, __Pyx_DOCSTR(__pyx_k_99), 0},
  {(char *)"pos", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_pos, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_pos, __Pyx_DOCSTR(__pyx_k_100), 0},
  {(char *)"bin", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_bin, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_bin, __Pyx_DOCSTR(__pyx_k_101), 0},
  {(char *)"rlen", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_rlen, 0, __Pyx_DOCSTR(__pyx_k_102), 0},
  {(char *)"aend", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_aend, 0, __Pyx_DOCSTR(__pyx_k_103), 0},
  {(char *)"alen", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_alen, 0, __Pyx_DOCSTR(__pyx_k_104), 0},
  {(char *)"mapq", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mapq, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mapq, __Pyx_DOCSTR(__pyx_k_105), 0},
  {(char *)"mrnm", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mrnm, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mrnm, __Pyx_DOCSTR(__pyx_k_106), 0},
  {(char *)"mpos", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mpos, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mpos, __Pyx_DOCSTR(__pyx_k_107), 0},
  {(char *)"isize", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_isize, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_isize, __Pyx_DOCSTR(__pyx_k_108), 0},
  {(char *)"is_paired", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_paired, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_paired, __Pyx_DOCSTR(__pyx_k_109), 0},
  {(char *)"is_proper_pair", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_proper_pair, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_proper_pair, __Pyx_DOCSTR(__pyx_k_110), 0},
  {(char *)"is_unmapped", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_unmapped, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_unmapped, __Pyx_DOCSTR(__pyx_k_111), 0},
  {(char *)"mate_is_unmapped", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_unmapped, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_unmapped, __Pyx_DOCSTR(__pyx_k_112), 0},
  {(char *)"is_reverse", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_reverse, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_reverse, __Pyx_DOCSTR(__pyx_k_113), 0},
  {(char *)"mate_is_reverse", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_reverse, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_mate_is_reverse, __Pyx_DOCSTR(__pyx_k_114), 0},
  {(char *)"is_read1", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read1, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read1, __Pyx_DOCSTR(__pyx_k_115), 0},
  {(char *)"is_read2", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read2, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_read2, __Pyx_DOCSTR(__pyx_k_116), 0},
  {(char *)"is_secondary", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_secondary, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_secondary, __Pyx_DOCSTR(__pyx_k_117), 0},
  {(char *)"is_qcfail", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_qcfail, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_qcfail, __Pyx_DOCSTR(__pyx_k_118), 0},
  {(char *)"is_duplicate", __pyx_getprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_duplicate, __pyx_setprop_11chimerascan_5pysam_9csamtools_11AlignedRead_is_duplicate, __Pyx_DOCSTR(__pyx_k_119), 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_AlignedRead = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_AlignedRead = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_AlignedRead = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_AlignedRead = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_AlignedRead = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.AlignedRead"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_AlignedRead, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_AlignedRead, /*tp_as_number*/
  &__pyx_tp_as_sequence_AlignedRead, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_AlignedRead, /*tp_as_mapping*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___hash__, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_11AlignedRead___str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_AlignedRead, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("\n    Class representing an aligned read. see SAM format specification for meaning of fields (http://samtools.sourceforge.net/).\n\n    This class stores a handle to the samtools C-structure representing\n    an aligned read. Member read access is forwarded to the C-structure\n    and converted into python objects. This implementation should be fast,\n    as only the data needed is converted.\n\n    For write access, the C-structure is updated in-place. This is\n    not the most efficient way to build BAM entries, as the variable\n    length data is concatenated and thus needs to resized if\n    a field is updated. Furthermore, the BAM entry might be\n    in an inconsistent state. The :meth:`~validate` method can\n    be used to check if an entry is consistent.\n\n    One issue to look out for is that the sequence should always\n    be set *before* the quality scores. Setting the sequence will\n    also erase any quality scores that were set previously.\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_AlignedRead, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_11chimerascan_5pysam_9csamtools_AlignedRead, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_AlignedRead, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_PileupProxy(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_PileupProxy(PyObject *o) {
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_tid(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_3tid___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_n(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_1n___get__(o);
}

static int __pyx_setprop_11chimerascan_5pysam_9csamtools_11PileupProxy_n(PyObject *o, PyObject *v, void *x) {
  if (v) {
    return __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_1n___set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_pos(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_3pos___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_pileups(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy_7pileups___get__(o);
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_PileupProxy[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_11chimerascan_5pysam_9csamtools_PileupProxy[] = {
  {(char *)"tid", __pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_tid, 0, __Pyx_DOCSTR(__pyx_k_120), 0},
  {(char *)"n", __pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_n, __pyx_setprop_11chimerascan_5pysam_9csamtools_11PileupProxy_n, __Pyx_DOCSTR(__pyx_k_121), 0},
  {(char *)"pos", __pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_pos, 0, 0, 0},
  {(char *)"pileups", __pyx_getprop_11chimerascan_5pysam_9csamtools_11PileupProxy_pileups, 0, __Pyx_DOCSTR(__pyx_k_122), 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_PileupProxy = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_PileupProxy = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_PileupProxy = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_PileupProxy = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_PileupProxy = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.PileupProxy"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupProxy), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_PileupProxy, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_PileupProxy, /*tp_as_number*/
  &__pyx_tp_as_sequence_PileupProxy, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_PileupProxy, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_11PileupProxy___str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_PileupProxy, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("A pileup column. A pileup column contains\n    all the reads that map to a certain target base.\n\n    tid\n        chromosome ID as is defined in the header\n    pos\n        the target base coordinate (0-based)\n    n\n        number of reads mapping to this column    \n    pileups\n        list of reads (:class:`pysam.PileupRead`) aligned to this column\n\n    This class is a proxy for results returned by the samtools pileup engine.\n    If the underlying engine iterator advances, the results of this column\n    will change.\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_PileupProxy, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_11chimerascan_5pysam_9csamtools_PileupProxy, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_PileupProxy, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)o);
  p->_alignment = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead___cinit__(o, __pyx_empty_tuple, NULL) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_PileupRead(PyObject *o) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)o;
  Py_XDECREF(((PyObject *)p->_alignment));
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_11chimerascan_5pysam_9csamtools_PileupRead(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)o;
  if (p->_alignment) {
    e = (*v)(((PyObject*)p->_alignment), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_11chimerascan_5pysam_9csamtools_PileupRead(PyObject *o) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->_alignment);
  p->_alignment = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_AlignedRead *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_alignment(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_9alignment___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_qpos(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_4qpos___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_indel(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_5indel___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_is_del(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_6is_del___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_is_head(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_7is_head___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_is_tail(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_7is_tail___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_level(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead_5level___get__(o);
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_PileupRead[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_11chimerascan_5pysam_9csamtools_PileupRead[] = {
  {(char *)"alignment", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_alignment, 0, __Pyx_DOCSTR(__pyx_k_123), 0},
  {(char *)"qpos", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_qpos, 0, __Pyx_DOCSTR(__pyx_k_124), 0},
  {(char *)"indel", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_indel, 0, __Pyx_DOCSTR(__pyx_k_125), 0},
  {(char *)"is_del", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_is_del, 0, __Pyx_DOCSTR(__pyx_k_126), 0},
  {(char *)"is_head", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_is_head, 0, 0, 0},
  {(char *)"is_tail", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_is_tail, 0, 0, 0},
  {(char *)"level", __pyx_getprop_11chimerascan_5pysam_9csamtools_10PileupRead_level, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_PileupRead = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_PileupRead = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_PileupRead = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_PileupRead = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_PileupRead = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.PileupRead"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_PileupRead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_PileupRead, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_PileupRead, /*tp_as_number*/
  &__pyx_tp_as_sequence_PileupRead, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_PileupRead, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_10PileupRead___str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_PileupRead, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("A read aligned to a column.\n    "), /*tp_doc*/
  __pyx_tp_traverse_11chimerascan_5pysam_9csamtools_PileupRead, /*tp_traverse*/
  __pyx_tp_clear_11chimerascan_5pysam_9csamtools_PileupRead, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_PileupRead, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_11chimerascan_5pysam_9csamtools_PileupRead, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_PileupRead, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_Samfile __pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile;

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_Samfile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)o);
  p->__pyx_vtab = __pyx_vtabptr_11chimerascan_5pysam_9csamtools_Samfile;
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_Samfile(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_nreferences(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_11nreferences___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_references(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_10references___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_lengths(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_7lengths___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_text(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_4text___get__(o);
}

static PyObject *__pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_header(PyObject *o, void *x) {
  return __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_6header___get__(o);
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_Samfile[] = {
  {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__isOpen)},
  {__Pyx_NAMESTR("_hasIndex"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__hasIndex, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__hasIndex)},
  {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__open, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__open)},
  {__Pyx_NAMESTR("getrname"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_getrname, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_getrname)},
  {__Pyx_NAMESTR("_parseRegion"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__parseRegion, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__parseRegion)},
  {__Pyx_NAMESTR("seek"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_seek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_seek)},
  {__Pyx_NAMESTR("tell"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_tell, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_tell)},
  {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_fetch)},
  {__Pyx_NAMESTR("pileup"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_pileup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_pileup)},
  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_close)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile_write, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile_write)},
  {__Pyx_NAMESTR("__enter__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___enter__, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___enter__)},
  {__Pyx_NAMESTR("__exit__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___exit__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___exit__)},
  {__Pyx_NAMESTR("_buildLine"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile__buildLine, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile__buildLine)},
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___next__)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_11chimerascan_5pysam_9csamtools_Samfile[] = {
  {(char *)"nreferences", __pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_127), 0},
  {(char *)"references", __pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_references, 0, __Pyx_DOCSTR(__pyx_k_128), 0},
  {(char *)"lengths", __pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_lengths, 0, __Pyx_DOCSTR(__pyx_k_129), 0},
  {(char *)"text", __pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_text, 0, __Pyx_DOCSTR(__pyx_k_130), 0},
  {(char *)"header", __pyx_getprop_11chimerascan_5pysam_9csamtools_7Samfile_header, 0, __Pyx_DOCSTR(__pyx_k_131), 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Samfile = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_Samfile = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_Samfile = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Samfile = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_Samfile = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.Samfile"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_Samfile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_Samfile, /*tp_as_number*/
  &__pyx_tp_as_sequence_Samfile, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Samfile, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Samfile, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("*(filename, mode='r', template = None, referencenames = None, referencelengths = None, text = NULL, header = None)*\n              \n    A *SAM* file. The file is automatically opened.\n    \n    *mode* should be ``r`` for reading or ``w`` for writing. The default is text mode so for binary \n    (:term:`BAM`) I/O you should append ``b`` for compressed or ``u`` for uncompressed :term:`BAM` output. \n    Use ``h`` to output header information  in text (:term:`TAM`)  mode.\n\n    If ``b`` is present, it must immediately follow ``r`` or ``w``. \n    Currently valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb`` and ``wbu``.\n    \n    so to open a :term:`BAM` file for reading::\n\n        f=Samfile('ex1.bam','rb')\n\n\n    For writing, the header of a :term:`TAM` file/:term:`BAM` file can be constituted from several\n    sources:\n\n        1. If *template* is given, the header is copied from a another *Samfile* (*template* must be of type *Samfile*).\n\n        2. If *header* is given, the header is build from a multi-level dictionary. The first level are the four types ('HD', 'SQ', ...). The second level is then a list of lines, with each line being a list of tag-value pairs.\n\n        3. If *text* is given, new header text is copied from raw text.\n\n        4. The names (*referencenames*) and lengths (*referencelengths*) are supplied directly as lists. \n\n    If an index for a BAM file exists (.bai), it will be opened automatically. Without an index random\n    access to reads via :meth:`fetch` and :meth:`pileup` is disabled.\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___iter__, /*tp_iter*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_7Samfile___next__, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_Samfile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_11chimerascan_5pysam_9csamtools_Samfile, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_Samfile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_Fastafile(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_Fastafile(PyObject *o) {
  (*Py_TYPE(o)->tp_free)(o);
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_Fastafile[] = {
  {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile__isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile__isOpen)},
  {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile__open, METH_O, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile__open)},
  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile_close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile_close)},
  {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile_fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_9Fastafile_fetch)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Fastafile = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_Fastafile = {
  __pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_Fastafile = {
  __pyx_pf_11chimerascan_5pysam_9csamtools_9Fastafile___len__, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Fastafile = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_Fastafile = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.Fastafile"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Fastafile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_Fastafile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_Fastafile, /*tp_as_number*/
  &__pyx_tp_as_sequence_Fastafile, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Fastafile, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Fastafile, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("*(filename)*\n              \n    A *FASTA* file. The file is automatically opened.\n\n    The file expects an indexed fasta file.\n\n    TODO: \n        add automatic indexing.\n        add function to get sequence names.\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_Fastafile, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_Fastafile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRow __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRow;

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)o);
  p->__pyx_vtab = __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRow;
  p->samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_IteratorRow(PyObject *o) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(((PyObject *)p->samfile));
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_11chimerascan_5pysam_9csamtools_IteratorRow(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)o;
  if (p->samfile) {
    e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_11chimerascan_5pysam_9csamtools_IteratorRow(PyObject *o) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_IteratorRow[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_11IteratorRow___next__)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_IteratorRow = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_IteratorRow = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_IteratorRow = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_IteratorRow = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_IteratorRow = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.IteratorRow"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_IteratorRow, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_IteratorRow, /*tp_as_number*/
  &__pyx_tp_as_sequence_IteratorRow, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_IteratorRow, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_IteratorRow, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("iterates over mapped reads in a region.\n\n    The samtools iterators assume that the file\n    position between iterations do not change.\n    As a consequence, no two iterators can work\n    on the same file. To permit this, each iterator\n    creates its own file handle by re-opening the\n    file.\n\n    Note that the index will be shared between \n    samfile and the iterator.\n    "), /*tp_doc*/
  __pyx_tp_traverse_11chimerascan_5pysam_9csamtools_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_11chimerascan_5pysam_9csamtools_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___iter__, /*tp_iter*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_11IteratorRow___next__, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_IteratorRow, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_IteratorRow, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorRowAll __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRowAll;

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *)o);
  p->__pyx_vtab = __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRowAll;
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_IteratorRowAll(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_IteratorRowAll[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_IteratorRowAll = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_IteratorRowAll = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_IteratorRowAll = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_IteratorRowAll = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_IteratorRowAll = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.IteratorRowAll"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_IteratorRowAll, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_IteratorRowAll, /*tp_as_number*/
  &__pyx_tp_as_sequence_IteratorRowAll, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_IteratorRowAll, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_IteratorRowAll, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("iterates over all mapped reads\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___iter__, /*tp_iter*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_IteratorRowAll, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_IteratorRowAll, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_11chimerascan_5pysam_9csamtools_IteratorColumn __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorColumn;

static PyObject *__pyx_tp_new_11chimerascan_5pysam_9csamtools_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)o);
  p->__pyx_vtab = __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorColumn;
  p->iter = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)Py_None); Py_INCREF(Py_None);
  if (__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___cinit__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_IteratorColumn(PyObject *o) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(((PyObject *)p->iter));
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_11chimerascan_5pysam_9csamtools_IteratorColumn(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)o;
  if (p->iter) {
    e = (*v)(((PyObject*)p->iter), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_11chimerascan_5pysam_9csamtools_IteratorColumn(PyObject *o) {
  struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *p = (struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->iter);
  p->iter = ((struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_11chimerascan_5pysam_9csamtools_IteratorColumn[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_IteratorColumn = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_IteratorColumn = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_IteratorColumn = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_IteratorColumn = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_11chimerascan_5pysam_9csamtools_IteratorColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("chimerascan.pysam.csamtools.IteratorColumn"), /*tp_name*/
  sizeof(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_11chimerascan_5pysam_9csamtools_IteratorColumn, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_IteratorColumn, /*tp_as_number*/
  &__pyx_tp_as_sequence_IteratorColumn, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_IteratorColumn, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_IteratorColumn, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("iterates over columns.\n\n    This iterator wraps the pileup functionality of samtools.\n    \n    For reasons of efficiency, the iterator returns the current \n    pileup buffer. As this buffer is updated at every iteration, \n    the contents of this iterator will change accordingly. Hence the conversion to\n    a list will not produce the expected result::\n    \n       f = Samfile(\"file.bam\", \"rb\")\n       result = list( f.pileup() )\n\n    Here, result will contain ``n`` objects of type :class:`PileupProxy` for ``n`` columns, \n    but each object will contain the same information.\n    \n    If the results of several columns are required at the same time, the results\n    need to be stored explicitely::\n\n       result = [ x.pileups() for x in f.pileup() ]\n\n    Here, result will be a list of ``n`` lists of objects of type :class:`PileupRead`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_11chimerascan_5pysam_9csamtools_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_11chimerascan_5pysam_9csamtools_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___iter__, /*tp_iter*/
  __pyx_pf_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__, /*tp_iternext*/
  __pyx_methods_11chimerascan_5pysam_9csamtools_IteratorColumn, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_11chimerascan_5pysam_9csamtools_IteratorColumn, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("_samtools_dispatch"), (PyCFunction)__pyx_pf_11chimerascan_5pysam_9csamtools__samtools_dispatch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11chimerascan_5pysam_9csamtools__samtools_dispatch)},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("csamtools"),
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_132, __pyx_k_132, sizeof(__pyx_k_132), 0, 0, 1, 0},
  {&__pyx_kp_s_133, __pyx_k_133, sizeof(__pyx_k_133), 0, 0, 1, 0},
  {&__pyx_kp_s_134, __pyx_k_134, sizeof(__pyx_k_134), 0, 0, 1, 0},
  {&__pyx_kp_u_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 1, 0, 0},
  {&__pyx_kp_u_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 1, 0, 0},
  {&__pyx_kp_u_137, __pyx_k_137, sizeof(__pyx_k_137), 0, 1, 0, 0},
  {&__pyx_kp_u_138, __pyx_k_138, sizeof(__pyx_k_138), 0, 1, 0, 0},
  {&__pyx_kp_u_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 1, 0, 0},
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
  {&__pyx_kp_u_140, __pyx_k_140, sizeof(__pyx_k_140), 0, 1, 0, 0},
  {&__pyx_kp_u_141, __pyx_k_141, sizeof(__pyx_k_141), 0, 1, 0, 0},
  {&__pyx_kp_u_142, __pyx_k_142, sizeof(__pyx_k_142), 0, 1, 0, 0},
  {&__pyx_kp_u_143, __pyx_k_143, sizeof(__pyx_k_143), 0, 1, 0, 0},
  {&__pyx_kp_u_144, __pyx_k_144, sizeof(__pyx_k_144), 0, 1, 0, 0},
  {&__pyx_kp_u_145, __pyx_k_145, sizeof(__pyx_k_145), 0, 1, 0, 0},
  {&__pyx_kp_u_146, __pyx_k_146, sizeof(__pyx_k_146), 0, 1, 0, 0},
  {&__pyx_kp_u_147, __pyx_k_147, sizeof(__pyx_k_147), 0, 1, 0, 0},
  {&__pyx_kp_u_148, __pyx_k_148, sizeof(__pyx_k_148), 0, 1, 0, 0},
  {&__pyx_kp_u_149, __pyx_k_149, sizeof(__pyx_k_149), 0, 1, 0, 0},
  {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
  {&__pyx_kp_u_150, __pyx_k_150, sizeof(__pyx_k_150), 0, 1, 0, 0},
  {&__pyx_kp_u_151, __pyx_k_151, sizeof(__pyx_k_151), 0, 1, 0, 0},
  {&__pyx_kp_u_152, __pyx_k_152, sizeof(__pyx_k_152), 0, 1, 0, 0},
  {&__pyx_kp_u_153, __pyx_k_153, sizeof(__pyx_k_153), 0, 1, 0, 0},
  {&__pyx_kp_u_154, __pyx_k_154, sizeof(__pyx_k_154), 0, 1, 0, 0},
  {&__pyx_kp_u_155, __pyx_k_155, sizeof(__pyx_k_155), 0, 1, 0, 0},
  {&__pyx_kp_u_156, __pyx_k_156, sizeof(__pyx_k_156), 0, 1, 0, 0},
  {&__pyx_kp_u_157, __pyx_k_157, sizeof(__pyx_k_157), 0, 1, 0, 0},
  {&__pyx_kp_u_158, __pyx_k_158, sizeof(__pyx_k_158), 0, 1, 0, 0},
  {&__pyx_kp_u_159, __pyx_k_159, sizeof(__pyx_k_159), 0, 1, 0, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_kp_u_160, __pyx_k_160, sizeof(__pyx_k_160), 0, 1, 0, 0},
  {&__pyx_kp_u_161, __pyx_k_161, sizeof(__pyx_k_161), 0, 1, 0, 0},
  {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
  {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
  {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
  {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
  {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0},
  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
  {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0},
  {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
  {&__pyx_kp_s_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0},
  {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
  {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
  {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0},
  {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
  {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
  {&__pyx_kp_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 0},
  {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0},
  {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
  {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0},
  {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0},
  {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
  {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0},
  {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
  {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0},
  {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0},
  {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
  {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0},
  {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
  {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0},
  {&__pyx_n_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 1},
  {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0},
  {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0},
  {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0},
  {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0},
  {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0},
  {&__pyx_kp_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 0},
  {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0},
  {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
  {&__pyx_kp_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 0},
  {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0},
  {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0},
  {&__pyx_kp_s_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 1, 0},
  {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0},
  {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0},
  {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0},
  {&__pyx_kp_s_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 0, 1, 0},
  {&__pyx_kp_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 0},
  {&__pyx_kp_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 0},
  {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
  {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0},
  {&__pyx_kp_s_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 0, 1, 0},
  {&__pyx_kp_s_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 1, 0},
  {&__pyx_kp_s_73, __pyx_k_73, sizeof(__pyx_k_73), 0, 0, 1, 0},
  {&__pyx_kp_s_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 1, 0},
  {&__pyx_kp_s_75, __pyx_k_75, sizeof(__pyx_k_75), 0, 0, 1, 0},
  {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0},
  {&__pyx_kp_s_77, __pyx_k_77, sizeof(__pyx_k_77), 0, 0, 1, 0},
  {&__pyx_kp_s_78, __pyx_k_78, sizeof(__pyx_k_78), 0, 0, 1, 0},
  {&__pyx_kp_s_79, __pyx_k_79, sizeof(__pyx_k_79), 0, 0, 1, 0},
  {&__pyx_kp_s_80, __pyx_k_80, sizeof(__pyx_k_80), 0, 0, 1, 0},
  {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0},
  {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0},
  {&__pyx_kp_s_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 0, 1, 0},
  {&__pyx_kp_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 0},
  {&__pyx_kp_s_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 0, 1, 0},
  {&__pyx_kp_s_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 0, 1, 0},
  {&__pyx_kp_s_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_n_s__A, __pyx_k__A, sizeof(__pyx_k__A), 0, 0, 1, 1},
  {&__pyx_n_s__AS, __pyx_k__AS, sizeof(__pyx_k__AS), 0, 0, 1, 1},
  {&__pyx_n_s__AlignedRead, __pyx_k__AlignedRead, sizeof(__pyx_k__AlignedRead), 0, 0, 1, 1},
  {&__pyx_n_s__C, __pyx_k__C, sizeof(__pyx_k__C), 0, 0, 1, 1},
  {&__pyx_n_s__CL, __pyx_k__CL, sizeof(__pyx_k__CL), 0, 0, 1, 1},
  {&__pyx_n_s__CN, __pyx_k__CN, sizeof(__pyx_k__CN), 0, 0, 1, 1},
  {&__pyx_n_s__CO, __pyx_k__CO, sizeof(__pyx_k__CO), 0, 0, 1, 1},
  {&__pyx_n_s__DS, __pyx_k__DS, sizeof(__pyx_k__DS), 0, 0, 1, 1},
  {&__pyx_n_s__DT, __pyx_k__DT, sizeof(__pyx_k__DT), 0, 0, 1, 1},
  {&__pyx_n_s__DictType, __pyx_k__DictType, sizeof(__pyx_k__DictType), 0, 0, 1, 1},
  {&__pyx_n_s__Fastafile, __pyx_k__Fastafile, sizeof(__pyx_k__Fastafile), 0, 0, 1, 1},
  {&__pyx_n_s__FloatType, __pyx_k__FloatType, sizeof(__pyx_k__FloatType), 0, 0, 1, 1},
  {&__pyx_n_s__GO, __pyx_k__GO, sizeof(__pyx_k__GO), 0, 0, 1, 1},
  {&__pyx_n_s__HD, __pyx_k__HD, sizeof(__pyx_k__HD), 0, 0, 1, 1},
  {&__pyx_n_s__I, __pyx_k__I, sizeof(__pyx_k__I), 0, 0, 1, 1},
  {&__pyx_n_s__ID, __pyx_k__ID, sizeof(__pyx_k__ID), 0, 0, 1, 1},
  {&__pyx_n_s__IOError, __pyx_k__IOError, sizeof(__pyx_k__IOError), 0, 0, 1, 1},
  {&__pyx_n_s__IntType, __pyx_k__IntType, sizeof(__pyx_k__IntType), 0, 0, 1, 1},
  {&__pyx_n_s__IteratorColumn, __pyx_k__IteratorColumn, sizeof(__pyx_k__IteratorColumn), 0, 0, 1, 1},
  {&__pyx_n_s__IteratorRow, __pyx_k__IteratorRow, sizeof(__pyx_k__IteratorRow), 0, 0, 1, 1},
  {&__pyx_n_s__IteratorRowAll, __pyx_k__IteratorRowAll, sizeof(__pyx_k__IteratorRowAll), 0, 0, 1, 1},
  {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
  {&__pyx_n_s__LB, __pyx_k__LB, sizeof(__pyx_k__LB), 0, 0, 1, 1},
  {&__pyx_n_s__LN, __pyx_k__LN, sizeof(__pyx_k__LN), 0, 0, 1, 1},
  {&__pyx_n_s__M5, __pyx_k__M5, sizeof(__pyx_k__M5), 0, 0, 1, 1},
  {&__pyx_n_s__NotImplementedError, __pyx_k__NotImplementedError, sizeof(__pyx_k__NotImplementedError), 0, 0, 1, 1},
  {&__pyx_n_s__O_CREAT, __pyx_k__O_CREAT, sizeof(__pyx_k__O_CREAT), 0, 0, 1, 1},
  {&__pyx_n_s__O_WRONLY, __pyx_k__O_WRONLY, sizeof(__pyx_k__O_WRONLY), 0, 0, 1, 1},
  {&__pyx_n_s__Outs, __pyx_k__Outs, sizeof(__pyx_k__Outs), 0, 0, 1, 1},
  {&__pyx_n_s__PG, __pyx_k__PG, sizeof(__pyx_k__PG), 0, 0, 1, 1},
  {&__pyx_n_s__PI, __pyx_k__PI, sizeof(__pyx_k__PI), 0, 0, 1, 1},
  {&__pyx_n_s__PL, __pyx_k__PL, sizeof(__pyx_k__PL), 0, 0, 1, 1},
  {&__pyx_n_s__PU, __pyx_k__PU, sizeof(__pyx_k__PU), 0, 0, 1, 1},
  {&__pyx_n_s__PileupColumn, __pyx_k__PileupColumn, sizeof(__pyx_k__PileupColumn), 0, 0, 1, 1},
  {&__pyx_n_s__PileupProxy, __pyx_k__PileupProxy, sizeof(__pyx_k__PileupProxy), 0, 0, 1, 1},
  {&__pyx_n_s__PileupRead, __pyx_k__PileupRead, sizeof(__pyx_k__PileupRead), 0, 0, 1, 1},
  {&__pyx_n_s__RG, __pyx_k__RG, sizeof(__pyx_k__RG), 0, 0, 1, 1},
  {&__pyx_n_s__S, __pyx_k__S, sizeof(__pyx_k__S), 0, 0, 1, 1},
  {&__pyx_n_s__SM, __pyx_k__SM, sizeof(__pyx_k__SM), 0, 0, 1, 1},
  {&__pyx_n_s__SN, __pyx_k__SN, sizeof(__pyx_k__SN), 0, 0, 1, 1},
  {&__pyx_n_s__SO, __pyx_k__SO, sizeof(__pyx_k__SO), 0, 0, 1, 1},
  {&__pyx_n_s__SP, __pyx_k__SP, sizeof(__pyx_k__SP), 0, 0, 1, 1},
  {&__pyx_n_s__SQ, __pyx_k__SQ, sizeof(__pyx_k__SQ), 0, 0, 1, 1},
  {&__pyx_n_s__Samfile, __pyx_k__Samfile, sizeof(__pyx_k__Samfile), 0, 0, 1, 1},
  {&__pyx_n_s__StderrStore, __pyx_k__StderrStore, sizeof(__pyx_k__StderrStore), 0, 0, 1, 1},
  {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1},
  {&__pyx_n_s__UR, __pyx_k__UR, sizeof(__pyx_k__UR), 0, 0, 1, 1},
  {&__pyx_n_s__VALID_HEADERS, __pyx_k__VALID_HEADERS, sizeof(__pyx_k__VALID_HEADERS), 0, 0, 1, 1},
  {&__pyx_n_s__VALID_HEADER_FIELDS, __pyx_k__VALID_HEADER_FIELDS, sizeof(__pyx_k__VALID_HEADER_FIELDS), 0, 0, 1, 1},
  {&__pyx_n_s__VALID_HEADER_ORDER, __pyx_k__VALID_HEADER_ORDER, sizeof(__pyx_k__VALID_HEADER_ORDER), 0, 0, 1, 1},
  {&__pyx_n_s__VALID_HEADER_TYPES, __pyx_k__VALID_HEADER_TYPES, sizeof(__pyx_k__VALID_HEADER_TYPES), 0, 0, 1, 1},
  {&__pyx_n_s__VN, __pyx_k__VN, sizeof(__pyx_k__VN), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s__Z, __pyx_k__Z, sizeof(__pyx_k__Z), 0, 0, 1, 1},
  {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
  {&__pyx_n_s____del__, __pyx_k____del__, sizeof(__pyx_k____del__), 0, 0, 1, 1},
  {&__pyx_n_s____dict__, __pyx_k____dict__, sizeof(__pyx_k____dict__), 0, 0, 1, 1},
  {&__pyx_n_s____getattribute__, __pyx_k____getattribute__, sizeof(__pyx_k____getattribute__), 0, 0, 1, 1},
  {&__pyx_n_s____init__, __pyx_k____init__, sizeof(__pyx_k____init__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____next__, __pyx_k____next__, sizeof(__pyx_k____next__), 0, 0, 1, 1},
  {&__pyx_n_s____str__, __pyx_k____str__, sizeof(__pyx_k____str__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s___alignment, __pyx_k___alignment, sizeof(__pyx_k___alignment), 0, 0, 1, 1},
  {&__pyx_n_s___buildHeader, __pyx_k___buildHeader, sizeof(__pyx_k___buildHeader), 0, 0, 1, 1},
  {&__pyx_n_s___buildLine, __pyx_k___buildLine, sizeof(__pyx_k___buildLine), 0, 0, 1, 1},
  {&__pyx_n_s___delegate, __pyx_k___delegate, sizeof(__pyx_k___delegate), 0, 0, 1, 1},
  {&__pyx_n_s___hasIndex, __pyx_k___hasIndex, sizeof(__pyx_k___hasIndex), 0, 0, 1, 1},
  {&__pyx_n_s___indel, __pyx_k___indel, sizeof(__pyx_k___indel), 0, 0, 1, 1},
  {&__pyx_n_s___isOpen, __pyx_k___isOpen, sizeof(__pyx_k___isOpen), 0, 0, 1, 1},
  {&__pyx_n_s___is_del, __pyx_k___is_del, sizeof(__pyx_k___is_del), 0, 0, 1, 1},
  {&__pyx_n_s___is_head, __pyx_k___is_head, sizeof(__pyx_k___is_head), 0, 0, 1, 1},
  {&__pyx_n_s___is_tail, __pyx_k___is_tail, sizeof(__pyx_k___is_tail), 0, 0, 1, 1},
  {&__pyx_n_s___level, __pyx_k___level, sizeof(__pyx_k___level), 0, 0, 1, 1},
  {&__pyx_n_s___open, __pyx_k___open, sizeof(__pyx_k___open), 0, 0, 1, 1},
  {&__pyx_n_s___parseRegion, __pyx_k___parseRegion, sizeof(__pyx_k___parseRegion), 0, 0, 1, 1},
  {&__pyx_n_s___qpos, __pyx_k___qpos, sizeof(__pyx_k___qpos), 0, 0, 1, 1},
  {&__pyx_n_s___samtools_dispatch, __pyx_k___samtools_dispatch, sizeof(__pyx_k___samtools_dispatch), 0, 0, 1, 1},
  {&__pyx_n_s__alignment, __pyx_k__alignment, sizeof(__pyx_k__alignment), 0, 0, 1, 1},
  {&__pyx_n_s__args, __pyx_k__args, sizeof(__pyx_k__args), 0, 0, 1, 1},
  {&__pyx_n_s__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1},
  {&__pyx_n_s__bam, __pyx_k__bam, sizeof(__pyx_k__bam), 0, 0, 1, 1},
  {&__pyx_n_s__beg, __pyx_k__beg, sizeof(__pyx_k__beg), 0, 0, 1, 1},
  {&__pyx_n_s__bin, __pyx_k__bin, sizeof(__pyx_k__bin), 0, 0, 1, 1},
  {&__pyx_n_s__bqual, __pyx_k__bqual, sizeof(__pyx_k__bqual), 0, 0, 1, 1},
  {&__pyx_n_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 1},
  {&__pyx_n_s__calcsize, __pyx_k__calcsize, sizeof(__pyx_k__calcsize), 0, 0, 1, 1},
  {&__pyx_n_s__callback, __pyx_k__callback, sizeof(__pyx_k__callback), 0, 0, 1, 1},
  {&__pyx_n_s__chain, __pyx_k__chain, sizeof(__pyx_k__chain), 0, 0, 1, 1},
  {&__pyx_n_s__chr, __pyx_k__chr, sizeof(__pyx_k__chr), 0, 0, 1, 1},
  {&__pyx_n_s__cigar, __pyx_k__cigar, sizeof(__pyx_k__cigar), 0, 0, 1, 1},
  {&__pyx_n_s__close, __pyx_k__close, sizeof(__pyx_k__close), 0, 0, 1, 1},
  {&__pyx_n_s__cmp, __pyx_k__cmp, sizeof(__pyx_k__cmp), 0, 0, 1, 1},
  {&__pyx_n_s__cnext, __pyx_k__cnext, sizeof(__pyx_k__cnext), 0, 0, 1, 1},
  {&__pyx_n_s__compare, __pyx_k__compare, sizeof(__pyx_k__compare), 0, 0, 1, 1},
  {&__pyx_n_s__core, __pyx_k__core, sizeof(__pyx_k__core), 0, 0, 1, 1},
  {&__pyx_n_s__ctypes, __pyx_k__ctypes, sizeof(__pyx_k__ctypes), 0, 0, 1, 1},
  {&__pyx_n_s__d, __pyx_k__d, sizeof(__pyx_k__d), 0, 0, 1, 1},
  {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1},
  {&__pyx_n_s__data_len, __pyx_k__data_len, sizeof(__pyx_k__data_len), 0, 0, 1, 1},
  {&__pyx_n_s__dup, __pyx_k__dup, sizeof(__pyx_k__dup), 0, 0, 1, 1},
  {&__pyx_n_s__dup2, __pyx_k__dup2, sizeof(__pyx_k__dup2), 0, 0, 1, 1},
  {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
  {&__pyx_n_s__exc_type, __pyx_k__exc_type, sizeof(__pyx_k__exc_type), 0, 0, 1, 1},
  {&__pyx_n_s__exc_value, __pyx_k__exc_value, sizeof(__pyx_k__exc_value), 0, 0, 1, 1},
  {&__pyx_n_s__exists, __pyx_k__exists, sizeof(__pyx_k__exists), 0, 0, 1, 1},
  {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1},
  {&__pyx_n_s__fancy_str, __pyx_k__fancy_str, sizeof(__pyx_k__fancy_str), 0, 0, 1, 1},
  {&__pyx_n_s__fastafile, __pyx_k__fastafile, sizeof(__pyx_k__fastafile), 0, 0, 1, 1},
  {&__pyx_n_s__fd, __pyx_k__fd, sizeof(__pyx_k__fd), 0, 0, 1, 1},
  {&__pyx_n_s__fetch, __pyx_k__fetch, sizeof(__pyx_k__fetch), 0, 0, 1, 1},
  {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1},
  {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1},
  {&__pyx_n_s__fileno, __pyx_k__fileno, sizeof(__pyx_k__fileno), 0, 0, 1, 1},
  {&__pyx_n_s__flag, __pyx_k__flag, sizeof(__pyx_k__flag), 0, 0, 1, 1},
  {&__pyx_n_s__flush, __pyx_k__flush, sizeof(__pyx_k__flush), 0, 0, 1, 1},
  {&__pyx_n_s__fp, __pyx_k__fp, sizeof(__pyx_k__fp), 0, 0, 1, 1},
  {&__pyx_n_s__getrname, __pyx_k__getrname, sizeof(__pyx_k__getrname), 0, 0, 1, 1},
  {&__pyx_n_s__hash, __pyx_k__hash, sizeof(__pyx_k__hash), 0, 0, 1, 1},
  {&__pyx_n_s__header, __pyx_k__header, sizeof(__pyx_k__header), 0, 0, 1, 1},
  {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1},
  {&__pyx_n_s__id, __pyx_k__id, sizeof(__pyx_k__id), 0, 0, 1, 1},
  {&__pyx_n_s__indel, __pyx_k__indel, sizeof(__pyx_k__indel), 0, 0, 1, 1},
  {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1},
  {&__pyx_n_s__is_del, __pyx_k__is_del, sizeof(__pyx_k__is_del), 0, 0, 1, 1},
  {&__pyx_n_s__is_head, __pyx_k__is_head, sizeof(__pyx_k__is_head), 0, 0, 1, 1},
  {&__pyx_n_s__is_tail, __pyx_k__is_tail, sizeof(__pyx_k__is_tail), 0, 0, 1, 1},
  {&__pyx_n_s__isbam, __pyx_k__isbam, sizeof(__pyx_k__isbam), 0, 0, 1, 1},
  {&__pyx_n_s__isize, __pyx_k__isize, sizeof(__pyx_k__isize), 0, 0, 1, 1},
  {&__pyx_n_s__isremote, __pyx_k__isremote, sizeof(__pyx_k__isremote), 0, 0, 1, 1},
  {&__pyx_n_s__iter, __pyx_k__iter, sizeof(__pyx_k__iter), 0, 0, 1, 1},
  {&__pyx_n_s__iterdata, __pyx_k__iterdata, sizeof(__pyx_k__iterdata), 0, 0, 1, 1},
  {&__pyx_n_s__itertools, __pyx_k__itertools, sizeof(__pyx_k__itertools), 0, 0, 1, 1},
  {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1},
  {&__pyx_n_s__l_aux, __pyx_k__l_aux, sizeof(__pyx_k__l_aux), 0, 0, 1, 1},
  {&__pyx_n_s__l_qname, __pyx_k__l_qname, sizeof(__pyx_k__l_qname), 0, 0, 1, 1},
  {&__pyx_n_s__l_qseq, __pyx_k__l_qseq, sizeof(__pyx_k__l_qseq), 0, 0, 1, 1},
  {&__pyx_n_s__l_text, __pyx_k__l_text, sizeof(__pyx_k__l_text), 0, 0, 1, 1},
  {&__pyx_n_s__level, __pyx_k__level, sizeof(__pyx_k__level), 0, 0, 1, 1},
  {&__pyx_n_s__m_data, __pyx_k__m_data, sizeof(__pyx_k__m_data), 0, 0, 1, 1},
  {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1},
  {&__pyx_n_s__mapq, __pyx_k__mapq, sizeof(__pyx_k__mapq), 0, 0, 1, 1},
  {&__pyx_n_s__method, __pyx_k__method, sizeof(__pyx_k__method), 0, 0, 1, 1},
  {&__pyx_n_s__mkstemp, __pyx_k__mkstemp, sizeof(__pyx_k__mkstemp), 0, 0, 1, 1},
  {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
  {&__pyx_n_s__mpos, __pyx_k__mpos, sizeof(__pyx_k__mpos), 0, 0, 1, 1},
  {&__pyx_n_s__mtid, __pyx_k__mtid, sizeof(__pyx_k__mtid), 0, 0, 1, 1},
  {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
  {&__pyx_n_s__n_cigar, __pyx_k__n_cigar, sizeof(__pyx_k__n_cigar), 0, 0, 1, 1},
  {&__pyx_n_s__n_plp, __pyx_k__n_plp, sizeof(__pyx_k__n_plp), 0, 0, 1, 1},
  {&__pyx_n_s__n_pu, __pyx_k__n_pu, sizeof(__pyx_k__n_pu), 0, 0, 1, 1},
  {&__pyx_n_s__n_targets, __pyx_k__n_targets, sizeof(__pyx_k__n_targets), 0, 0, 1, 1},
  {&__pyx_n_s__nreferences, __pyx_k__nreferences, sizeof(__pyx_k__nreferences), 0, 0, 1, 1},
  {&__pyx_n_s__object, __pyx_k__object, sizeof(__pyx_k__object), 0, 0, 1, 1},
  {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1},
  {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1},
  {&__pyx_n_s__opt, __pyx_k__opt, sizeof(__pyx_k__opt), 0, 0, 1, 1},
  {&__pyx_n_s__os, __pyx_k__os, sizeof(__pyx_k__os), 0, 0, 1, 1},
  {&__pyx_n_s__pack_into, __pyx_k__pack_into, sizeof(__pyx_k__pack_into), 0, 0, 1, 1},
  {&__pyx_n_s__path, __pyx_k__path, sizeof(__pyx_k__path), 0, 0, 1, 1},
  {&__pyx_n_s__pileup, __pyx_k__pileup, sizeof(__pyx_k__pileup), 0, 0, 1, 1},
  {&__pyx_n_s__pileup_iter, __pyx_k__pileup_iter, sizeof(__pyx_k__pileup_iter), 0, 0, 1, 1},
  {&__pyx_n_s__pileups, __pyx_k__pileups, sizeof(__pyx_k__pileups), 0, 0, 1, 1},
  {&__pyx_n_s__plp, __pyx_k__plp, sizeof(__pyx_k__plp), 0, 0, 1, 1},
  {&__pyx_n_s__port, __pyx_k__port, sizeof(__pyx_k__port), 0, 0, 1, 1},
  {&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1},
  {&__pyx_n_s__qname, __pyx_k__qname, sizeof(__pyx_k__qname), 0, 0, 1, 1},
  {&__pyx_n_s__qpos, __pyx_k__qpos, sizeof(__pyx_k__qpos), 0, 0, 1, 1},
  {&__pyx_n_s__qseq, __pyx_k__qseq, sizeof(__pyx_k__qseq), 0, 0, 1, 1},
  {&__pyx_n_s__qual, __pyx_k__qual, sizeof(__pyx_k__qual), 0, 0, 1, 1},
  {&__pyx_n_s__r, __pyx_k__r, sizeof(__pyx_k__r), 0, 0, 1, 1},
  {&__pyx_n_s__raw, __pyx_k__raw, sizeof(__pyx_k__raw), 0, 0, 1, 1},
  {&__pyx_n_s__rb, __pyx_k__rb, sizeof(__pyx_k__rb), 0, 0, 1, 1},
  {&__pyx_n_s__readAndRelease, __pyx_k__readAndRelease, sizeof(__pyx_k__readAndRelease), 0, 0, 1, 1},
  {&__pyx_n_s__readlines, __pyx_k__readlines, sizeof(__pyx_k__readlines), 0, 0, 1, 1},
  {&__pyx_n_s__record, __pyx_k__record, sizeof(__pyx_k__record), 0, 0, 1, 1},
  {&__pyx_n_s__reference, __pyx_k__reference, sizeof(__pyx_k__reference), 0, 0, 1, 1},
  {&__pyx_n_s__referencelengths, __pyx_k__referencelengths, sizeof(__pyx_k__referencelengths), 0, 0, 1, 1},
  {&__pyx_n_s__referencenames, __pyx_k__referencenames, sizeof(__pyx_k__referencenames), 0, 0, 1, 1},
  {&__pyx_n_s__region, __pyx_k__region, sizeof(__pyx_k__region), 0, 0, 1, 1},
  {&__pyx_n_s__release, __pyx_k__release, sizeof(__pyx_k__release), 0, 0, 1, 1},
  {&__pyx_n_s__remove, __pyx_k__remove, sizeof(__pyx_k__remove), 0, 0, 1, 1},
  {&__pyx_n_s__restore, __pyx_k__restore, sizeof(__pyx_k__restore), 0, 0, 1, 1},
  {&__pyx_n_s__retval, __pyx_k__retval, sizeof(__pyx_k__retval), 0, 0, 1, 1},
  {&__pyx_n_s__rg2lib, __pyx_k__rg2lib, sizeof(__pyx_k__rg2lib), 0, 0, 1, 1},
  {&__pyx_n_s__rname, __pyx_k__rname, sizeof(__pyx_k__rname), 0, 0, 1, 1},
  {&__pyx_n_s__s, __pyx_k__s, sizeof(__pyx_k__s), 0, 0, 1, 1},
  {&__pyx_n_s__samfile, __pyx_k__samfile, sizeof(__pyx_k__samfile), 0, 0, 1, 1},
  {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1},
  {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1},
  {&__pyx_n_s__seq, __pyx_k__seq, sizeof(__pyx_k__seq), 0, 0, 1, 1},
  {&__pyx_n_s__setdevice, __pyx_k__setdevice, sizeof(__pyx_k__setdevice), 0, 0, 1, 1},
  {&__pyx_n_s__setfd, __pyx_k__setfd, sizeof(__pyx_k__setfd), 0, 0, 1, 1},
  {&__pyx_n_s__setfile, __pyx_k__setfile, sizeof(__pyx_k__setfile), 0, 0, 1, 1},
  {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1},
  {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1},
  {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1},
  {&__pyx_n_s__stderr, __pyx_k__stderr, sizeof(__pyx_k__stderr), 0, 0, 1, 1},
  {&__pyx_n_s__stderr_f, __pyx_k__stderr_f, sizeof(__pyx_k__stderr_f), 0, 0, 1, 1},
  {&__pyx_n_s__stderr_h, __pyx_k__stderr_h, sizeof(__pyx_k__stderr_h), 0, 0, 1, 1},
  {&__pyx_n_s__stderr_save, __pyx_k__stderr_save, sizeof(__pyx_k__stderr_save), 0, 0, 1, 1},
  {&__pyx_n_s__stdout, __pyx_k__stdout, sizeof(__pyx_k__stdout), 0, 0, 1, 1},
  {&__pyx_n_s__streams, __pyx_k__streams, sizeof(__pyx_k__streams), 0, 0, 1, 1},
  {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1},
  {&__pyx_n_s__struct, __pyx_k__struct, sizeof(__pyx_k__struct), 0, 0, 1, 1},
  {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
  {&__pyx_n_s__tags, __pyx_k__tags, sizeof(__pyx_k__tags), 0, 0, 1, 1},
  {&__pyx_n_s__target_len, __pyx_k__target_len, sizeof(__pyx_k__target_len), 0, 0, 1, 1},
  {&__pyx_n_s__target_name, __pyx_k__target_name, sizeof(__pyx_k__target_name), 0, 0, 1, 1},
  {&__pyx_n_s__tell, __pyx_k__tell, sizeof(__pyx_k__tell), 0, 0, 1, 1},
  {&__pyx_n_s__tempfile, __pyx_k__tempfile, sizeof(__pyx_k__tempfile), 0, 0, 1, 1},
  {&__pyx_n_s__template, __pyx_k__template, sizeof(__pyx_k__template), 0, 0, 1, 1},
  {&__pyx_n_s__text, __pyx_k__text, sizeof(__pyx_k__text), 0, 0, 1, 1},
  {&__pyx_n_s__tid, __pyx_k__tid, sizeof(__pyx_k__tid), 0, 0, 1, 1},
  {&__pyx_n_s__traceback, __pyx_k__traceback, sizeof(__pyx_k__traceback), 0, 0, 1, 1},
  {&__pyx_n_s__types, __pyx_k__types, sizeof(__pyx_k__types), 0, 0, 1, 1},
  {&__pyx_n_s__until_eof, __pyx_k__until_eof, sizeof(__pyx_k__until_eof), 0, 0, 1, 1},
  {&__pyx_n_s__view, __pyx_k__view, sizeof(__pyx_k__view), 0, 0, 1, 1},
  {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1},
  {&__pyx_n_s__wb, __pyx_k__wb, sizeof(__pyx_k__wb), 0, 0, 1, 1},
  {&__pyx_n_s__wbu, __pyx_k__wbu, sizeof(__pyx_k__wbu), 0, 0, 1, 1},
  {&__pyx_n_s__wh, __pyx_k__wh, sizeof(__pyx_k__wh), 0, 0, 1, 1},
  {&__pyx_n_s__where, __pyx_k__where, sizeof(__pyx_k__where), 0, 0, 1, 1},
  {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1},
  {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_object = __Pyx_GetName(__pyx_b, __pyx_n_s__object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_cmp = __Pyx_GetName(__pyx_b, __pyx_n_s__cmp); if (!__pyx_builtin_cmp) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_chr = __Pyx_GetName(__pyx_b, __pyx_n_s__chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_16 = PyInt_FromLong(16); if (unlikely(!__pyx_int_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_32 = PyInt_FromLong(32); if (unlikely(!__pyx_int_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_64 = PyInt_FromLong(64); if (unlikely(!__pyx_int_64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_255 = PyInt_FromLong(255); if (unlikely(!__pyx_int_255)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_256 = PyInt_FromLong(256); if (unlikely(!__pyx_int_256)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_512 = PyInt_FromLong(512); if (unlikely(!__pyx_int_512)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_neg_127 = PyInt_FromLong(-127); if (unlikely(!__pyx_int_neg_127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0660 = PyInt_FromLong(0660); if (unlikely(!__pyx_int_0660)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1024 = PyInt_FromLong(1024); if (unlikely(!__pyx_int_1024)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_65535 = PyInt_FromLong(65535); if (unlikely(!__pyx_int_65535)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_neg_32767 = PyInt_FromLong(-32767); if (unlikely(!__pyx_int_neg_32767)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4294967295 = PyInt_FromString((char *)"4294967295", 0, 0); if (unlikely(!__pyx_int_4294967295)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_neg_2147483648 = PyInt_FromLong(-2147483648); if (unlikely(!__pyx_int_neg_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initcsamtools(void); /*proto*/
PyMODINIT_FUNC initcsamtools(void)
#else
PyMODINIT_FUNC PyInit_csamtools(void); /*proto*/
PyMODINIT_FUNC PyInit_csamtools(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_csamtools(void)", __LINE__, __FILE__);
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __pyx_binding_PyCFunctionType_USED
  if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("csamtools"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_chimerascan__pysam__csamtools) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_AlignedRead, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11AlignedRead___str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11AlignedRead___str__.doc = __pyx_doc_11chimerascan_5pysam_9csamtools_11AlignedRead___str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11AlignedRead___str__;
    }
  }
  if (__Pyx_SetAttrString(__pyx_m, "AlignedRead", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_AlignedRead = &__pyx_type_11chimerascan_5pysam_9csamtools_AlignedRead;
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "PileupProxy", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_PileupProxy = &__pyx_type_11chimerascan_5pysam_9csamtools_PileupProxy;
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1905; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1905; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_PileupRead = &__pyx_type_11chimerascan_5pysam_9csamtools_PileupRead;
  __pyx_vtabptr_11chimerascan_5pysam_9csamtools_Samfile = &__pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile._buildHeader = (bam_header_t *(*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *, PyObject *))__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile__buildHeader;
  __pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile.getCurrent = (bam1_t *(*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *))__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile_getCurrent;
  __pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile.cnext = (int (*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_Samfile *))__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile_cnext;
  #else
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile._buildHeader = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile__buildHeader;
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile.getCurrent = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile_getCurrent;
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_Samfile.cnext = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_7Samfile_cnext;
  #endif
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_Samfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_7Samfile___next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_7Samfile___next__.doc = __pyx_doc_11chimerascan_5pysam_9csamtools_7Samfile___next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_11chimerascan_5pysam_9csamtools_7Samfile___next__;
    }
  }
  if (__Pyx_SetVtable(__pyx_type_11chimerascan_5pysam_9csamtools_Samfile.tp_dict, __pyx_vtabptr_11chimerascan_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "Samfile", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_Samfile = &__pyx_type_11chimerascan_5pysam_9csamtools_Samfile;
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_Fastafile = &__pyx_type_11chimerascan_5pysam_9csamtools_Fastafile;
  __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRow = &__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRow;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRow.getCurrent = (bam1_t *(*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *))__pyx_f_11chimerascan_5pysam_9csamtools_11IteratorRow_getCurrent;
  __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRow.cnext = (int (*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRow *))__pyx_f_11chimerascan_5pysam_9csamtools_11IteratorRow_cnext;
  #else
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRow.getCurrent = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_11IteratorRow_getCurrent;
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRow.cnext = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_11IteratorRow_cnext;
  #endif
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRow, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11IteratorRow___next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11IteratorRow___next__.doc = __pyx_doc_11chimerascan_5pysam_9csamtools_11IteratorRow___next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_11chimerascan_5pysam_9csamtools_11IteratorRow___next__;
    }
  }
  if (__Pyx_SetVtable(__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRow.tp_dict, __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRow = &__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRow;
  __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRowAll = &__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRowAll;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *))__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorRowAll_getCurrent;
  __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorRowAll *))__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorRowAll_cnext;
  #else
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRowAll.getCurrent = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorRowAll_getCurrent;
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorRowAll.cnext = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorRowAll_cnext;
  #endif
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__.doc = __pyx_doc_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorRowAll___next__;
    }
  }
  if (__Pyx_SetVtable(__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRowAll.tp_dict, __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorRowAll = &__pyx_type_11chimerascan_5pysam_9csamtools_IteratorRowAll;
  __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorColumn = &__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorColumn;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorColumn.cnext = (int (*)(struct __pyx_obj_11chimerascan_5pysam_9csamtools_IteratorColumn *))__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorColumn_cnext;
  #else
  *(void(**)(void))&__pyx_vtable_11chimerascan_5pysam_9csamtools_IteratorColumn.cnext = (void(*)(void))__pyx_f_11chimerascan_5pysam_9csamtools_14IteratorColumn_cnext;
  #endif
  if (PyType_Ready(&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorColumn, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__.doc = __pyx_doc_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_11chimerascan_5pysam_9csamtools_14IteratorColumn___next__;
    }
  }
  if (__Pyx_SetVtable(__pyx_type_11chimerascan_5pysam_9csamtools_IteratorColumn.tp_dict, __pyx_vtabptr_11chimerascan_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_11chimerascan_5pysam_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_11chimerascan_5pysam_9csamtools_IteratorColumn = &__pyx_type_11chimerascan_5pysam_9csamtools_IteratorColumn;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":5
 * # adds doc-strings for sphinx
 * 
 * import tempfile, os, sys, types, itertools, struct, ctypes             # <<<<<<<<<<<<<<
 * 
 * from python_string cimport PyString_FromStringAndSize, PyString_AS_STRING
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__tempfile), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tempfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__os), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__os, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__types), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__types, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__itertools), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__itertools, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__struct), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__struct, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__ctypes), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ctypes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":104
 *     (<object>f)(a)
 * 
 * class PileupColumn(object):             # <<<<<<<<<<<<<<
 *     '''A pileup column. A pileup column contains
 *     all the reads that map to a certain target base.
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_builtin_object);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_object);
  __Pyx_GIVEREF(__pyx_builtin_object);
  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_132)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_CreateClass(__pyx_t_2, ((PyObject *)__pyx_t_1), __pyx_n_s__PileupColumn, "chimerascan.pysam.csamtools"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":117
 *         list of reads (:class:`pysam.PileupRead`) aligned to this column
 *     '''
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" + "\n".join( map(str, self.pileups) )
 */
  __pyx_t_2 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_12PileupColumn___str__, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyMethod_New(__pyx_t_2, 0, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s____str__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PileupColumn, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":161
 *     return 0
 * 
 * class StderrStore():             # <<<<<<<<<<<<<<
 *     '''
 *     stderr is captured.
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_133)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStore, "chimerascan.pysam.csamtools"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":165
 *     stderr is captured.
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
 *         self.stderr_save = Outs( sys.stderr.fileno() )
 */
  __pyx_t_4 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore___init__, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyMethod_New(__pyx_t_4, 0, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s____init__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":170
 *         self.stderr_save.setfd( self.stderr_h )
 * 
 *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
 *         self.stderr_save.restore()
 *         lines = []
 */
  __pyx_t_2 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore_readAndRelease, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyMethod_New(__pyx_t_2, 0, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":178
 *         return lines
 * 
 *     def release(self):             # <<<<<<<<<<<<<<
 *         self.stderr_save.restore()
 *         if os.path.exists(self.stderr_f):
 */
  __pyx_t_4 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore_release, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyMethod_New(__pyx_t_4, 0, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s__release, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":183
 *             os.remove( self.stderr_f )
 * 
 *     def __del__(self):             # <<<<<<<<<<<<<<
 *         self.release()
 * 
 */
  __pyx_t_2 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_11StderrStore___del__, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyMethod_New(__pyx_t_2, 0, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s____del__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":190
 * ######################################################################
 * # valid types for sam headers
 * VALID_HEADER_TYPES = { "HD" : dict,             # <<<<<<<<<<<<<<
 *                        "SQ" : list,
 *                        "RG" : list,
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HD), ((PyObject *)((PyObject*)&PyDict_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":191
 * # valid types for sam headers
 * VALID_HEADER_TYPES = { "HD" : dict,
 *                        "SQ" : list,             # <<<<<<<<<<<<<<
 *                        "RG" : list,
 *                        "PG" : list,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)((PyObject*)&PyList_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":192
 * VALID_HEADER_TYPES = { "HD" : dict,
 *                        "SQ" : list,
 *                        "RG" : list,             # <<<<<<<<<<<<<<
 *                        "PG" : list,
 *                        "CO" : list }
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__RG), ((PyObject *)((PyObject*)&PyList_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":193
 *                        "SQ" : list,
 *                        "RG" : list,
 *                        "PG" : list,             # <<<<<<<<<<<<<<
 *                        "CO" : list }
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)&PyList_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":194
 *                        "RG" : list,
 *                        "PG" : list,
 *                        "CO" : list }             # <<<<<<<<<<<<<<
 * 
 * # order of records within sam headers
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CO), ((PyObject *)((PyObject*)&PyList_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":197
 * 
 * # order of records within sam headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
 * 
 * # type conversions within sam header records
 */
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__HD));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__HD));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__HD));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__SQ));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__SQ));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SQ));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__RG));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__RG));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__RG));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PG));
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__PG));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PG));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__CO));
  PyTuple_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__CO));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CO));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADERS, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":200
 * 
 * # type conversions within sam header records
 * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },             # <<<<<<<<<<<<<<
 *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
 *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SO), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__GO), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":201
 * # type conversions within sam header records
 * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
 *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },             # <<<<<<<<<<<<<<
 *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },
 *                         "PG" : { "ID" : str, "VN" : str, "CL" : str }, }
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SN), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__LN), ((PyObject *)((PyObject*)&PyInt_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__AS), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__M5), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__UR), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SP), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":202
 * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
 *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
 *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },             # <<<<<<<<<<<<<<
 *                         "PG" : { "ID" : str, "VN" : str, "CL" : str }, }
 * 
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SM), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__LB), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__DS), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__PU), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__PI), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__CN), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__DT), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__PL), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":203
 *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
 *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },
 *                         "PG" : { "ID" : str, "VN" : str, "CL" : str }, }             # <<<<<<<<<<<<<<
 * 
 * # output order of fields within records
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__CL), ((PyObject *)((PyObject*)&PyString_Type))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":206
 * 
 * # output order of fields within records
 * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
 *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
 *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__VN));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__VN));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__VN));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__SO));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__SO));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SO));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__GO));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_n_s__GO));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__GO));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HD), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":207
 * # output order of fields within records
 * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
 *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
 *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
 *                        "PG" : ( "ID", "VN", "CL" ), }
 */
  __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__SN));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__SN));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SN));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__LN));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__LN));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LN));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__AS));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_n_s__AS));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AS));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__M5));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_n_s__M5));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__M5));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__UR));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_n_s__UR));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__UR));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__SP));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_n_s__SP));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SP));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SQ), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":208
 * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
 *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
 *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),             # <<<<<<<<<<<<<<
 *                        "PG" : ( "ID", "VN", "CL" ), }
 * 
 */
  __pyx_t_3 = PyTuple_New(9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ID));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__ID));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ID));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__SM));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__SM));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SM));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__LB));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_n_s__LB));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LB));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__DS));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_n_s__DS));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DS));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PU));
  PyTuple_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_n_s__PU));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PU));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PI));
  PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_n_s__PI));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PI));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__CN));
  PyTuple_SET_ITEM(__pyx_t_3, 6, ((PyObject *)__pyx_n_s__CN));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CN));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__DT));
  PyTuple_SET_ITEM(__pyx_t_3, 7, ((PyObject *)__pyx_n_s__DT));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DT));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PL));
  PyTuple_SET_ITEM(__pyx_t_3, 8, ((PyObject *)__pyx_n_s__PL));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PL));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__RG), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":209
 *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
 *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
 *                        "PG" : ( "ID", "VN", "CL" ), }             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ID));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__ID));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ID));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__VN));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__VN));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__VN));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__CL));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_n_s__CL));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CL));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":477
 *                region = None,
 *                callback = None,
 *                until_eof = False ):             # <<<<<<<<<<<<<<
 *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
 * 
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_25 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1950
 *             return self._level
 * 
 * class Outs:             # <<<<<<<<<<<<<<
 *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
 *     def __init__(self, id = 1):
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_134)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__Outs, "chimerascan.pysam.csamtools"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1952
 * class Outs:
 *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
 *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
 *         self.streams = []
 *         self.id = id
 */
  __pyx_t_4 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs___init__, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyMethod_New(__pyx_t_4, 0, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s____init__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1956
 *         self.id = id
 * 
 *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
 *         '''open an existing file, like "/dev/null"'''
 *         fd = os.open(filename, os.O_WRONLY)
 */
  __pyx_t_2 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_setdevice, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyMethod_New(__pyx_t_2, 0, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s__setdevice, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1961
 *         self.setfd(fd)
 * 
 *     def setfile(self, filename):             # <<<<<<<<<<<<<<
 *         '''open a new file.'''
 *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
 */
  __pyx_t_4 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_setfile, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyMethod_New(__pyx_t_4, 0, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s__setfile, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1966
 *         self.setfd(fd)
 * 
 *     def setfd(self, fd):             # <<<<<<<<<<<<<<
 *         ofd = os.dup(self.id)      #  Save old stream on new unit.
 *         self.streams.append(ofd)
 */
  __pyx_t_2 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_setfd, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyMethod_New(__pyx_t_2, 0, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s__setfd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1966; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1973
 *         os.close(fd)                #  Close other unit (look out, caller.)
 * 
 *     def restore(self):             # <<<<<<<<<<<<<<
 *         '''restore previous output stream'''
 *         if self.streams:
 */
  __pyx_t_4 = PyCFunction_New(&__pyx_mdef_11chimerascan_5pysam_9csamtools_4Outs_restore, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyMethod_New(__pyx_t_4, 0, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyObject_SetAttr(__pyx_t_3, __pyx_n_s__restore, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Outs, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":2053
 *     return retval, out_stderr, out_stdout
 * 
 * __all__ = ["Samfile",             # <<<<<<<<<<<<<<
 *            "Fastafile",
 *            "IteratorRow",
 */
  __pyx_t_1 = PyList_New(9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Samfile));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__Samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Fastafile));
  PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__Fastafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Fastafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorRow));
  PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__IteratorRow));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorRow));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorRowAll));
  PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__IteratorRowAll));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorRowAll));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorColumn));
  PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__IteratorColumn));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorColumn));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__AlignedRead));
  PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__AlignedRead));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AlignedRead));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupColumn));
  PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__PileupColumn));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupColumn));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupProxy));
  PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__PileupProxy));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupProxy));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupRead));
  PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s__PileupRead));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupRead));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=True
 * # adds doc-strings for sphinx
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_135), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_136), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_137), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__getrname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_138), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_139), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_140), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__tell); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_141), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_142), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__pileup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_143), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_144), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_145), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___buildLine); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_146), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Samfile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____next__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_147), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Fastafile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_148), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Fastafile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s___open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_149), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Fastafile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_150), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IteratorRow); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____next__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_151), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IteratorRowAll); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____next__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_152), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__IteratorColumn); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____next__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_153), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__AlignedRead); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____str__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_154), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__AlignedRead); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__compare); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_155), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__AlignedRead); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__opt); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_156), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__AlignedRead); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fancy_str); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_157), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__setdevice); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_158), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__setfile); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_159), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__restore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_160), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s___samtools_dispatch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetAttrString(__pyx_t_3, "__doc__"); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_161), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "/home/mkiyer/workspace/chimerascan/chimerascan/pysam/csamtools.pxd":2
 * 
 * cdef extern from "string.h":             # <<<<<<<<<<<<<<
 *   ctypedef int size_t
 *   void *memcpy(void *dst,void *src,size_t len)
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  if (__pyx_m) {
    __Pyx_AddTraceback("init chimerascan.pysam.csamtools");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init chimerascan.pysam.csamtools");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}


#if CYTHON_PROFILE

static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
        if (*code == NULL) {
            *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
            if (*code == NULL) return 0;
        }
        *frame = PyFrame_New(
            PyThreadState_GET(),            /*PyThreadState *tstate*/
            *code,                          /*PyCodeObject *code*/
            PyModule_GetDict(__pyx_m),      /*PyObject *globals*/
            0                               /*PyObject *locals*/
        );
        if (*frame == NULL) return 0;
    }
    else {
        (*frame)->f_tstate = PyThreadState_GET();
    }
    return PyThreadState_GET()->c_profilefunc(PyThreadState_GET()->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
}

static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyCodeObject *py_code = 0;

    #if PY_MAJOR_VERSION < 3
    py_funcname = PyString_FromString(funcname);
    py_srcfile = PyString_FromString(srcfile);
    #else
    py_funcname = PyUnicode_FromString(funcname);
    py_srcfile = PyUnicode_FromString(srcfile);
    #endif
    if (!py_funcname | !py_srcfile) goto bad;

    py_code = PyCode_New(
        0,                /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,                /*int kwonlyargcount,*/
        #endif
        0,                /*int nlocals,*/
        0,                /*int stacksize,*/
        0,                /*int flags,*/
        __pyx_empty_bytes,  /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,       /*PyObject *filename,*/
        py_funcname,      /*PyObject *name,*/
        firstlineno,      /*int firstlineno,*/
        __pyx_empty_bytes   /*PyObject *lnotab*/
    );

bad: 
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    
    return py_code;
}

#endif /* CYTHON_PROFILE */

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
        #if PY_VERSION_HEX < 0x02050000
                 "need more than %d value%s to unpack", (int)index,
        #else
                 "need more than %zd value%s to unpack", index,
        #endif
                 (index == 1) ? "" : "s");
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
        #if PY_VERSION_HEX < 0x02050000
            "too many values to unpack (expected %d)", (int)expected);
        #else
            "too many values to unpack (expected %zd)", expected);
        #endif
}

static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
    PyObject *item;
    if (!(item = PyIter_Next(iter))) {
        if (!PyErr_Occurred()) {
            __Pyx_RaiseNeedMoreValuesError(index);
        }
    }
    return item;
}

static int __Pyx_EndUnpack(PyObject *iter, Py_ssize_t expected) {
    PyObject *item;
    if ((item = PyIter_Next(iter))) {
        Py_DECREF(item);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    }
    else if (!PyErr_Occurred())
        return 0;
    else
        return -1;
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #else
        if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key)))
        #endif
            goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    return 0;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (Py_TYPE(obj) == type) return 1;
    }
    else {
        if (PyObject_TypeCheck(obj, type)) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}


static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable");
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
    if (unlikely(tstate->curexc_type))
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (XDECREF may run arbitrary code). */
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}


static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
    long r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}


static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}

static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_CreateClass(
    PyObject *bases, PyObject *dict, PyObject *name, const char *modname)
{
    PyObject *py_modname;
    PyObject *result = 0;

    #if PY_MAJOR_VERSION < 3
    py_modname = PyString_FromString(modname);
    #else
    py_modname = PyUnicode_FromString(modname);
    #endif
    if (!py_modname)
        goto bad;
    if (PyDict_SetItemString(dict, "__module__", py_modname) < 0)
        goto bad;
    #if PY_MAJOR_VERSION < 3
    result = PyClass_New(bases, dict, name);
    #else
    result = PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, name, bases, dict, NULL);
    #endif
bad:
    Py_XDECREF(py_modname);
    return result;
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t val) {
    const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(uint32_t) == sizeof(char))  ||
        (sizeof(uint32_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(uint32_t) == sizeof(int)) ||
               (sizeof(uint32_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(uint32_t), 
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject* x) {
    const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if (sizeof(uint32_t) == sizeof(char)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(uint32_t) == sizeof(short)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(uint32_t) == sizeof(int)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(uint32_t) == sizeof(long)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedLongLong(x);
    }  else {
        uint32_t val;
        PyObject *v = __Pyx_PyNumber_Int(x);
        #if PY_VERSION_HEX < 0x03000000
        if (likely(v) && !PyLong_Check(v)) {
            PyObject *tmp = v;
            v = PyNumber_Long(tmp);
            Py_DECREF(tmp);
        }
        #endif
        if (likely(v)) {
            int one = 1; int is_little = (int)*(unsigned char *)&one;
            unsigned char *bytes = (unsigned char *)&val;
            int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                          bytes, sizeof(val),
                                          is_little, !is_unsigned);
            Py_DECREF(v);
            if (likely(!ret))
                return val;
        }
        return (uint32_t)-1;
    }
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t val) {
    const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(int32_t) == sizeof(char))  ||
        (sizeof(int32_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(int32_t) == sizeof(int)) ||
               (sizeof(int32_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(int32_t), 
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int64_t(int64_t val) {
    const int64_t neg_one = (int64_t)-1, const_zero = (int64_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(int64_t) == sizeof(char))  ||
        (sizeof(int64_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(int64_t) == sizeof(int)) ||
               (sizeof(int64_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(int64_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(int64_t), 
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject* x) {
    const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if (sizeof(int32_t) == sizeof(char)) {
        if (is_unsigned)
            return (int32_t)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (int32_t)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(int32_t) == sizeof(short)) {
        if (is_unsigned)
            return (int32_t)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (int32_t)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(int32_t) == sizeof(int)) {
        if (is_unsigned)
            return (int32_t)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (int32_t)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(int32_t) == sizeof(long)) {
        if (is_unsigned)
            return (int32_t)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (int32_t)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (int32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (int32_t)__Pyx_PyInt_AsSignedLongLong(x);
    }  else {
        int32_t val;
        PyObject *v = __Pyx_PyNumber_Int(x);
        #if PY_VERSION_HEX < 0x03000000
        if (likely(v) && !PyLong_Check(v)) {
            PyObject *tmp = v;
            v = PyNumber_Long(tmp);
            Py_DECREF(tmp);
        }
        #endif
        if (likely(v)) {
            int one = 1; int is_little = (int)*(unsigned char *)&one;
            unsigned char *bytes = (unsigned char *)&val;
            int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                          bytes, sizeof(val),
                                          is_little, !is_unsigned);
            Py_DECREF(v);
            if (likely(!ret))
                return val;
        }
        return (int32_t)-1;
    }
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint8_t(uint8_t val) {
    const uint8_t neg_one = (uint8_t)-1, const_zero = (uint8_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(uint8_t) == sizeof(char))  ||
        (sizeof(uint8_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(uint8_t) == sizeof(int)) ||
               (sizeof(uint8_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(uint8_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(uint8_t), 
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static CYTHON_INLINE uint64_t __Pyx_PyInt_from_py_uint64_t(PyObject* x) {
    const uint64_t neg_one = (uint64_t)-1, const_zero = (uint64_t)0;
    const int is_unsigned = const_zero < neg_one;
    if (sizeof(uint64_t) == sizeof(char)) {
        if (is_unsigned)
            return (uint64_t)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (uint64_t)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(uint64_t) == sizeof(short)) {
        if (is_unsigned)
            return (uint64_t)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (uint64_t)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(uint64_t) == sizeof(int)) {
        if (is_unsigned)
            return (uint64_t)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (uint64_t)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(uint64_t) == sizeof(long)) {
        if (is_unsigned)
            return (uint64_t)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (uint64_t)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(uint64_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (uint64_t)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (uint64_t)__Pyx_PyInt_AsSignedLongLong(x);
    }  else {
        uint64_t val;
        PyObject *v = __Pyx_PyNumber_Int(x);
        #if PY_VERSION_HEX < 0x03000000
        if (likely(v) && !PyLong_Check(v)) {
            PyObject *tmp = v;
            v = PyNumber_Long(tmp);
            Py_DECREF(tmp);
        }
        #endif
        if (likely(v)) {
            int one = 1; int is_little = (int)*(unsigned char *)&one;
            unsigned char *bytes = (unsigned char *)&val;
            int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                          bytes, sizeof(val),
                                          is_little, !is_unsigned);
            Py_DECREF(v);
            if (likely(!ret))
                return val;
        }
        return (uint64_t)-1;
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
