/* Generated by Cython 0.20.1 on Wed Jul 16 21:19:35 2014 */

#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
#else
#define CYTHON_USE_PYLONG_INTERNALS 0
#endif
#endif
#endif
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02040000
    #error Cython requires Python 2.4+.
#else
#define CYTHON_ABI "0_20_1"
#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
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if CYTHON_COMPILING_IN_PYPY
#define Py_OptimizeFlag 0
#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 CYTHON_FORMAT_SSIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_As_int(o)
  #define PyNumber_Index(o)    ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
                                (PyErr_Format(PyExc_TypeError, \
                                              "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
                                 (PyObject*)0))
  #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
                                  !PyComplex_Check(o))
  #define PyIndex_Check __Pyx_PyIndex_Check
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
  #define __PYX_BUILD_PY_SSIZE_T "i"
#else
  #define __PYX_BUILD_PY_SSIZE_T "n"
  #define CYTHON_FORMAT_SSIZE_T "z"
  #define __Pyx_PyIndex_Check PyIndex_Check
#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)
  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#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_VERSION_HEX < 0x02060000
  #define Py_TPFLAGS_HAVE_VERSION_TAG 0
#endif
#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TPFLAGS_IS_ABSTRACT)
  #define Py_TPFLAGS_IS_ABSTRACT 0
#endif
#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE)
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#define __Pyx_PyString_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#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
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj) || \
                                         PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#if PY_VERSION_HEX < 0x02060000
  #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
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #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
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#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
#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
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
   a quiet NaN. */
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#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

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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE__pysam__csamfile
#define __PYX_HAVE_API__pysam__csamfile
#include "stdint.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "zlib.h"
#include "htslib/kstring.h"
#include "htslib/hfile.h"
#include "htslib/bgzf.h"
#include "htslib/hts.h"
#include "htslib/sam.h"
#include "pysam_stream.h"
#include "htslib/faidx.h"
#include "htslib/tbx.h"
#include "htslib_util.h"
#include "samfile_util.h"
#include "pythread.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#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) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (    \
    (sizeof(type) < sizeof(Py_ssize_t))  ||             \
    (sizeof(type) > sizeof(Py_ssize_t) &&               \
          likely(v < (type)PY_SSIZE_T_MAX ||            \
                 v == (type)PY_SSIZE_T_MAX)  &&         \
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||       \
                                v == (type)PY_SSIZE_T_MIN)))  ||  \
    (sizeof(type) == sizeof(Py_ssize_t) &&              \
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||        \
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromUString(s)  __Pyx_PyObject_FromString((char*)s)
#define __Pyx_PyBytes_FromUString(s)   __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyByteArray_FromUString(s)   __Pyx_PyByteArray_FromString((char*)s)
#define __Pyx_PyStr_FromUString(s)     __Pyx_PyStr_FromString((char*)s)
#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return u_end - u - 1;
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#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);
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys = NULL;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    sys = PyImport_ImportModule("sys");
    if (sys == NULL) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    if (default_encoding == NULL) goto bad;
    if (strcmp(PyBytes_AsString(default_encoding), "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        const char* default_encoding_c = PyBytes_AS_STRING(default_encoding);
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (ascii_chars_u == NULL) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (ascii_chars_b == NULL || strncmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
    }
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return 0;
bad:
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys = NULL;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (sys == NULL) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    if (default_encoding == NULL) goto bad;
    default_encoding_c = PyBytes_AS_STRING(default_encoding);
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(sys);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(sys);
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


#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_d;
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[] = {
  "csamfile.pyx",
  "cfaidx.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
};

/*--- Type declarations ---*/
struct __pyx_obj_5pysam_6cfaidx_Fastafile;
struct __pyx_obj_5pysam_6cfaidx_FastqProxy;
struct __pyx_obj_5pysam_6cfaidx_Fastqfile;
struct __pyx_obj_5pysam_8csamfile_AlignedRead;
struct __pyx_obj_5pysam_8csamfile_Samfile;
struct __pyx_obj_5pysam_8csamfile_PileupProxy;
struct __pyx_obj_5pysam_8csamfile_PileupRead;
struct __pyx_obj_5pysam_8csamfile_IteratorRow;
struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion;
struct __pyx_obj_5pysam_8csamfile_IteratorRowHead;
struct __pyx_obj_5pysam_8csamfile_IteratorRowAll;
struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs;
struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection;
struct __pyx_obj_5pysam_8csamfile_IteratorColumn;
struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion;
struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_8csamfile_IndexedReads;
struct __pyx_obj_5pysam_8csamfile_SNPCall;
struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr;
struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr;
struct __pyx_t_5pysam_8csamfile___iterdata;
typedef struct __pyx_t_5pysam_8csamfile___iterdata __pyx_t_5pysam_8csamfile___iterdata;
struct __pyx_opt_args_5pysam_8csamfile_11AlignedRead_setTag;
struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData;
struct __pyx_opt_args_5pysam_8csamfile_get_type_code;

/* "pysam/csamfile.pxd":54
 * # Utility types
 * 
 * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
 *     htsFile * htsfile
 *     bam_hdr_t * header
 */
struct __pyx_t_5pysam_8csamfile___iterdata {
  htsFile *htsfile;
  bam_hdr_t *header;
  hts_itr_t *iter;
  faidx_t *fastafile;
  int tid;
  char *seq;
  int seq_len;
};

/* "pysam/csamfile.pxd":73
 *     # add an alignment tag with value to the AlignedRead
 *     # an existing tag of the same name will be replaced.
 *     cpdef setTag( self, tag, value, value_type = ?, replace = ? )             # <<<<<<<<<<<<<<
 * 
 * cdef class Samfile:
 */
struct __pyx_opt_args_5pysam_8csamfile_11AlignedRead_setTag {
  int __pyx_n;
  PyObject *value_type;
  PyObject *replace;
};

/* "pysam/csamfile.pxd":179
 *     cdef char * getSequence( self )
 *     cdef setMask(self, mask)
 *     cdef setupIteratorData(self,             # <<<<<<<<<<<<<<
 *                            int tid,
 *                            int start,
 */
struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData {
  int __pyx_n;
  int reopen;
};

/* "pysam/csamfile.pyx":1948
 *     return qual
 * 
 * cdef inline uint8_t get_type_code(value, value_type = None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */
struct __pyx_opt_args_5pysam_8csamfile_get_type_code {
  int __pyx_n;
  PyObject *value_type;
};

/* "cfaidx.pxd":14
 *         char *s
 * 
 * cdef class Fastafile:             # <<<<<<<<<<<<<<
 *     cdef object _filename, _references, _lengths, reference2length
 *     cdef faidx_t* fastafile
 */
struct __pyx_obj_5pysam_6cfaidx_Fastafile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile *__pyx_vtab;
  PyObject *_filename;
  PyObject *_references;
  PyObject *_lengths;
  PyObject *reference2length;
  faidx_t *fastafile;
};


/* "cfaidx.pxd":21
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 * 
 */
struct __pyx_obj_5pysam_6cfaidx_FastqProxy {
  PyObject_HEAD
  kseq_t *_delegate;
};


/* "cfaidx.pxd":25
 * 
 * 
 * cdef class Fastqfile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef gzFile fastqfile
 */
struct __pyx_obj_5pysam_6cfaidx_Fastqfile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile *__pyx_vtab;
  PyObject *_filename;
  gzFile fastqfile;
  kseq_t *entry;
};


/* "pysam/csamfile.pxd":66
 * #
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedRead:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedRead represents
 */
struct __pyx_obj_5pysam_8csamfile_AlignedRead {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_8csamfile_AlignedRead *__pyx_vtab;
  bam1_t *_delegate;
};


/* "pysam/csamfile.pxd":75
 *     cpdef setTag( self, tag, value, value_type = ?, replace = ? )
 * 
 * cdef class Samfile:             # <<<<<<<<<<<<<<
 * 
 *     cdef object _filename
 */
struct __pyx_obj_5pysam_8csamfile_Samfile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_8csamfile_Samfile *__pyx_vtab;
  PyObject *_filename;
  htsFile *htsfile;
  BGZF *fp;
  hts_idx_t *index;
  bam_hdr_t *header;
  int isbam;
  int isstream;
  int isremote;
  bam1_t *b;
  char *mode;
  int64_t start_offset;
};


/* "pysam/csamfile.pxd":112
 *     cdef char * _getrname(self, int tid)
 * 
 * cdef class PileupProxy:             # <<<<<<<<<<<<<<
 *     cdef bam_pileup1_t ** plp
 *     cdef int tid
 */
struct __pyx_obj_5pysam_8csamfile_PileupProxy {
  PyObject_HEAD
  bam_pileup1_t **plp;
  int tid;
  int pos;
  int n_pu;
};


/* "pysam/csamfile.pxd":118
 *     cdef int n_pu
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef AlignedRead _alignment
 *     cdef int32_t  _qpos
 */
struct __pyx_obj_5pysam_8csamfile_PileupRead {
  PyObject_HEAD
  struct __pyx_obj_5pysam_8csamfile_AlignedRead *_alignment;
  int32_t _qpos;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
};


/* "pysam/csamfile.pxd":127
 *     cdef uint32_t _is_tail
 * 
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     cdef int retval
 *     cdef bam1_t * b
 */
struct __pyx_obj_5pysam_8csamfile_IteratorRow {
  PyObject_HEAD
  int retval;
  bam1_t *b;
  struct __pyx_obj_5pysam_8csamfile_Samfile *samfile;
  htsFile *htsfile;
  int owns_samfile;
};


/* "pysam/csamfile.pxd":134
 *     cdef int owns_samfile
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent( self )
 */
struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowRegion *__pyx_vtab;
  hts_itr_t *iter;
};


/* "pysam/csamfile.pxd":139
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */
struct __pyx_obj_5pysam_8csamfile_IteratorRowHead {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowHead *__pyx_vtab;
  int max_rows;
  int current_row;
};


/* "pysam/csamfile.pxd":145
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent( self )
 *     cdef int cnext(self)
 */
struct __pyx_obj_5pysam_8csamfile_IteratorRowAll {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowAll *__pyx_vtab;
};


/* "pysam/csamfile.pxd":149
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int         tid
 *     cdef IteratorRowRegion rowiter
 */
struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow __pyx_base;
  int tid;
  struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *rowiter;
};


/* "pysam/csamfile.pxd":153
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */
struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowSelection *__pyx_vtab;
  int current_pos;
  PyObject *positions;
  BGZF *fp;
};


/* "pysam/csamfile.pxd":160
 *     cdef BGZF * fp
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */
struct __pyx_obj_5pysam_8csamfile_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *iter;
  int tid;
  int pos;
  int n_plp;
  int mask;
  bam_pileup1_t *plp;
  bam_plp_t pileup_iter;
  __pyx_t_5pysam_8csamfile___iterdata iterdata;
  struct __pyx_obj_5pysam_8csamfile_Samfile *samfile;
  struct __pyx_obj_5pysam_6cfaidx_Fastafile *fastafile;
  PyObject *stepper;
  int max_depth;
};


/* "pysam/csamfile.pxd":187
 *     cdef reset(self, tid, start, end)
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */
struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion {
  struct __pyx_obj_5pysam_8csamfile_IteratorColumn __pyx_base;
  int start;
  int end;
  int truncate;
};


/* "pysam/csamfile.pxd":192
 *     cdef int truncate
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs {
  struct __pyx_obj_5pysam_8csamfile_IteratorColumn __pyx_base;
};


/* "pysam/csamfile.pxd":195
 *     pass
 * 
 * cdef class IndexedReads:             # <<<<<<<<<<<<<<
 *     cdef Samfile samfile
 *     cdef htsFile * htsfile
 */
struct __pyx_obj_5pysam_8csamfile_IndexedReads {
  PyObject_HEAD
  struct __pyx_obj_5pysam_8csamfile_Samfile *samfile;
  htsFile *htsfile;
  PyObject *index;
  int owns_samfile;
  BGZF *fp;
};


/* "pysam/csamfile.pyx":3324
 * 
 * 
 * cdef class SNPCall:             # <<<<<<<<<<<<<<
 *     '''the results of a SNP call.'''
 *     cdef int _tid
 */
struct __pyx_obj_5pysam_8csamfile_SNPCall {
  PyObject_HEAD
  int _tid;
  int _pos;
  char _reference_base;
  char _genotype;
  int _consensus_quality;
  int _snp_quality;
  int _rms_mapping_quality;
  int _coverage;
};


/* "pysam/csamfile.pyx":105
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 */
struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr {
  PyObject_HEAD
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_y;
  PyObject *__pyx_t_0;
  PyObject *__pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/csamfile.pyx":107
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
 * 
 */
struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr {
  PyObject_HEAD
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_y;
  PyObject *__pyx_t_0;
  PyObject *__pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};



/* "cfaidx.pxd":14
 *         char *s
 * 
 * cdef class Fastafile:             # <<<<<<<<<<<<<<
 *     cdef object _filename, _references, _lengths, reference2length
 *     cdef faidx_t* fastafile
 */

struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile {
  char *(*_fetch)(struct __pyx_obj_5pysam_6cfaidx_Fastafile *, char *, int, int, int *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile *__pyx_vtabptr_5pysam_6cfaidx_Fastafile;


/* "cfaidx.pxd":25
 * 
 * 
 * cdef class Fastqfile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef gzFile fastqfile
 */

struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile {
  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_6cfaidx_Fastqfile *);
  int (*cnext)(struct __pyx_obj_5pysam_6cfaidx_Fastqfile *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile *__pyx_vtabptr_5pysam_6cfaidx_Fastqfile;


/* "pysam/csamfile.pyx":2045
 * ###########################################################
 * ###########################################################
 * cdef class AlignedRead:             # <<<<<<<<<<<<<<
 *     '''
 *     Class representing an aligned read. See the SAM format specification for
 */

struct __pyx_vtabstruct_5pysam_8csamfile_AlignedRead {
  PyObject *(*setTag)(struct __pyx_obj_5pysam_8csamfile_AlignedRead *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_8csamfile_11AlignedRead_setTag *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_AlignedRead *__pyx_vtabptr_5pysam_8csamfile_AlignedRead;


/* "pysam/csamfile.pyx":247
 * 
 * 
 * cdef class Samfile:             # <<<<<<<<<<<<<<
 *     '''*(filename, mode=None, template = None,
 *          referencenames = None, referencelengths = None,
 */

struct __pyx_vtabstruct_5pysam_8csamfile_Samfile {
  bam_hdr_t *(*_buildHeader)(struct __pyx_obj_5pysam_8csamfile_Samfile *, PyObject *);
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_8csamfile_Samfile *);
  int (*cnext)(struct __pyx_obj_5pysam_8csamfile_Samfile *);
  int (*write)(struct __pyx_obj_5pysam_8csamfile_Samfile *, struct __pyx_obj_5pysam_8csamfile_AlignedRead *, int __pyx_skip_dispatch);
  char *(*_getrname)(struct __pyx_obj_5pysam_8csamfile_Samfile *, int);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_Samfile *__pyx_vtabptr_5pysam_8csamfile_Samfile;


/* "pysam/csamfile.pyx":1266
 *             hts_close(self.htsfile)
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(Samfile samfile, int tid, int beg, int end, int reopen = True )*
 * 
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowRegion {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *);
  int (*cnext)(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowRegion *__pyx_vtabptr_5pysam_8csamfile_IteratorRowRegion;


/* "pysam/csamfile.pyx":1330
 *         hts_itr_destroy(self.iter)
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(Samfile samfile, n, int reopen = True)*
 * 
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowHead {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *);
  int (*cnext)(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowHead *__pyx_vtabptr_5pysam_8csamfile_IteratorRowHead;


/* "pysam/csamfile.pyx":1383
 * 
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(Samfile samfile, int reopen = True)*
 * 
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowAll *__pyx_vtabptr_5pysam_8csamfile_IteratorRowAll;


/* "pysam/csamfile.pyx":1484
 * 
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(Samfile samfile)*
 * 
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowSelection {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *);
  int (*cnext)(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowSelection *__pyx_vtabptr_5pysam_8csamfile_IteratorRowSelection;


/* "pysam/csamfile.pyx":1608
 *     return ret
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 *     '''abstract base class for iterators over columns.
 * 
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn {
  int (*cnext)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *);
  char *(*getSequence)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *);
  PyObject *(*setMask)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *, PyObject *);
  PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData *__pyx_optional_args);
  PyObject *(*reset)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *, PyObject *, PyObject *, PyObject *);
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn *__pyx_vtabptr_5pysam_8csamfile_IteratorColumn;


/* "pysam/csamfile.pyx":1782
 * 
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     '''iterates over a region only.
 *     '''
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnRegion {
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_8csamfile_IteratorColumnRegion;


/* "pysam/csamfile.pyx":1820
 * 
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     """iterates over all columns by chaining iterators over each reference
 *     """
 */

struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnAllRefs {
  struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_8csamfile_IteratorColumnAllRefs;
#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); /*proto*/
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          if (acquire_gil) { \
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
              PyGILState_Release(__pyx_gilstate_save); \
          } else { \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #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_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #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_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XDECREF_SET(r, v) do {                            \
        PyObject *tmp = (PyObject *) r;                         \
        r = v; __Pyx_XDECREF(tmp);                              \
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {                             \
        PyObject *tmp = (PyObject *) r;                         \
        r = v; __Pyx_DECREF(tmp);                               \
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/

#ifndef CYTHON_PROFILE
  #define CYTHON_PROFILE 1
#endif
#ifndef CYTHON_TRACE
  #define CYTHON_TRACE 0
#endif
#if CYTHON_TRACE
  #undef CYTHON_PROFILE_REUSE_FRAME
#endif
#ifndef CYTHON_PROFILE_REUSE_FRAME
  #define CYTHON_PROFILE_REUSE_FRAME 0
#endif
#if CYTHON_PROFILE || CYTHON_TRACE
  #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_CLEAR(__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 || (CYTHON_TRACE && PyThreadState_GET()->c_tracefunc)))) {      \
      __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 || (CYTHON_TRACE && PyThreadState_GET()->c_tracefunc))) {  \
      PyThreadState* tstate = PyThreadState_GET();                                         \
      tstate->use_tracing = 0;                                                             \
      PyObject *exc_info = __Pyx_GetExceptionTuple();                                      \
      if (exc_info) {                                                                      \
          if (CYTHON_TRACE && tstate->c_tracefunc)                                         \
              tstate->c_tracefunc(                                                         \
                  tstate->c_traceobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);          \
          tstate->c_profilefunc(                                                           \
              tstate->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);            \
          Py_DECREF(exc_info);                                                             \
      }                                                                                    \
      tstate->use_tracing = 1;                                                             \
  }
  #define __Pyx_TraceReturn(result)                                                  \
  if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing) {             \
      PyThreadState* tstate = PyThreadState_GET();                                   \
      tstate->use_tracing = 0;                                                        \
      if (CYTHON_TRACE && tstate->c_tracefunc)                                       \
          tstate->c_tracefunc(                                                       \
              tstate->c_traceobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result);  \
      if (tstate->c_profilefunc)                                                     \
          tstate->c_profilefunc(                                                     \
              tstate->c_profileobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result);  \
      CYTHON_FRAME_DEL;                                                              \
      tstate->use_tracing = 1;                                                       \
  }
  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 */
#if CYTHON_TRACE
  #define __Pyx_TraceLine(lineno)                                                          \
  if (unlikely(__Pyx_use_tracing) && unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_tracefunc)) {    \
      PyThreadState* tstate = PyThreadState_GET();                                         \
      __pyx_frame->f_lineno = lineno;                                                     \
      tstate->use_tracing = 0;                                                             \
      tstate->c_tracefunc(tstate->c_traceobj, __pyx_frame, PyTrace_LINE, NULL);           \
      tstate->use_tracing = 1;                                                             \
  }
#else
  #define __Pyx_TraceLine(lineno)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); /*proto*/
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

#include <string.h>

static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));

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 void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/

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

#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join
#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
#else
#define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION < 3
    #define __Pyx_PyBytes_Join _PyString_Join
    #else
    #define __Pyx_PyBytes_Join _PyBytes_Join
    #endif
#else
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values); /*proto*/
#endif

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 int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
    const char* function_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 CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact); /*proto*/

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 int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/

#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

static PyObject* __Pyx_PyObject_CallMethodTuple(PyObject* obj, PyObject* method_name, PyObject* args) {
    PyObject *method, *result = NULL;
    if (unlikely(!args)) return NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
    result = __Pyx_PyObject_Call(method, args, NULL);
    Py_DECREF(method);
bad:
    Py_DECREF(args);
    return result;
}
#define __Pyx_PyObject_CallMethod3(obj, name, arg1, arg2, arg3) \
    __Pyx_PyObject_CallMethodTuple(obj, name, PyTuple_Pack(3, arg1, arg2, arg3))
#define __Pyx_PyObject_CallMethod2(obj, name, arg1, arg2) \
    __Pyx_PyObject_CallMethodTuple(obj, name, PyTuple_Pack(2, arg1, arg2))
#define __Pyx_PyObject_CallMethod1(obj, name, arg1) \
    __Pyx_PyObject_CallMethodTuple(obj, name, PyTuple_Pack(1, arg1))
#define __Pyx_PyObject_CallMethod0(obj, name) \
    __Pyx_PyObject_CallMethodTuple(obj, name, (Py_INCREF(__pyx_empty_tuple), __pyx_empty_tuple))

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*proto*/

static CYTHON_INLINE int __Pyx_PySequence_Contains(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /*proto*/

static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback); /*proto*/

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/

static CYTHON_INLINE int __Pyx_PyDict_Contains(PyObject* item, PyObject* dict, int eq) {
    int result = PyDict_Contains(dict, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

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

static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/

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

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

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

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

static void* __Pyx_GetVtable(PyObject *dict); /*proto*/

static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

#define __Pyx_CyFunction_USED 1
#include <structmember.h>
#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
#define __Pyx_CYFUNCTION_CCLASS        0x04
#define __Pyx_CyFunction_GetClosure(f) \
    (((__pyx_CyFunctionObject *) (f))->func_closure)
#define __Pyx_CyFunction_GetClassObj(f) \
    (((__pyx_CyFunctionObject *) (f))->func_classobj)
#define __Pyx_CyFunction_Defaults(type, f) \
    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
#define __Pyx_CyFunction_SetDefaultsGetter(f, g) \
    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
typedef struct {
    PyCFunctionObject func;
    PyObject *func_dict;
    PyObject *func_weakreflist;
    PyObject *func_name;
    PyObject *func_qualname;
    PyObject *func_doc;
    PyObject *func_globals;
    PyObject *func_code;
    PyObject *func_closure;
    PyObject *func_classobj; /* No-args super() class cell */
    void *defaults;
    int defaults_pyobjects;
    int flags;
    PyObject *defaults_tuple;   /* Const defaults tuple */
    PyObject *defaults_kwdict;  /* Const kwonly defaults dict */
    PyObject *(*defaults_getter)(PyObject *);
    PyObject *func_annotations; /* function annotations dict */
} __pyx_CyFunctionObject;
static PyTypeObject *__pyx_CyFunctionType = 0;
#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code) \
    __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *self,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
                                                         size_t size,
                                                         int pyobjects);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
                                                            PyObject *tuple);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                             PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                              PyObject *dict);
static int __Pyx_CyFunction_init(void);

static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
                                           PyObject *mkw, PyObject *modname, PyObject *doc); /*proto*/
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /*proto*/

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

static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value);

static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);

static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *);

static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);

static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

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

#define __Pyx_Generator_USED
#include <structmember.h>
#include <frameobject.h>
typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *);
typedef struct {
    PyObject_HEAD
    __pyx_generator_body_t body;
    PyObject *closure;
    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;
    PyObject *gi_weakreflist;
    PyObject *classobj;
    PyObject *yieldfrom;
    int resume_label;
    char is_running;
} __pyx_GeneratorObject;
static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
                                                  PyObject *closure);
static int __pyx_Generator_init(void);
static int __Pyx_Generator_clear(PyObject* self);
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue);
#else
#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue)
#endif

static int __Pyx_check_binary_version(void);

#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

static PyObject *__Pyx_ImportModule(const char *name); /*proto*/

static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);  /*proto*/

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/


/* Module declarations from 'libc.stdint' */

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdlib' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from 'pysam.chtslib' */

/* Module declarations from 'pysam.cfaidx' */
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_Fastafile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastqProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_Fastqfile = 0;

/* Module declarations from 'cpython.version' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'cpython.exc' */

/* Module declarations from 'cpython.module' */

/* Module declarations from 'cpython.mem' */

/* Module declarations from 'cpython.tuple' */

/* Module declarations from 'cpython.list' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.sequence' */

/* Module declarations from 'cpython.mapping' */

/* Module declarations from 'cpython.iterator' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* Module declarations from 'cpython.number' */

/* Module declarations from 'cpython.int' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.bool' */
static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;

/* Module declarations from 'cpython.long' */

/* Module declarations from 'cpython.float' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.complex' */
static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;

/* Module declarations from 'cpython.string' */

/* Module declarations from 'cpython.unicode' */

/* Module declarations from 'cpython.dict' */

/* Module declarations from 'cpython.instance' */

/* Module declarations from 'cpython.function' */

/* Module declarations from 'cpython.method' */

/* Module declarations from 'cpython.weakref' */

/* Module declarations from 'cpython.getargs' */

/* Module declarations from 'cpython.pythread' */

/* Module declarations from 'cpython.pystate' */

/* Module declarations from 'cpython.cobject' */

/* Module declarations from 'cpython.oldbuffer' */

/* Module declarations from 'cpython.set' */

/* Module declarations from 'cpython.buffer' */

/* Module declarations from 'cpython.bytes' */

/* Module declarations from 'cpython.pycapsule' */

/* Module declarations from 'cpython' */

/* Module declarations from 'pysam.csamfile' */
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_AlignedRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_Samfile = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_PileupProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_PileupRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorRowRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorRowHead = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorRowAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorRowSelection = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorColumnRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IteratorColumnAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_IndexedReads = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile_SNPCall = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile___pyx_scope_struct__genexpr = 0;
static PyTypeObject *__pyx_ptype_5pysam_8csamfile___pyx_scope_struct_1_genexpr = 0;
static PyObject *__pyx_v_5pysam_8csamfile__FILENAME_ENCODING = 0;
static char *__pyx_v_5pysam_8csamfile_CODE2CIGAR;
static int __pyx_v_5pysam_8csamfile_max_pos;
static PyObject *__pyx_f_5pysam_8csamfile_from_string_and_size(char *, size_t); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile__encodeFilename(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile__forceBytes(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile__charptr_to_str(char *); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile__forceStr(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile_makeAlignedRead(bam1_t *); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile_makePileupProxy(bam_pileup1_t **, int, int, int); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile_makePileupRead(bam_pileup1_t *); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile_convertBinaryTagToList(uint8_t *); /*proto*/
static int __pyx_f_5pysam_8csamfile___advance_all(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_8csamfile___advance_snpcalls(void *, bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_8csamfile_query_start(bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_8csamfile_query_end(bam1_t *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_8csamfile_get_seq_range(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_8csamfile_get_qual_range(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE uint8_t __pyx_f_5pysam_8csamfile_get_type_code(PyObject *, struct __pyx_opt_args_5pysam_8csamfile_get_type_code *__pyx_optional_args); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_8csamfile_convert_python_tag(PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/
#define __Pyx_MODULE_NAME "pysam.csamfile"
int __pyx_module_is_main_pysam__csamfile = 0;

/* Implementation of 'pysam.csamfile' */
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_ord;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_OverflowError;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_OSError;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_sorted;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_pf_5pysam_8csamfile_genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_3genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_12PileupColumn___str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_7Samfile___cinit__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_2_isOpen(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_4_hasIndex(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_6_open(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_template, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_text, PyObject *__pyx_v_header, PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_8gettid(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_10getrname(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_12_parseRegion(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_14reset(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_16seek(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, uint64_t __pyx_v_offset, int __pyx_v_where); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_18tell(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_20fetch(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_callback, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_22head(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_n); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_24mate(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_26count(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_28pileup(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_30close(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_8csamfile_7Samfile_32__dealloc__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_34write(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_36__enter__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_38__exit__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_8filename___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_11nreferences___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_10references___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_7lengths___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_6mapped___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_40_checkIndex(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_8unmapped___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_12nocoordinate___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_4text___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_6header___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_42_buildLine(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_44__iter__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_46__next__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11IteratorRow___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_reopen); /* proto */
static void __pyx_pf_5pysam_8csamfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_8csamfile_IteratorRow *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_8csamfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, PyObject *__pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_4addReference(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_6cfaidx_Fastafile *__pyx_v_fastafile); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_6hasReference(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_8csamfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead___init__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_8csamfile_11AlignedRead_2__dealloc__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4__str__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_6compare(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_other); /* proto */
static Py_hash_t __pyx_pf_5pysam_8csamfile_11AlignedRead_8__hash__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_10_convert_python_tag(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_pytag, PyObject *__pyx_v_value, PyObject *__pyx_v_fmts, PyObject *__pyx_v_args); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5qname___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5qname_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5cigar___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5cigar_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_values); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_11cigarstring___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_11cigarstring_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_cigar); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3seq___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3seq_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_seq); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4qual___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4qual_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5query___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5qqual___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_6qstart___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4qend___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4qlen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4tags___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4tags_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_12setTag(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4flag___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4flag_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5rname___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5rname_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3tid___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3tid_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3pos___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3pos_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_pos); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3bin___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3bin_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_bin); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4rlen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4aend___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4alen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4mapq___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4mapq_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4mrnm___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4mrnm_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5rnext___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5rnext_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4mpos___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4mpos_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5pnext___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5pnext_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5isize___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5isize_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4tlen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4tlen_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_9is_paired___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_paired_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_14is_proper_pair___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_11is_unmapped___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_11is_unmapped_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_10is_reverse___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_10is_reverse_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_15mate_is_reverse___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read1___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read1_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read2___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read2_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_12is_secondary___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_secondary_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_9is_qcfail___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_qcfail_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_12is_duplicate___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_duplicate_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_9positions___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_15inferred_length___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_13aligned_pairs___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_6blocks___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_14overlap(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_16opt(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_18fancy_str(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11PileupProxy___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_2__str__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_3tid___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_1n___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_11PileupProxy_1n_2__set__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self, PyObject *__pyx_v_n); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_3pos___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_7pileups___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_2__str__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_4qpos___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_5level___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall___str__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_8csamfile_12IndexedReads___init__(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_reopen); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_12IndexedReads_2build(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_8csamfile_12IndexedReads_4find(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */
static void __pyx_pf_5pysam_8csamfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_tp_new_5pysam_8csamfile_AlignedRead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_Samfile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_PileupProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_IndexedReads(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile_SNPCall(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile___pyx_scope_struct__genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_8csamfile___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static char __pyx_k_A[] = "A";
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_H[] = "H";
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_h[] = "h";
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_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_FO[] = "FO";
static char __pyx_k_GO[] = "GO";
static char __pyx_k_HD[] = "HD";
static char __pyx_k_ID[] = "ID";
static char __pyx_k_KS[] = "KS";
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_PN[] = "PN";
static char __pyx_k_PP[] = "PP";
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__3[] = "\t";
static char __pyx_k__4[] = "\n";
static char __pyx_k__6[] = "-";
static char __pyx_k__9[] = "";
static char __pyx_k_os[] = "os";
static char __pyx_k_rU[] = "rU";
static char __pyx_k_rb[] = "rb";
static char __pyx_k_re[] = "re";
static char __pyx_k_wb[] = "wb";
static char __pyx_k_wh[] = "wh";
static char __pyx_k__14[] = "[:-]";
static char __pyx_k__41[] = "@";
static char __pyx_k__47[] = ":";
static char __pyx_k__76[] = "<";
static char __pyx_k__79[] = "(";
static char __pyx_k__80[] = ")";
static char __pyx_k_all[] = "all";
static char __pyx_k_bai[] = ".bai";
static char __pyx_k_beg[] = "beg";
static char __pyx_k_bin[] = "bin";
static char __pyx_k_c_2[] = "%c";
static char __pyx_k_chr[] = "chr";
static char __pyx_k_doc[] = "__doc__";
static char __pyx_k_end[] = "end";
static char __pyx_k_ftp[] = "ftp:";
static char __pyx_k_get[] = "get";
static char __pyx_k_i_c[] = "%i%c";
static char __pyx_k_map[] = "map";
static char __pyx_k_max[] = "max";
static char __pyx_k_min[] = "min";
static char __pyx_k_ord[] = "ord";
static char __pyx_k_pos[] = "pos";
static char __pyx_k_raw[] = "raw";
static char __pyx_k_s_2[] = "s";
static char __pyx_k_s_s[] = "%s:%s";
static char __pyx_k_seq[] = "seq";
static char __pyx_k_str[] = "__str__";
static char __pyx_k_sys[] = "sys";
static char __pyx_k_tag[] = "tag";
static char __pyx_k_tid[] = "tid";
static char __pyx_k_wbu[] = "wbu";
static char __pyx_k_zip[] = "zip";
static char __pyx_k_2scB[] = "2scB";
static char __pyx_k_2scH[] = "2scH";
static char __pyx_k_2scI[] = "2scI";
static char __pyx_k_2scb[] = "2scb";
static char __pyx_k_2scc[] = "2scc";
static char __pyx_k_2scf[] = "2scf";
static char __pyx_k_2sch[] = "2sch";
static char __pyx_k_2sci[] = "2sci";
static char __pyx_k_Zidf[] = "Zidf";
static char __pyx_k_args[] = "args";
static char __pyx_k_flag[] = "flag";
static char __pyx_k_fmts[] = "fmts";
static char __pyx_k_http[] = "http:";
static char __pyx_k_init[] = "__init__";
static char __pyx_k_join[] = "join";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_mapq[] = "mapq";
static char __pyx_k_mode[] = "mode";
static char __pyx_k_mpos[] = "mpos";
static char __pyx_k_mrnm[] = "mrnm";
static char __pyx_k_mtid[] = "mtid";
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_rlen[] = "rlen";
static char __pyx_k_seek[] = "seek";
static char __pyx_k_self[] = "self";
static char __pyx_k_send[] = "send";
static char __pyx_k_tags[] = "tags";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_text[] = "text";
static char __pyx_k_warn[] = "warn";
static char __pyx_k_all_2[] = "__all__";
static char __pyx_k_ascii[] = "ascii";
static char __pyx_k_bqual[] = "bqual";
static char __pyx_k_cigar[] = "cigar";
static char __pyx_k_close[] = "close";
static char __pyx_k_fetch[] = "fetch";
static char __pyx_k_indel[] = "indel";
static char __pyx_k_isize[] = "isize";
static char __pyx_k_items[] = "items";
static char __pyx_k_level[] = "level";
static char __pyx_k_pytag[] = "pytag";
static char __pyx_k_qname[] = "qname";
static char __pyx_k_rname[] = "rname";
static char __pyx_k_split[] = "split";
static char __pyx_k_start[] = "start";
static char __pyx_k_strip[] = "strip";
static char __pyx_k_throw[] = "throw";
static char __pyx_k_types[] = "types";
static char __pyx_k_value[] = "value";
static char __pyx_k_where[] = "where";
static char __pyx_k_write[] = "write";
static char __pyx_k_2sc_is[] = "2sc%is";
static char __pyx_k_append[] = "append";
static char __pyx_k_ctypes[] = "ctypes";
static char __pyx_k_decode[] = "decode";
static char __pyx_k_encode[] = "encode";
static char __pyx_k_exists[] = "exists";
static char __pyx_k_extend[] = "extend";
static char __pyx_k_fields[] = "fields";
static char __pyx_k_gettid[] = "gettid";
static char __pyx_k_header[] = "header";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_isOpen[] = "_isOpen";
static char __pyx_k_is_del[] = "is_del";
static char __pyx_k_l_data[] = "l_data";
static char __pyx_k_l_qseq[] = "l_qseq";
static char __pyx_k_m_data[] = "m_data";
static char __pyx_k_module[] = "__module__";
static char __pyx_k_object[] = "object";
static char __pyx_k_offset[] = "offset";
static char __pyx_k_record[] = "record";
static char __pyx_k_region[] = "region";
static char __pyx_k_reopen[] = "reopen";
static char __pyx_k_setTag[] = "setTag";
static char __pyx_k_sorted[] = "sorted";
static char __pyx_k_struct[] = "struct";
static char __pyx_k_IOError[] = "IOError";
static char __pyx_k_OSError[] = "OSError";
static char __pyx_k_Samfile[] = "Samfile";
static char __pyx_k_compile[] = "compile";
static char __pyx_k_findall[] = "findall";
static char __pyx_k_is_head[] = "is_head";
static char __pyx_k_is_tail[] = "is_tail";
static char __pyx_k_islower[] = "islower";
static char __pyx_k_isupper[] = "isupper";
static char __pyx_k_l_qname[] = "l_qname";
static char __pyx_k_lengths[] = "lengths";
static char __pyx_k_n_cigar[] = "n_cigar";
static char __pyx_k_pileups[] = "pileups";
static char __pyx_k_prepare[] = "__prepare__";
static char __pyx_k_replace[] = "replace";
static char __pyx_k_samfile[] = "samfile";
static char __pyx_k_stepper[] = "stepper";
static char __pyx_k_KeyError[] = "KeyError";
static char __pyx_k_calcsize[] = "calcsize";
static char __pyx_k_callback[] = "callback";
static char __pyx_k_check_sq[] = "check_sq";
static char __pyx_k_coverage[] = "coverage";
static char __pyx_k_exc_type[] = "exc_type";
static char __pyx_k_filename[] = "filename";
static char __pyx_k_genotype[] = "genotype";
static char __pyx_k_hasIndex[] = "_hasIndex";
static char __pyx_k_nextiter[] = "nextiter";
static char __pyx_k_platform[] = "platform";
static char __pyx_k_qualname[] = "__qualname__";
static char __pyx_k_samtools[] = "samtools";
static char __pyx_k_tempfile[] = "tempfile";
static char __pyx_k_template[] = "template";
static char __pyx_k_truncate[] = "truncate";
static char __pyx_k_warnings[] = "warnings";
static char __pyx_k_2sccI_i_s[] = "2sccI%i%s";
static char __pyx_k_30s_10s_s[] = "%-30s %-10s= %s";
static char __pyx_k_MIDNSHP_X[] = "MIDNSHP=X";
static char __pyx_k_TypeError[] = "TypeError";
static char __pyx_k_alignment[] = "alignment";
static char __pyx_k_buildLine[] = "_buildLine";
static char __pyx_k_enumerate[] = "enumerate";
static char __pyx_k_exc_value[] = "exc_value";
static char __pyx_k_fastafile[] = "fastafile";
static char __pyx_k_itertools[] = "itertools";
static char __pyx_k_max_depth[] = "max_depth";
static char __pyx_k_metaclass[] = "__metaclass__";
static char __pyx_k_pack_into[] = "pack_into";
static char __pyx_k_positions[] = "positions";
static char __pyx_k_reference[] = "reference";
static char __pyx_k_traceback[] = "traceback";
static char __pyx_k_until_eof[] = "until_eof";
static char __pyx_k_CIGAR2CODE[] = "CIGAR2CODE";
static char __pyx_k_IS_PYTHON3[] = "IS_PYTHON3";
static char __pyx_k_PileupRead[] = "PileupRead";
static char __pyx_k_Query_name[] = "Query name";
static char __pyx_k_ValueError[] = "ValueError";
static char __pyx_k_checkIndex[] = "_checkIndex";
static char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static char __pyx_k_references[] = "references";
static char __pyx_k_startswith[] = "startswith";
static char __pyx_k_value_type[] = "value_type";
static char __pyx_k_AlignedRead[] = "AlignedRead";
static char __pyx_k_Binary_flag[] = "Binary flag";
static char __pyx_k_CIGAR_REGEX[] = "CIGAR_REGEX";
static char __pyx_k_Insert_size[] = "Insert size";
static char __pyx_k_IteratorRow[] = "IteratorRow";
static char __pyx_k_PileupProxy[] = "PileupProxy";
static char __pyx_k_add_sq_text[] = "add_sq_text";
static char __pyx_k_collections[] = "collections";
static char __pyx_k_d_MIDNSHP_X[] = "(\\d+)([MIDNSHP=X])";
static char __pyx_k_defaultdict[] = "defaultdict";
static char __pyx_k_nreferences[] = "nreferences";
static char __pyx_k_parseRegion[] = "_parseRegion";
static char __pyx_k_snp_quality[] = "snp_quality";
static char __pyx_k_Contig_index[] = "Contig index";
static char __pyx_k_IndexedReads[] = "IndexedReads";
static char __pyx_k_PileupColumn[] = "PileupColumn";
static char __pyx_k_SQ_SN_s_LN_s[] = "@SQ\tSN:%s\tLN:%s\n";
static char __pyx_k_check_header[] = "check_header";
static char __pyx_k_getattribute[] = "__getattribute__";
static char __pyx_k_version_info[] = "version_info";
static char __pyx_k_Cigar_entries[] = "Cigar entries";
static char __pyx_k_Invalid_tag_s[] = "Invalid tag: %s";
static char __pyx_k_OverflowError[] = "OverflowError";
static char __pyx_k_StopIteration[] = "StopIteration";
static char __pyx_k_VALID_HEADERS[] = "VALID_HEADERS";
static char __pyx_k_AttributeError[] = "AttributeError";
static char __pyx_k_IteratorColumn[] = "IteratorColumn";
static char __pyx_k_Quality_scores[] = "Quality scores";
static char __pyx_k_Query_sequence[] = "Query sequence";
static char __pyx_k_mate_not_found[] = "mate not found";
static char __pyx_k_properties_bin[] = "properties bin";
static char __pyx_k_pysam_csamfile[] = "pysam.csamfile";
static char __pyx_k_reference_base[] = "reference_base";
static char __pyx_k_referencenames[] = "referencenames";
static char __pyx_k_unknown_type_s[] = "unknown type '%s'";
static char __pyx_k_Mapping_quality[] = "Mapping quality";
static char __pyx_k_mapping_quality[] = "mapping_quality";
static char __pyx_k_properties_flag[] = "properties flag";
static char __pyx_k_file_s_not_found[] = "file `%s` not found";
static char __pyx_k_read_s_not_found[] = "read %s not found";
static char __pyx_k_referencelengths[] = "referencelengths";
static char __pyx_k_consensus_quality[] = "consensus_quality";
static char __pyx_k_mapping_quality_2[] = "mapping quality";
static char __pyx_k_tag_s_not_present[] = "tag '%s' not present";
static char __pyx_k_PileupColumn___str[] = "PileupColumn.__str__";
static char __pyx_k_VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
static char __pyx_k_VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
static char __pyx_k_end_out_of_range_i[] = "end out of range (%i)";
static char __pyx_k_getdefaultencoding[] = "getdefaultencoding";
static char __pyx_k_mate_s_is_unmapped[] = "mate %s: is unmapped";
static char __pyx_k_read_s_is_unpaired[] = "read %s: is unpaired";
static char __pyx_k_true_if_QC_failure[] = "true if QC failure";
static char __pyx_k_Maximum_data_length[] = "Maximum data length";
static char __pyx_k_NotImplementedError[] = "NotImplementedError";
static char __pyx_k_VALID_HEADER_FIELDS[] = "VALID_HEADER_FIELDS";
static char __pyx_k_invalid_reference_s[] = "invalid reference `%s`";
static char __pyx_k_the_genotype_called[] = "the genotype called.";
static char __pyx_k_the_template_length[] = "the template length";
static char __pyx_k_Bam_index_bin_number[] = "Bam index bin number";
static char __pyx_k_Length_of_query_name[] = "Length of query name";
static char __pyx_k_create_string_buffer[] = "create_string_buffer";
static char __pyx_k_start_out_of_range_i[] = "start out of range (%i)";
static char __pyx_k_Position_of_mate_pair[] = "Position of mate pair";
static char __pyx_k_could_not_open_file_s[] = "could not open file `%s`";
static char __pyx_k_getfilesystemencoding[] = "getfilesystemencoding";
static char __pyx_k_header_line_without_s[] = "header line without '@': '%s'";
static char __pyx_k_true_if_this_is_read1[] = "true if this is read1";
static char __pyx_k_true_if_this_is_read2[] = "true if this is read2";
static char __pyx_k_Count_of_cigar_entries[] = "Count of cigar entries";
static char __pyx_k_error_during_iteration[] = "error during iteration";
static char __pyx_k_Length_of_auxilary_data[] = "Length of auxilary data";
static char __pyx_k_current_sequence_length[] = "current sequence length.";
static char __pyx_k_Length_of_query_sequence[] = "Length of query sequence";
static char __pyx_k_the_position_of_the_mate[] = "the position of the mate";
static char __pyx_k_Mapped_position_on_contig[] = "Mapped position on contig";
static char __pyx_k_unknown_auxilliary_type_s[] = "unknown auxilliary type '%s'";
static char __pyx_k_Contig_index_for_mate_pair[] = "Contig index for mate pair";
static char __pyx_k_nucleotide_position_of_SNP[] = "nucleotide position of SNP.";
static char __pyx_k_tid_i_out_of_range_0_tid_i[] = "tid %i out of range 0<=tid<%i";
static char __pyx_k_unable_to_open_index_for_s[] = "unable to open index for `%s` ";
static char __pyx_k_0_based_leftmost_coordinate[] = "0-based leftmost coordinate";
static char __pyx_k_error_while_opening_index_s[] = "error while opening index `%s` ";
static char __pyx_k_invalid_file_opening_mode_s[] = "invalid file opening mode `%s`";
static char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file";
static char __pyx_k_callback_not_implemented_yet[] = "callback not implemented yet";
static char __pyx_k_no_index_available_for_fetch[] = "no index available for fetch";
static char __pyx_k_seek_no_available_in_streams[] = "seek no available in streams";
static char __pyx_k_true_if_the_mate_is_unmapped[] = "true if the mate is unmapped";
static char __pyx_k_no_index_available_for_pileup[] = "no index available for pileup";
static char __pyx_k_true_if_not_primary_alignment[] = "true if not primary alignment";
static char __pyx_k_home_andreas_devel_pysam_pysam[] = "/home/andreas/devel/pysam/pysam/csamfile.pyx";
static char __pyx_k_term_target_ID_DEPRECATED_from[] = "\n        :term:`target` ID\n\n        DEPRECATED from pysam-0.4 - use tid in the future.\n        The rname field caused a lot of confusion as it returns\n        the :term:`target` ID instead of the reference sequence\n        name.\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_term_target_ID_note_This_field[] = "\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_pileup_column_A_pileup_column[] = "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_a_list_of_start_and_end_positio[] = " a list of start and end positions of\n        aligned gapless blocks.\n\n        The start and end positions are in genomic \n        coordinates. \n      \n        Blocks are not normalized, i.e. two blocks \n        might be directly adjacent. This happens if\n        the two blocks are separated by an insertion \n        in the read.\n        ";
static char __pyx_k_fetch_called_on_bamfile_without[] = "fetch called on bamfile without index";
static char __pyx_k_file_does_not_have_valid_header[] = "file does not have valid header (mode='%s') - is it BAM format?";
static char __pyx_k_header_line_with_invalid_type_s[] = "header line with invalid type '%s': '%s'";
static char __pyx_k_incomplete_sequence_information[] = "incomplete sequence information in '%s'";
static char __pyx_k_inferred_read_length_from_CIGAR[] = "inferred read length from CIGAR string.\n\n        Returns 0 if CIGAR string is not present.\n        ";
static char __pyx_k_invalid_coordinates_start_i_end[] = "invalid coordinates: start (%i) > end (%i)";
static char __pyx_k_malformatted_header_no_in_field[] = "malformatted header: no ':' in field";
static char __pyx_k_number_of_reads_mapping_to_this[] = "number of reads mapping to this column.";
static char __pyx_k_quality_and_sequence_mismatch_i[] = "quality and sequence mismatch: %i != %i";
static char __pyx_k_the_chromosome_ID_as_is_defined[] = "the chromosome ID as is defined in the header";
static char __pyx_k_the_root_mean_square_rms_of_the[] = "the root mean square (rms) of the mapping quality of all reads involved in the call.";
static char __pyx_k_true_if_read_itself_is_unmapped[] = "true if read itself is unmapped";
static char __pyx_k_1_iff_the_base_on_the_padded_rea[] = "1 iff the base on the padded read is a deletion";
static char __pyx_k_Argument_must_be_string_bytes_or[] = "Argument must be string, bytes or unicode.";
static char __pyx_k_Argument_must_be_string_or_unico[] = "Argument must be string or unicode.";
static char __pyx_k_Invalid_clipping_in_CIGAR_string[] = "Invalid clipping in CIGAR string";
static char __pyx_k_PileupProxy_accessed_after_itera[] = "PileupProxy accessed after iterator finished";
static char __pyx_k_Samfile_mapped_only_available_in[] = "Samfile.mapped only available in bam files";
static char __pyx_k_This_class_cannot_be_instantiate[] = "This class cannot be instantiated from Python";
static char __pyx_k_Unsupported_value_type_in_set_op[] = "Unsupported value_type in set_option";
static char __pyx_k_a_class_pysam_AlignedRead_object[] = "a :class:`pysam.AlignedRead` object of the aligned read";
static char __pyx_k_a_list_of_aligned_read_and_refer[] = "a list of aligned read and reference positions.\n\n        Unaligned position are marked by None.\n        ";
static char __pyx_k_a_list_of_reference_positions_th[] = "a list of reference positions that this read aligns to.";
static char __pyx_k_aligned_length_of_the_read_on_th[] = "aligned length of the read on the reference genome.\n\n        This is equal to `aend - pos`. Returns None if not available.";
static char __pyx_k_aligned_portion_of_the_read_This[] = "aligned portion of the read.\n\n        This is a substring of :attr:`seq` that excludes flanking bases that were\n        :term:`soft clipped` (None if not present). It is equal to ``seq[qstart:qend]``.\n\n        In Python 3, this property is of type bytes. Assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        SAM/BAM files may include extra flanking bases that are\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_aligned_query_sequence_quality_v[] = "aligned query sequence quality values (None if not\n        present). These are the quality values that correspond to :attr:`query`, that is,\n        they exclude qualities of :term:`soft clipped` bases. This is equal to\n        ``qual[qstart:qend]``.\n\n        This property is read-only.\n\n        In Python 3, this property is of type bytes.";
static char __pyx_k_aligned_reference_position_of_th[] = "aligned reference position of the read on the reference genome.  \n        \n        aend points to one past the last aligned residue.\n        Returns None if not available.";
static char __pyx_k_can_not_iterate_over_samfile_wit[] = "can not iterate over samfile without header";
static char __pyx_k_can_only_IndexReads_on_bam_files[] = "can only IndexReads on bam files";
static char __pyx_k_can_t_guess_type_or_invalid_type[] = "can't guess type or invalid type code specified";
static char __pyx_k_could_not_open_file_mode_s_is_it[] = "could not open file (mode='%s') - is it SAM/BAM format?";
static char __pyx_k_coverage_or_read_depth_the_numbe[] = "coverage or read depth - the number of reads involved in the call.";
static char __pyx_k_either_supply_options_template_h[] = "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing";
static char __pyx_k_end_index_of_the_aligned_query_p[] = "end index of the aligned query portion of the sequence (0-based, exclusive)";
static char __pyx_k_fetch_called_for_htsfile_without[] = "fetch called for htsfile without header";
static char __pyx_k_fetching_by_region_is_not_availa[] = "fetching by region is not available for sam files";
static char __pyx_k_file_header_is_empty_mode_s_is_i[] = "file header is empty (mode='%s') - is it SAM/BAM format?";
static char __pyx_k_full_contents_of_the_term_sam_fi[] = "full contents of the :term:`sam file` header as a string.";
static char __pyx_k_header_information_within_the_te[] = "header information within the :term:`sam file`. The records and fields are returned as\n        a two-level dictionary.\n        ";
static char __pyx_k_indel_length_0_for_no_indel_posi[] = "indel length; 0 for no indel, positive for ins and negative for del";
static char __pyx_k_integer_i_out_of_range_of_BAM_SA[] = "integer %i out of range of BAM/SAM specification";
static char __pyx_k_invalid_type_for_record_s_s_expe[] = "invalid type for record %s: %s, expected %s";
static char __pyx_k_length_of_the_aligned_query_sequ[] = "length of the aligned query sequence.\n\n        This is equal to :attr:`qend` - :attr:`qstart`";
static char __pyx_k_length_of_the_read_This_includes[] = "length of the read. This includes soft-clipped bases\n        and is equal to ``len(seq)``.\n\n        This property is read-only.\n\n        Returns 0 if not available.";
static char __pyx_k_list_of_reads_class_pysam_Pileup[] = "list of reads (:class:`pysam.PileupRead`) aligned to this column";
static char __pyx_k_mapping_information_not_recorded[] = "mapping information not recorded in index or index not available";
static char __pyx_k_multiple_s_lines_are_not_permitt[] = "multiple '%s' lines are not permitted";
static char __pyx_k_no_index_available_for_iteration[] = "no index available for iteration";
static char __pyx_k_number_of_term_filename_associat[] = "number of :term:`filename` associated with this object.";
static char __pyx_k_number_of_term_reference_sequenc[] = "number of :term:`reference` sequences in the file.";
static char __pyx_k_pileup_of_samfiles_not_implement[] = "pileup of samfiles not implemented yet";
static char __pyx_k_position_of_the_read_base_at_the[] = "position of the read base at the pileup site, 0-based";
static char __pyx_k_read_sequence_base_qualities_inc[] = "read sequence base qualities, including :term:`soft\n        clipped` bases (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        Note that to set quality scores the sequence has to be set\n        previously as this will determine the permitted length of\n        the quality score array.\n\n        This method raises a ValueError if the length of the \n        quality scores and the sequence are not the same.\n        ";
static char __pyx_k_read_sequence_bases_including_te[] = "read sequence bases, including :term:`soft clipped` bases \n        (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a\n        unicode string to it consisting of ASCII characters only will\n        work, but is inefficient.\n\n        Note that assigning to seq will invalidate any quality scores.\n        Thus, to in-place edit the sequence and quality scores, copies of\n        the quality scores need to be taken. Consider trimming for example::\n\n           q = read.qual\n           read.seq = read.seq[5:10]\n           read.qual = q[5:10]\n\n        The sequence is returned as it is stored in the BAM file. Some mappers\n        might have stored a reverse complement of the original read \n        sequence.\n        ";
static char __pyx_k_reference_base_at_pos_N_if_no_re[] = "reference base at pos. ``N`` if no reference sequence supplied.";
static char __pyx_k_reference_sequence_for_s_tid_i_n[] = "reference sequence for '%s' (tid=%i) not found";
static char __pyx_k_seek_only_available_in_bam_files[] = "seek only available in bam files";
static char __pyx_k_start_index_of_the_aligned_query[] = "start index of the aligned query portion of the sequence (0-based, inclusive).\n\n        This the index of the first base in :attr:`seq` that is not soft-clipped.\n        ";
static char __pyx_k_the_genotype_quality_Phred_scale[] = "the genotype quality (Phred-scaled).";
static char __pyx_k_the_insert_size_deprecated_use_t[] = "the insert size\n        deprecated: use tlen instead";
static char __pyx_k_the_position_of_the_mate_depreca[] = "the position of the mate\n        deprecated, use PNEXT instead.";
static char __pyx_k_the_query_name_None_if_not_prese[] = "the query name (None if not present)";
static char __pyx_k_the_snp_quality_Phred_scaled_pro[] = "the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.";
static char __pyx_k_the_tags_in_the_AUX_field_This_p[] = "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        This method will happily write the same tag\n        multiple times.\n        ";
static char __pyx_k_the_term_cigar_alignment_The_ali[] = "the :term:`cigar` alignment. The alignment\n        is returned as a list of tuples of (operation, length). \n\n        If the alignment is not present, an empty list is\n        returned.\n\n        The operations are:\n\n        +-----+--------------+-----+\n        |M    |BAM_CMATCH    |0    |\n        +-----+--------------+-----+\n        |I    |BAM_CINS      |1    |\n        +-----+--------------+-----+\n        |D    |BAM_CDEL      |2    |\n        +-----+--------------+-----+\n        |N    |BAM_CREF_SKIP |3    |\n        +-----+--------------+-----+\n        |S    |BAM_CSOFT_CLIP|4    |\n        +-----+--------------+-----+\n        |H    |BAM_CHARD_CLIP|5    |\n        +-----+--------------+-----+\n        |P    |BAM_CPAD      |6    |\n        +-----+--------------+-----+\n        |=    |BAM_CEQUAL    |7    |\n        +-----+--------------+-----+\n        |X    |BAM_CDIFF     |8    |\n        +-----+--------------+-----+\n\n        .. note::\n            The output is a list of (operation, length) tuples, such as\n            ``[(0, 30)]``.\n            This is different from the SAM specification and\n            the :attr:`cigarstring` property, which uses a\n            (length, operation) order, for example: ``30M``.\n\n        To unset the cigar property, assign an empty list\n        or None.\n        ";
static char __pyx_k_the_term_cigar_alignment_as_a_st[] = "the :term:`cigar` alignment as a string.\n        \n        The cigar string is a string of alternating integers\n        and characters denoting the length and the type of\n        an operation.\n\n        .. note::\n            The order length,operation is specified in the\n            SAM format. It is different from the order of\n            the :attr:`cigar` property.\n\n        Returns the empty string if not present.\n\n        To unset the cigarstring, assign None or the\n        empty string.\n        ";
static char __pyx_k_the_term_reference_id_of_the_mat[] = "the :term:`reference` id of the mate\n        deprecated, use RNEXT instead.\n        ";
static char __pyx_k_total_number_of_mapped_alignment[] = "total number of mapped alignments in file.\n        ";
static char __pyx_k_total_number_of_reads_without_co[] = "total number of reads without coordinates\n        ";
static char __pyx_k_total_number_of_unmapped_reads_i[] = "total number of unmapped reads in file.\n        ";
static char __pyx_k_true_if_optical_or_PCR_duplicate[] = "true if optical or PCR duplicate";
static char __pyx_k_true_if_read_is_mapped_in_a_prop[] = "true if read is mapped in a proper pair";
static char __pyx_k_true_if_read_is_mapped_to_revers[] = "true if read is mapped to reverse strand";
static char __pyx_k_true_if_read_is_paired_in_sequen[] = "true if read is paired in sequencing";
static char __pyx_k_true_is_read_is_mapped_to_revers[] = "true is read is mapped to reverse strand";
static char __pyx_k_tuple_of_the_lengths_of_the_term[] = "tuple of the lengths of the :term:`reference` sequences. The lengths are in the same order as\n        :attr:`pysam.Samfile.references`\n        ";
static char __pyx_k_tuple_with_the_names_of_term_ref[] = "tuple with the names of :term:`reference` sequences.";
static char __pyx_k_unequal_names_and_lengths_of_ref[] = "unequal names and lengths of reference sequences";
static char __pyx_k_unknown_field_code_s_in_record_s[] = "unknown field code '%s' in record '%s'";
static char __pyx_k_unknown_stepper_option_s_in_Iter[] = "unknown stepper option `%s` in IteratorColumn";
static char __pyx_k_file_does_not_have_valid_header_2[] = "file does not have valid header (mode='%s') - is it SAM format?";
static char __pyx_k_the_term_reference_id_of_the_mat_2[] = "the :term:`reference` id of the mate ";
static PyObject *__pyx_kp_s_2scB;
static PyObject *__pyx_kp_s_2scH;
static PyObject *__pyx_kp_s_2scI;
static PyObject *__pyx_kp_s_2sc_is;
static PyObject *__pyx_kp_s_2scb;
static PyObject *__pyx_kp_s_2scc;
static PyObject *__pyx_kp_s_2sccI_i_s;
static PyObject *__pyx_kp_s_2scf;
static PyObject *__pyx_kp_s_2sch;
static PyObject *__pyx_kp_s_2sci;
static PyObject *__pyx_kp_s_30s_10s_s;
static PyObject *__pyx_n_s_A;
static PyObject *__pyx_n_s_AS;
static PyObject *__pyx_kp_s_A_pileup_column_A_pileup_column;
static PyObject *__pyx_n_s_AlignedRead;
static PyObject *__pyx_kp_u_Argument_must_be_string_bytes_or;
static PyObject *__pyx_kp_u_Argument_must_be_string_or_unico;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_n_s_B;
static PyObject *__pyx_kp_s_Bam_index_bin_number;
static PyObject *__pyx_kp_s_Binary_flag;
static PyObject *__pyx_n_s_C;
static PyObject *__pyx_n_s_CIGAR2CODE;
static PyObject *__pyx_n_s_CIGAR_REGEX;
static PyObject *__pyx_n_s_CL;
static PyObject *__pyx_n_s_CN;
static PyObject *__pyx_n_s_CO;
static PyObject *__pyx_kp_s_Cigar_entries;
static PyObject *__pyx_kp_s_Contig_index;
static PyObject *__pyx_kp_s_Contig_index_for_mate_pair;
static PyObject *__pyx_kp_s_Count_of_cigar_entries;
static PyObject *__pyx_n_s_D;
static PyObject *__pyx_n_s_DS;
static PyObject *__pyx_n_s_DT;
static PyObject *__pyx_n_s_F;
static PyObject *__pyx_n_s_FO;
static PyObject *__pyx_n_s_GO;
static PyObject *__pyx_n_s_H;
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_IS_PYTHON3;
static PyObject *__pyx_kp_s_I_O_operation_on_closed_file;
static PyObject *__pyx_n_s_IndexedReads;
static PyObject *__pyx_kp_s_Insert_size;
static PyObject *__pyx_kp_s_Invalid_tag_s;
static PyObject *__pyx_n_s_IteratorColumn;
static PyObject *__pyx_n_s_IteratorRow;
static PyObject *__pyx_n_s_KS;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_n_s_LB;
static PyObject *__pyx_n_s_LN;
static PyObject *__pyx_kp_s_Length_of_auxilary_data;
static PyObject *__pyx_kp_s_Length_of_query_name;
static PyObject *__pyx_kp_s_Length_of_query_sequence;
static PyObject *__pyx_n_s_M5;
static PyObject *__pyx_kp_s_Mapped_position_on_contig;
static PyObject *__pyx_kp_s_Mapping_quality;
static PyObject *__pyx_kp_s_Maximum_data_length;
static PyObject *__pyx_n_s_NotImplementedError;
static PyObject *__pyx_n_s_OSError;
static PyObject *__pyx_n_s_OverflowError;
static PyObject *__pyx_n_s_PG;
static PyObject *__pyx_n_s_PI;
static PyObject *__pyx_n_s_PL;
static PyObject *__pyx_n_s_PN;
static PyObject *__pyx_n_s_PP;
static PyObject *__pyx_n_s_PU;
static PyObject *__pyx_n_s_PileupColumn;
static PyObject *__pyx_n_s_PileupColumn___str;
static PyObject *__pyx_n_s_PileupProxy;
static PyObject *__pyx_kp_s_PileupProxy_accessed_after_itera;
static PyObject *__pyx_n_s_PileupRead;
static PyObject *__pyx_kp_s_Position_of_mate_pair;
static PyObject *__pyx_kp_s_Quality_scores;
static PyObject *__pyx_kp_s_Query_name;
static PyObject *__pyx_kp_s_Query_sequence;
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_kp_s_SQ_SN_s_LN_s;
static PyObject *__pyx_n_s_Samfile;
static PyObject *__pyx_kp_s_Samfile_mapped_only_available_in;
static PyObject *__pyx_n_s_StopIteration;
static PyObject *__pyx_kp_s_This_class_cannot_be_instantiate;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_UR;
static PyObject *__pyx_kp_s_Unsupported_value_type_in_set_op;
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_Zidf;
static PyObject *__pyx_kp_s__14;
static PyObject *__pyx_kp_s__3;
static PyObject *__pyx_kp_s__4;
static PyObject *__pyx_kp_s__41;
static PyObject *__pyx_kp_s__47;
static PyObject *__pyx_kp_b__6;
static PyObject *__pyx_kp_s__76;
static PyObject *__pyx_kp_s__79;
static PyObject *__pyx_kp_s__80;
static PyObject *__pyx_kp_s__9;
static PyObject *__pyx_n_s_add_sq_text;
static PyObject *__pyx_n_s_alignment;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_all_2;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_ascii;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_kp_b_bai;
static PyObject *__pyx_n_s_beg;
static PyObject *__pyx_n_s_bin;
static PyObject *__pyx_n_s_bqual;
static PyObject *__pyx_n_s_buildLine;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_kp_s_c_2;
static PyObject *__pyx_n_s_calcsize;
static PyObject *__pyx_n_s_callback;
static PyObject *__pyx_kp_s_callback_not_implemented_yet;
static PyObject *__pyx_kp_s_can_not_iterate_over_samfile_wit;
static PyObject *__pyx_kp_s_can_only_IndexReads_on_bam_files;
static PyObject *__pyx_kp_s_can_t_guess_type_or_invalid_type;
static PyObject *__pyx_n_s_checkIndex;
static PyObject *__pyx_n_s_check_header;
static PyObject *__pyx_n_s_check_sq;
static PyObject *__pyx_n_s_chr;
static PyObject *__pyx_n_s_cigar;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_compile;
static PyObject *__pyx_n_s_consensus_quality;
static PyObject *__pyx_kp_s_could_not_open_file_mode_s_is_it;
static PyObject *__pyx_kp_s_could_not_open_file_s;
static PyObject *__pyx_n_s_coverage;
static PyObject *__pyx_n_s_create_string_buffer;
static PyObject *__pyx_n_s_ctypes;
static PyObject *__pyx_n_s_d;
static PyObject *__pyx_kp_s_d_MIDNSHP_X;
static PyObject *__pyx_n_s_decode;
static PyObject *__pyx_n_s_defaultdict;
static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_kp_s_either_supply_options_template_h;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_kp_s_end_out_of_range_i;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_kp_s_error_during_iteration;
static PyObject *__pyx_kp_s_error_while_opening_index_s;
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_extend;
static PyObject *__pyx_n_s_f;
static PyObject *__pyx_n_s_fastafile;
static PyObject *__pyx_n_s_fetch;
static PyObject *__pyx_kp_s_fetch_called_for_htsfile_without;
static PyObject *__pyx_kp_s_fetch_called_on_bamfile_without;
static PyObject *__pyx_kp_s_fetching_by_region_is_not_availa;
static PyObject *__pyx_n_s_fields;
static PyObject *__pyx_kp_s_file_does_not_have_valid_header;
static PyObject *__pyx_kp_s_file_does_not_have_valid_header_2;
static PyObject *__pyx_kp_s_file_header_is_empty_mode_s_is_i;
static PyObject *__pyx_kp_s_file_s_not_found;
static PyObject *__pyx_n_s_filename;
static PyObject *__pyx_n_s_findall;
static PyObject *__pyx_n_s_flag;
static PyObject *__pyx_n_s_fmts;
static PyObject *__pyx_kp_b_ftp;
static PyObject *__pyx_n_s_genotype;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_getattribute;
static PyObject *__pyx_n_s_getdefaultencoding;
static PyObject *__pyx_n_s_getfilesystemencoding;
static PyObject *__pyx_n_s_gettid;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_hasIndex;
static PyObject *__pyx_n_s_header;
static PyObject *__pyx_kp_s_header_line_with_invalid_type_s;
static PyObject *__pyx_kp_s_header_line_without_s;
static PyObject *__pyx_kp_s_home_andreas_devel_pysam_pysam;
static PyObject *__pyx_kp_b_http;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_kp_s_i_c;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_kp_s_incomplete_sequence_information;
static PyObject *__pyx_n_s_indel;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_kp_s_integer_i_out_of_range_of_BAM_SA;
static PyObject *__pyx_kp_s_invalid_coordinates_start_i_end;
static PyObject *__pyx_kp_s_invalid_file_opening_mode_s;
static PyObject *__pyx_kp_s_invalid_reference_s;
static PyObject *__pyx_kp_s_invalid_type_for_record_s_s_expe;
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_isize;
static PyObject *__pyx_n_s_islower;
static PyObject *__pyx_n_s_isupper;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_itertools;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_l_data;
static PyObject *__pyx_n_s_l_qname;
static PyObject *__pyx_n_s_l_qseq;
static PyObject *__pyx_n_s_lengths;
static PyObject *__pyx_n_s_level;
static PyObject *__pyx_n_s_m_data;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_kp_s_malformatted_header_no_in_field;
static PyObject *__pyx_n_s_map;
static PyObject *__pyx_kp_s_mapping_information_not_recorded;
static PyObject *__pyx_n_s_mapping_quality;
static PyObject *__pyx_n_s_mapq;
static PyObject *__pyx_kp_s_mate_not_found;
static PyObject *__pyx_kp_s_mate_s_is_unmapped;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_max_depth;
static PyObject *__pyx_n_s_metaclass;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_mpos;
static PyObject *__pyx_n_s_mrnm;
static PyObject *__pyx_n_s_mtid;
static PyObject *__pyx_kp_s_multiple_s_lines_are_not_permitt;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_n_cigar;
static PyObject *__pyx_n_s_nextiter;
static PyObject *__pyx_kp_s_no_index_available_for_fetch;
static PyObject *__pyx_kp_s_no_index_available_for_iteration;
static PyObject *__pyx_kp_s_no_index_available_for_pileup;
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_ord;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_pack_into;
static PyObject *__pyx_n_s_parseRegion;
static PyObject *__pyx_n_s_path;
static PyObject *__pyx_kp_s_pileup_of_samfiles_not_implement;
static PyObject *__pyx_n_s_pileups;
static PyObject *__pyx_n_s_platform;
static PyObject *__pyx_n_s_port;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_positions;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_pysam_csamfile;
static PyObject *__pyx_n_s_pytag;
static PyObject *__pyx_n_s_pyx_vtable;
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_kp_s_quality_and_sequence_mismatch_i;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_rU;
static PyObject *__pyx_n_s_raw;
static PyObject *__pyx_n_s_rb;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_kp_s_read_s_is_unpaired;
static PyObject *__pyx_kp_s_read_s_not_found;
static PyObject *__pyx_n_s_record;
static PyObject *__pyx_n_s_reference;
static PyObject *__pyx_n_s_reference_base;
static PyObject *__pyx_kp_s_reference_sequence_for_s_tid_i_n;
static PyObject *__pyx_n_s_referencelengths;
static PyObject *__pyx_n_s_referencenames;
static PyObject *__pyx_n_s_references;
static PyObject *__pyx_n_s_region;
static PyObject *__pyx_n_s_reopen;
static PyObject *__pyx_n_s_replace;
static PyObject *__pyx_n_s_rlen;
static PyObject *__pyx_n_s_rname;
static PyObject *__pyx_kp_s_s;
static PyObject *__pyx_n_s_s_2;
static PyObject *__pyx_kp_s_s_s;
static PyObject *__pyx_n_s_samfile;
static PyObject *__pyx_n_s_samtools;
static PyObject *__pyx_n_s_seek;
static PyObject *__pyx_kp_s_seek_no_available_in_streams;
static PyObject *__pyx_kp_s_seek_only_available_in_bam_files;
static PyObject *__pyx_n_s_self;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_seq;
static PyObject *__pyx_n_s_setTag;
static PyObject *__pyx_n_s_snp_quality;
static PyObject *__pyx_n_s_sorted;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_kp_s_start_out_of_range_i;
static PyObject *__pyx_n_s_startswith;
static PyObject *__pyx_n_s_stepper;
static PyObject *__pyx_n_s_str;
static PyObject *__pyx_n_s_strip;
static PyObject *__pyx_n_s_struct;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_tag;
static PyObject *__pyx_kp_s_tag_s_not_present;
static PyObject *__pyx_n_s_tags;
static PyObject *__pyx_n_s_tempfile;
static PyObject *__pyx_n_s_template;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_text;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_tid;
static PyObject *__pyx_kp_s_tid_i_out_of_range_0_tid_i;
static PyObject *__pyx_n_s_traceback;
static PyObject *__pyx_n_s_truncate;
static PyObject *__pyx_n_s_types;
static PyObject *__pyx_kp_s_unable_to_open_index_for_s;
static PyObject *__pyx_kp_s_unequal_names_and_lengths_of_ref;
static PyObject *__pyx_kp_s_unknown_auxilliary_type_s;
static PyObject *__pyx_kp_s_unknown_field_code_s_in_record_s;
static PyObject *__pyx_kp_s_unknown_stepper_option_s_in_Iter;
static PyObject *__pyx_kp_s_unknown_type_s;
static PyObject *__pyx_n_s_until_eof;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_s_value_type;
static PyObject *__pyx_n_s_version_info;
static PyObject *__pyx_n_s_w;
static PyObject *__pyx_n_s_warn;
static PyObject *__pyx_n_s_warnings;
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_zip;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_255;
static PyObject *__pyx_int_8000;
static PyObject *__pyx_int_65535;
static PyObject *__pyx_int_536870912;
static PyObject *__pyx_int_4294967295;
static PyObject *__pyx_int_neg_4;
static PyObject *__pyx_int_neg_127;
static PyObject *__pyx_int_neg_32767;
static PyObject *__pyx_int_neg_2147483648;
static int __pyx_k__57;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_slice__10;
static PyObject *__pyx_slice__43;
static PyObject *__pyx_slice__45;
static PyObject *__pyx_slice__46;
static PyObject *__pyx_slice__61;
static PyObject *__pyx_slice__65;
static PyObject *__pyx_slice__70;
static PyObject *__pyx_slice__74;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__60;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__64;
static PyObject *__pyx_tuple__66;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__68;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__72;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__75;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__78;
static PyObject *__pyx_tuple__81;
static PyObject *__pyx_tuple__82;
static PyObject *__pyx_tuple__83;
static PyObject *__pyx_tuple__84;
static PyObject *__pyx_tuple__85;
static PyObject *__pyx_tuple__87;
static PyObject *__pyx_tuple__88;
static PyObject *__pyx_tuple__89;
static PyObject *__pyx_tuple__90;
static PyObject *__pyx_tuple__91;
static PyObject *__pyx_codeobj__86;
static PyObject *__pyx_gb_5pysam_8csamfile_2generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysam/csamfile.pyx":105
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 */

static PyObject *__pyx_pf_5pysam_8csamfile_genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *)__pyx_tp_new_5pysam_8csamfile___pyx_scope_struct__genexpr(__pyx_ptype_5pysam_8csamfile___pyx_scope_struct__genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 105);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_8csamfile_2generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5pysam_8csamfile_2generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *(*__pyx_t_4)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_1 = __pyx_int_0;
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_8csamfile_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    {
      __pyx_t_2 = __pyx_t_4(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_y);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_y, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
    PyList_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_t_3);
    __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_generator->resume_label = -1;
  __Pyx_Generator_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return NULL;
}
static PyObject *__pyx_gb_5pysam_8csamfile_5generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysam/csamfile.pyx":107
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
 * 
 */

static PyObject *__pyx_pf_5pysam_8csamfile_3genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *)__pyx_tp_new_5pysam_8csamfile___pyx_scope_struct_1_genexpr(__pyx_ptype_5pysam_8csamfile___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 107);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_8csamfile_5generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5pysam_8csamfile_5generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_1 = __pyx_int_0;
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_8csamfile_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    {
      __pyx_t_2 = __pyx_t_4(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_y);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_y, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_1 = __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 = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
    PyList_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
    __pyx_t_5 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_t_3);
    __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  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_5);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_generator->resume_label = -1;
  __Pyx_Generator_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return NULL;
}

/* "pysam/csamfile.pyx":28
 * ########################################################################
 * IS_PYTHON3 = PY_MAJOR_VERSION >= 3
 * cdef from_string_and_size(char* s, size_t length):             # <<<<<<<<<<<<<<
 *     if PY_MAJOR_VERSION < 3:
 *         return s[:length]
 */

static PyObject *__pyx_f_5pysam_8csamfile_from_string_and_size(char *__pyx_v_s, size_t __pyx_v_length) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("from_string_and_size", 0);
  __Pyx_TraceCall("from_string_and_size", __pyx_f[0], 28);

  /* "pysam/csamfile.pyx":29
 * IS_PYTHON3 = PY_MAJOR_VERSION >= 3
 * cdef from_string_and_size(char* s, size_t length):
 *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
 *         return s[:length]
 *     else:
 */
  __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":30
 * cdef from_string_and_size(char* s, size_t length):
 *     if PY_MAJOR_VERSION < 3:
 *         return s[:length]             # <<<<<<<<<<<<<<
 *     else:
 *         return s[:length].decode("ascii")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":32
 *         return s[:length]
 *     else:
 *         return s[:length].decode("ascii")             # <<<<<<<<<<<<<<
 * 
 * # filename encoding (copied from lxml.etree.pyx)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_s, 0, __pyx_v_length, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":28
 * ########################################################################
 * IS_PYTHON3 = PY_MAJOR_VERSION >= 3
 * cdef from_string_and_size(char* s, size_t length):             # <<<<<<<<<<<<<<
 *     if PY_MAJOR_VERSION < 3:
 *         return s[:length]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.from_string_and_size", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":45
 * #_C_FILENAME_ENCODING = <char*>_FILENAME_ENCODING
 * 
 * cdef bytes _encodeFilename(object filename):             # <<<<<<<<<<<<<<
 *     """Make sure a filename is 8-bit encoded (or None)."""
 *     if filename is None:
 */

static PyObject *__pyx_f_5pysam_8csamfile__encodeFilename(PyObject *__pyx_v_filename) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_encodeFilename", 0);
  __Pyx_TraceCall("_encodeFilename", __pyx_f[0], 45);

  /* "pysam/csamfile.pyx":47
 * cdef bytes _encodeFilename(object filename):
 *     """Make sure a filename is 8-bit encoded (or None)."""
 *     if filename is None:             # <<<<<<<<<<<<<<
 *         return None
 *     elif PyBytes_Check(filename):
 */
  __pyx_t_1 = (__pyx_v_filename == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":48
 *     """Make sure a filename is 8-bit encoded (or None)."""
 *     if filename is None:
 *         return None             # <<<<<<<<<<<<<<
 *     elif PyBytes_Check(filename):
 *         return filename
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = ((PyObject*)Py_None);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":49
 *     if filename is None:
 *         return None
 *     elif PyBytes_Check(filename):             # <<<<<<<<<<<<<<
 *         return filename
 *     elif PyUnicode_Check(filename):
 */
  __pyx_t_2 = (PyBytes_Check(__pyx_v_filename) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":50
 *         return None
 *     elif PyBytes_Check(filename):
 *         return filename             # <<<<<<<<<<<<<<
 *     elif PyUnicode_Check(filename):
 *         return filename.encode(_FILENAME_ENCODING)
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_filename)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_INCREF(__pyx_v_filename);
    __pyx_r = ((PyObject*)__pyx_v_filename);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":51
 *     elif PyBytes_Check(filename):
 *         return filename
 *     elif PyUnicode_Check(filename):             # <<<<<<<<<<<<<<
 *         return filename.encode(_FILENAME_ENCODING)
 *     else:
 */
  __pyx_t_2 = (PyUnicode_Check(__pyx_v_filename) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":52
 *         return filename
 *     elif PyUnicode_Check(filename):
 *         return filename.encode(_FILENAME_ENCODING)             # <<<<<<<<<<<<<<
 *     else:
 *         raise TypeError, u"Argument must be string or unicode."
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __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 = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_5pysam_8csamfile__FILENAME_ENCODING);
    __Pyx_GIVEREF(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":54
 *         return filename.encode(_FILENAME_ENCODING)
 *     else:
 *         raise TypeError, u"Argument must be string or unicode."             # <<<<<<<<<<<<<<
 * 
 * cdef bytes _forceBytes(object s):
 */
    __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_u_Argument_must_be_string_or_unico, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":45
 * #_C_FILENAME_ENCODING = <char*>_FILENAME_ENCODING
 * 
 * cdef bytes _encodeFilename(object filename):             # <<<<<<<<<<<<<<
 *     """Make sure a filename is 8-bit encoded (or None)."""
 *     if filename is None:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.csamfile._encodeFilename", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":56
 *         raise TypeError, u"Argument must be string or unicode."
 * 
 * cdef bytes _forceBytes(object s):             # <<<<<<<<<<<<<<
 *     u"""convert string or unicode object to bytes, assuming ascii encoding.
 *     """
 */

static PyObject *__pyx_f_5pysam_8csamfile__forceBytes(PyObject *__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_forceBytes", 0);
  __Pyx_TraceCall("_forceBytes", __pyx_f[0], 56);

  /* "pysam/csamfile.pyx":59
 *     u"""convert string or unicode object to bytes, assuming ascii encoding.
 *     """
 *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
 *         return s
 *     elif s is None:
 */
  __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":60
 *     """
 *     if PY_MAJOR_VERSION < 3:
 *         return s             # <<<<<<<<<<<<<<
 *     elif s is None:
 *         return None
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_INCREF(__pyx_v_s);
    __pyx_r = ((PyObject*)__pyx_v_s);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":61
 *     if PY_MAJOR_VERSION < 3:
 *         return s
 *     elif s is None:             # <<<<<<<<<<<<<<
 *         return None
 *     elif PyBytes_Check(s):
 */
  __pyx_t_1 = (__pyx_v_s == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":62
 *         return s
 *     elif s is None:
 *         return None             # <<<<<<<<<<<<<<
 *     elif PyBytes_Check(s):
 *         return s
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = ((PyObject*)Py_None);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":63
 *     elif s is None:
 *         return None
 *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
 *         return s
 *     elif PyUnicode_Check(s):
 */
  __pyx_t_2 = (PyBytes_Check(__pyx_v_s) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":64
 *         return None
 *     elif PyBytes_Check(s):
 *         return s             # <<<<<<<<<<<<<<
 *     elif PyUnicode_Check(s):
 *         return s.encode('ascii')
 */
    __Pyx_XDECREF(__pyx_r);
    if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_s)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_INCREF(__pyx_v_s);
    __pyx_r = ((PyObject*)__pyx_v_s);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":65
 *     elif PyBytes_Check(s):
 *         return s
 *     elif PyUnicode_Check(s):             # <<<<<<<<<<<<<<
 *         return s.encode('ascii')
 *     else:
 */
  __pyx_t_2 = (PyUnicode_Check(__pyx_v_s) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":66
 *         return s
 *     elif PyUnicode_Check(s):
 *         return s.encode('ascii')             # <<<<<<<<<<<<<<
 *     else:
 *         raise TypeError, u"Argument must be string, bytes or unicode."
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":68
 *         return s.encode('ascii')
 *     else:
 *         raise TypeError, u"Argument must be string, bytes or unicode."             # <<<<<<<<<<<<<<
 * 
 * cdef inline bytes _forceCmdlineBytes(object s):
 */
    __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_u_Argument_must_be_string_bytes_or, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":56
 *         raise TypeError, u"Argument must be string or unicode."
 * 
 * cdef bytes _forceBytes(object s):             # <<<<<<<<<<<<<<
 *     u"""convert string or unicode object to bytes, assuming ascii encoding.
 *     """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile._forceBytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":70
 *         raise TypeError, u"Argument must be string, bytes or unicode."
 * 
 * cdef inline bytes _forceCmdlineBytes(object s):             # <<<<<<<<<<<<<<
 *     return _forceBytes(s)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_8csamfile__forceCmdlineBytes(PyObject *__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_forceCmdlineBytes", 0);
  __Pyx_TraceCall("_forceCmdlineBytes", __pyx_f[0], 70);

  /* "pysam/csamfile.pyx":71
 * 
 * cdef inline bytes _forceCmdlineBytes(object s):
 *     return _forceBytes(s)             # <<<<<<<<<<<<<<
 * 
 * cdef _charptr_to_str(char* s):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":70
 *         raise TypeError, u"Argument must be string, bytes or unicode."
 * 
 * cdef inline bytes _forceCmdlineBytes(object s):             # <<<<<<<<<<<<<<
 *     return _forceBytes(s)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile._forceCmdlineBytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":73
 *     return _forceBytes(s)
 * 
 * cdef _charptr_to_str(char* s):             # <<<<<<<<<<<<<<
 *     if PY_MAJOR_VERSION < 3:
 *         return s
 */

static PyObject *__pyx_f_5pysam_8csamfile__charptr_to_str(char *__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_charptr_to_str", 0);
  __Pyx_TraceCall("_charptr_to_str", __pyx_f[0], 73);

  /* "pysam/csamfile.pyx":74
 * 
 * cdef _charptr_to_str(char* s):
 *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
 *         return s
 *     else:
 */
  __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":75
 * cdef _charptr_to_str(char* s):
 *     if PY_MAJOR_VERSION < 3:
 *         return s             # <<<<<<<<<<<<<<
 *     else:
 *         return s.decode("ascii")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":77
 *         return s
 *     else:
 *         return s.decode("ascii")             # <<<<<<<<<<<<<<
 * 
 * cdef _forceStr(object s):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_s, 0, strlen(__pyx_v_s), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":73
 *     return _forceBytes(s)
 * 
 * cdef _charptr_to_str(char* s):             # <<<<<<<<<<<<<<
 *     if PY_MAJOR_VERSION < 3:
 *         return s
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile._charptr_to_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":79
 *         return s.decode("ascii")
 * 
 * cdef _forceStr(object s):             # <<<<<<<<<<<<<<
 *     """Return s converted to str type of current Python
 *     (bytes in Py2, unicode in Py3)"""
 */

static PyObject *__pyx_f_5pysam_8csamfile__forceStr(PyObject *__pyx_v_s) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_forceStr", 0);
  __Pyx_TraceCall("_forceStr", __pyx_f[0], 79);

  /* "pysam/csamfile.pyx":82
 *     """Return s converted to str type of current Python
 *     (bytes in Py2, unicode in Py3)"""
 *     if s is None:             # <<<<<<<<<<<<<<
 *         return None
 *     if PY_MAJOR_VERSION < 3:
 */
  __pyx_t_1 = (__pyx_v_s == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":83
 *     (bytes in Py2, unicode in Py3)"""
 *     if s is None:
 *         return None             # <<<<<<<<<<<<<<
 *     if PY_MAJOR_VERSION < 3:
 *         return s
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":84
 *     if s is None:
 *         return None
 *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
 *         return s
 *     elif PyBytes_Check(s):
 */
  __pyx_t_2 = ((PY_MAJOR_VERSION < 3) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":85
 *         return None
 *     if PY_MAJOR_VERSION < 3:
 *         return s             # <<<<<<<<<<<<<<
 *     elif PyBytes_Check(s):
 *         return s.decode('ascii')
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_s);
    __pyx_r = __pyx_v_s;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":86
 *     if PY_MAJOR_VERSION < 3:
 *         return s
 *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
 *         return s.decode('ascii')
 *     else:
 */
  __pyx_t_2 = (PyBytes_Check(__pyx_v_s) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":87
 *         return s
 *     elif PyBytes_Check(s):
 *         return s.decode('ascii')             # <<<<<<<<<<<<<<
 *     else:
 *         # assume unicode
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_decode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":90
 *     else:
 *         # assume unicode
 *         return s             # <<<<<<<<<<<<<<
 * 
 * ########################################################################
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_s);
    __pyx_r = __pyx_v_s;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":79
 *         return s.decode("ascii")
 * 
 * cdef _forceStr(object s):             # <<<<<<<<<<<<<<
 *     """Return s converted to str type of current Python
 *     (bytes in Py2, unicode in Py3)"""
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile._forceStr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":120
 * #####################################################################
 * cdef class AlignedRead
 * cdef makeAlignedRead(bam1_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedRead.'''
 *     # note that the following does not call __init__
 */

static PyObject *__pyx_f_5pysam_8csamfile_makeAlignedRead(bam1_t *__pyx_v_src) {
  struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("makeAlignedRead", 0);
  __Pyx_TraceCall("makeAlignedRead", __pyx_f[0], 120);

  /* "pysam/csamfile.pyx":123
 *     '''enter src into AlignedRead.'''
 *     # note that the following does not call __init__
 *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
 *     dest._delegate = bam_dup1(src)
 *     return dest
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_8csamfile_AlignedRead(((PyTypeObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_AlignedRead)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_8csamfile_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":124
 *     # note that the following does not call __init__
 *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
 *     dest._delegate = bam_dup1(src)             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src);

  /* "pysam/csamfile.pyx":125
 *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
 *     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;

  /* "pysam/csamfile.pyx":120
 * #####################################################################
 * cdef class AlignedRead
 * cdef makeAlignedRead(bam1_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedRead.'''
 *     # note that the following does not call __init__
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.makeAlignedRead", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":128
 * 
 * cdef class PileupProxy
 * cdef makePileupProxy(bam_pileup1_t ** plp, int tid, int pos, int n):             # <<<<<<<<<<<<<<
 *     # note that the following does not call __init__
 *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
 */

static PyObject *__pyx_f_5pysam_8csamfile_makePileupProxy(bam_pileup1_t **__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n) {
  struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("makePileupProxy", 0);
  __Pyx_TraceCall("makePileupProxy", __pyx_f[0], 128);

  /* "pysam/csamfile.pyx":130
 * cdef makePileupProxy(bam_pileup1_t ** plp, int tid, int pos, int n):
 *     # note that the following does not call __init__
 *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)             # <<<<<<<<<<<<<<
 *      dest.plp = plp
 *      dest.tid = tid
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_8csamfile_PileupProxy(((PyTypeObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_PileupProxy)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_8csamfile_PileupProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":131
 *     # note that the following does not call __init__
 *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
 *      dest.plp = plp             # <<<<<<<<<<<<<<
 *      dest.tid = tid
 *      dest.pos = pos
 */
  __pyx_v_dest->plp = __pyx_v_plp;

  /* "pysam/csamfile.pyx":132
 *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
 *      dest.plp = plp
 *      dest.tid = tid             # <<<<<<<<<<<<<<
 *      dest.pos = pos
 *      dest.n = n
 */
  __pyx_v_dest->tid = __pyx_v_tid;

  /* "pysam/csamfile.pyx":133
 *      dest.plp = plp
 *      dest.tid = tid
 *      dest.pos = pos             # <<<<<<<<<<<<<<
 *      dest.n = n
 *      return dest
 */
  __pyx_v_dest->pos = __pyx_v_pos;

  /* "pysam/csamfile.pyx":134
 *      dest.tid = tid
 *      dest.pos = pos
 *      dest.n = n             # <<<<<<<<<<<<<<
 *      return dest
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_dest), __pyx_n_s_n, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":135
 *      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;

  /* "pysam/csamfile.pyx":128
 * 
 * cdef class PileupProxy
 * cdef makePileupProxy(bam_pileup1_t ** plp, int tid, int pos, int n):             # <<<<<<<<<<<<<<
 *     # note that the following does not call __init__
 *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.makePileupProxy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":138
 * 
 * cdef class PileupRead
 * cdef makePileupRead( bam_pileup1_t * src ):             # <<<<<<<<<<<<<<
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 */

static PyObject *__pyx_f_5pysam_8csamfile_makePileupRead(bam_pileup1_t *__pyx_v_src) {
  struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int __pyx_t_3;
  uint32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("makePileupRead", 0);
  __Pyx_TraceCall("makePileupRead", __pyx_f[0], 138);

  /* "pysam/csamfile.pyx":140
 * cdef makePileupRead( bam_pileup1_t * src ):
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)             # <<<<<<<<<<<<<<
 *     dest._alignment = makeAlignedRead( src.b )
 *     dest._qpos = src.qpos
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_8csamfile_PileupRead(((PyTypeObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_PileupRead)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_8csamfile_PileupRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":141
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 *     dest._alignment = makeAlignedRead( src.b )             # <<<<<<<<<<<<<<
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 */
  __pyx_t_1 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_src->b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __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_5pysam_8csamfile_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __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_5pysam_8csamfile_AlignedRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":142
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 *     dest._alignment = makeAlignedRead( src.b )
 *     dest._qpos = src.qpos             # <<<<<<<<<<<<<<
 *     dest._indel = src.indel
 *     dest._level = src.level
 */
  __pyx_t_2 = __pyx_v_src->qpos;
  __pyx_v_dest->_qpos = __pyx_t_2;

  /* "pysam/csamfile.pyx":143
 *     dest._alignment = makeAlignedRead( src.b )
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel             # <<<<<<<<<<<<<<
 *     dest._level = src.level
 *     dest._is_del = src.is_del
 */
  __pyx_t_3 = __pyx_v_src->indel;
  __pyx_v_dest->_indel = __pyx_t_3;

  /* "pysam/csamfile.pyx":144
 *     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_t_3 = __pyx_v_src->level;
  __pyx_v_dest->_level = __pyx_t_3;

  /* "pysam/csamfile.pyx":145
 *     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_t_4 = __pyx_v_src->is_del;
  __pyx_v_dest->_is_del = __pyx_t_4;

  /* "pysam/csamfile.pyx":146
 *     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_t_4 = __pyx_v_src->is_head;
  __pyx_v_dest->_is_head = __pyx_t_4;

  /* "pysam/csamfile.pyx":147
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_t_4 = __pyx_v_src->is_tail;
  __pyx_v_dest->_is_tail = __pyx_t_4;

  /* "pysam/csamfile.pyx":148
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * cdef convertBinaryTagToList( uint8_t * s ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":138
 * 
 * cdef class PileupRead
 * cdef makePileupRead( bam_pileup1_t * src ):             # <<<<<<<<<<<<<<
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.makePileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":150
 *     return dest
 * 
 * cdef convertBinaryTagToList( uint8_t * s ):             # <<<<<<<<<<<<<<
 *     """return bytesize, number of values list of values in s."""
 *     cdef char auxtype
 */

static PyObject *__pyx_f_5pysam_8csamfile_convertBinaryTagToList(uint8_t *__pyx_v_s) {
  char __pyx_v_auxtype;
  uint8_t __pyx_v_byte_size;
  int32_t __pyx_v_nvalues;
  PyObject *__pyx_v_values = NULL;
  CYTHON_UNUSED long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("convertBinaryTagToList", 0);
  __Pyx_TraceCall("convertBinaryTagToList", __pyx_f[0], 150);

  /* "pysam/csamfile.pyx":157
 * 
 *     # get byte size
 *     auxtype = s[0]             # <<<<<<<<<<<<<<
 *     byte_size = aux_type2size( auxtype )
 *     s += 1
 */
  __pyx_v_auxtype = (__pyx_v_s[0]);

  /* "pysam/csamfile.pyx":158
 *     # get byte size
 *     auxtype = s[0]
 *     byte_size = aux_type2size( auxtype )             # <<<<<<<<<<<<<<
 *     s += 1
 *     # get number of values in array
 */
  __pyx_v_byte_size = aux_type2size(__pyx_v_auxtype);

  /* "pysam/csamfile.pyx":159
 *     auxtype = s[0]
 *     byte_size = aux_type2size( auxtype )
 *     s += 1             # <<<<<<<<<<<<<<
 *     # get number of values in array
 *     nvalues = (<int32_t*>s)[0]
 */
  __pyx_v_s = (__pyx_v_s + 1);

  /* "pysam/csamfile.pyx":161
 *     s += 1
 *     # get number of values in array
 *     nvalues = (<int32_t*>s)[0]             # <<<<<<<<<<<<<<
 *     s += 4
 *     # get values
 */
  __pyx_v_nvalues = (((int32_t *)__pyx_v_s)[0]);

  /* "pysam/csamfile.pyx":162
 *     # get number of values in array
 *     nvalues = (<int32_t*>s)[0]
 *     s += 4             # <<<<<<<<<<<<<<
 *     # get values
 *     values = []
 */
  __pyx_v_s = (__pyx_v_s + 4);

  /* "pysam/csamfile.pyx":164
 *     s += 4
 *     # get values
 *     values = []             # <<<<<<<<<<<<<<
 *     if auxtype == 'c':
 *         for x from 0 <= x < nvalues:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_values = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":189
 *             values.append((<uint32_t*>s)[0])
 *             s += 4
 *     elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<float*>s)[0])
 */
  switch (__pyx_v_auxtype) {

    /* "pysam/csamfile.pyx":165
 *     # get values
 *     values = []
 *     if auxtype == 'c':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<int8_t*>s)[0])
 */
    case 'c':

    /* "pysam/csamfile.pyx":166
 *     values = []
 *     if auxtype == 'c':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<int8_t*>s)[0])
 *             s += 1
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":167
 *     if auxtype == 'c':
 *         for x from 0 <= x < nvalues:
 *             values.append((<int8_t*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 1
 *     elif auxtype == 'C':
 */
      __pyx_t_1 = __Pyx_PyInt_From_int8_t((((int8_t *)__pyx_v_s)[0])); 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_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":168
 *         for x from 0 <= x < nvalues:
 *             values.append((<int8_t*>s)[0])
 *             s += 1             # <<<<<<<<<<<<<<
 *     elif auxtype == 'C':
 *         for x from 0 <= x < nvalues:
 */
      __pyx_v_s = (__pyx_v_s + 1);
    }
    break;

    /* "pysam/csamfile.pyx":169
 *             values.append((<int8_t*>s)[0])
 *             s += 1
 *     elif auxtype == 'C':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint8_t*>s)[0])
 */
    case 'C':

    /* "pysam/csamfile.pyx":170
 *             s += 1
 *     elif auxtype == 'C':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<uint8_t*>s)[0])
 *             s += 1
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":171
 *     elif auxtype == 'C':
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint8_t*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 1
 *     elif auxtype == 's':
 */
      __pyx_t_1 = __Pyx_PyInt_From_uint8_t((((uint8_t *)__pyx_v_s)[0])); 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_3 = __Pyx_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":172
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint8_t*>s)[0])
 *             s += 1             # <<<<<<<<<<<<<<
 *     elif auxtype == 's':
 *         for x from 0 <= x < nvalues:
 */
      __pyx_v_s = (__pyx_v_s + 1);
    }
    break;

    /* "pysam/csamfile.pyx":173
 *             values.append((<uint8_t*>s)[0])
 *             s += 1
 *     elif auxtype == 's':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<int16_t*>s)[0])
 */
    case 's':

    /* "pysam/csamfile.pyx":174
 *             s += 1
 *     elif auxtype == 's':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<int16_t*>s)[0])
 *             s += 2
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":175
 *     elif auxtype == 's':
 *         for x from 0 <= x < nvalues:
 *             values.append((<int16_t*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 2
 *     elif auxtype == 'S':
 */
      __pyx_t_1 = __Pyx_PyInt_From_int16_t((((int16_t *)__pyx_v_s)[0])); 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);
      __pyx_t_3 = __Pyx_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":176
 *         for x from 0 <= x < nvalues:
 *             values.append((<int16_t*>s)[0])
 *             s += 2             # <<<<<<<<<<<<<<
 *     elif auxtype == 'S':
 *         for x from 0 <= x < nvalues:
 */
      __pyx_v_s = (__pyx_v_s + 2);
    }
    break;

    /* "pysam/csamfile.pyx":177
 *             values.append((<int16_t*>s)[0])
 *             s += 2
 *     elif auxtype == 'S':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint16_t*>s)[0])
 */
    case 'S':

    /* "pysam/csamfile.pyx":178
 *             s += 2
 *     elif auxtype == 'S':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<uint16_t*>s)[0])
 *             s += 2
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":179
 *     elif auxtype == 'S':
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint16_t*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 2
 *     elif auxtype == 'i':
 */
      __pyx_t_1 = __Pyx_PyInt_From_uint16_t((((uint16_t *)__pyx_v_s)[0])); 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_3 = __Pyx_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":180
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint16_t*>s)[0])
 *             s += 2             # <<<<<<<<<<<<<<
 *     elif auxtype == 'i':
 *         for x from 0 <= x < nvalues:
 */
      __pyx_v_s = (__pyx_v_s + 2);
    }
    break;

    /* "pysam/csamfile.pyx":181
 *             values.append((<uint16_t*>s)[0])
 *             s += 2
 *     elif auxtype == 'i':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<int32_t*>s)[0])
 */
    case 'i':

    /* "pysam/csamfile.pyx":182
 *             s += 2
 *     elif auxtype == 'i':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<int32_t*>s)[0])
 *             s += 4
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":183
 *     elif auxtype == 'i':
 *         for x from 0 <= x < nvalues:
 *             values.append((<int32_t*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 4
 *     elif auxtype == 'I':
 */
      __pyx_t_1 = __Pyx_PyInt_From_int32_t((((int32_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":184
 *         for x from 0 <= x < nvalues:
 *             values.append((<int32_t*>s)[0])
 *             s += 4             # <<<<<<<<<<<<<<
 *     elif auxtype == 'I':
 *         for x from 0 <= x < nvalues:
 */
      __pyx_v_s = (__pyx_v_s + 4);
    }
    break;

    /* "pysam/csamfile.pyx":185
 *             values.append((<int32_t*>s)[0])
 *             s += 4
 *     elif auxtype == 'I':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint32_t*>s)[0])
 */
    case 'I':

    /* "pysam/csamfile.pyx":186
 *             s += 4
 *     elif auxtype == 'I':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<uint32_t*>s)[0])
 *             s += 4
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":187
 *     elif auxtype == 'I':
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint32_t*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 4
 *     elif auxtype == 'f':
 */
      __pyx_t_1 = __Pyx_PyInt_From_uint32_t((((uint32_t *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":188
 *         for x from 0 <= x < nvalues:
 *             values.append((<uint32_t*>s)[0])
 *             s += 4             # <<<<<<<<<<<<<<
 *     elif auxtype == 'f':
 *         for x from 0 <= x < nvalues:
 */
      __pyx_v_s = (__pyx_v_s + 4);
    }
    break;

    /* "pysam/csamfile.pyx":189
 *             values.append((<uint32_t*>s)[0])
 *             s += 4
 *     elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *         for x from 0 <= x < nvalues:
 *             values.append((<float*>s)[0])
 */
    case 'f':

    /* "pysam/csamfile.pyx":190
 *             s += 4
 *     elif auxtype == 'f':
 *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
 *             values.append((<float*>s)[0])
 *             s += 4
 */
    __pyx_t_2 = __pyx_v_nvalues;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":191
 *     elif auxtype == 'f':
 *         for x from 0 <= x < nvalues:
 *             values.append((<float*>s)[0])             # <<<<<<<<<<<<<<
 *             s += 4
 * 
 */
      __pyx_t_1 = PyFloat_FromDouble((((float *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":192
 *         for x from 0 <= x < nvalues:
 *             values.append((<float*>s)[0])
 *             s += 4             # <<<<<<<<<<<<<<
 * 
 *     return byte_size, nvalues, values
 */
      __pyx_v_s = (__pyx_v_s + 4);
    }
    break;
    default: break;
  }

  /* "pysam/csamfile.pyx":194
 *             s += 4
 * 
 *     return byte_size, nvalues, values             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __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 = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_values);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_values);
  __Pyx_GIVEREF(__pyx_v_values);
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":150
 *     return dest
 * 
 * cdef convertBinaryTagToList( uint8_t * s ):             # <<<<<<<<<<<<<<
 *     """return bytesize, number of values list of values in s."""
 *     cdef char auxtype
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.csamfile.convertBinaryTagToList", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":210
 *         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) )
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_12PileupColumn_1__str__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_12PileupColumn___str__[] = "PileupColumn.__str__(self)";
static PyMethodDef __pyx_mdef_5pysam_8csamfile_12PileupColumn_1__str__ = {__Pyx_NAMESTR("__str__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_12PileupColumn_1__str__, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_12PileupColumn___str__)};
static PyObject *__pyx_pw_5pysam_8csamfile_12PileupColumn_1__str__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_12PileupColumn___str__(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_12PileupColumn___str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 210);

  /* "pysam/csamfile.pyx":211
 *     '''
 *     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);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __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);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __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_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":212
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_pileups); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __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_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":210
 *         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) )
 */

  /* function exit code */
  __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("pysam.csamfile.PileupColumn.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":309
 *     '''
 * 
 *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 *         self._filename = None
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_7Samfile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_7Samfile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  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;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile___cinit__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_7Samfile___cinit__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 309);

  /* "pysam/csamfile.pyx":310
 * 
 *     def __cinit__(self, *args, **kwargs ):
 *         self.htsfile = NULL             # <<<<<<<<<<<<<<
 *         self._filename = None
 *         self.isbam = False
 */
  __pyx_v_self->htsfile = NULL;

  /* "pysam/csamfile.pyx":311
 *     def __cinit__(self, *args, **kwargs ):
 *         self.htsfile = NULL
 *         self._filename = None             # <<<<<<<<<<<<<<
 *         self.isbam = False
 *         self.isstream = False
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = Py_None;

  /* "pysam/csamfile.pyx":312
 *         self.htsfile = NULL
 *         self._filename = None
 *         self.isbam = False             # <<<<<<<<<<<<<<
 *         self.isstream = False
 *         self._open(*args, **kwargs)
 */
  __pyx_v_self->isbam = 0;

  /* "pysam/csamfile.pyx":313
 *         self._filename = None
 *         self.isbam = False
 *         self.isstream = False             # <<<<<<<<<<<<<<
 *         self._open(*args, **kwargs)
 * 
 */
  __pyx_v_self->isstream = 0;

  /* "pysam/csamfile.pyx":314
 *         self.isbam = False
 *         self.isstream = False
 *         self._open(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *         # allocate memory for iterator
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__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 = PySequence_Tuple(__pyx_v_args); 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_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":317
 * 
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 * 
 *     def _isOpen( self ):
 */
  __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/csamfile.pyx":309
 *     '''
 * 
 *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 *         self._filename = None
 */

  /* function exit code */
  __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("pysam.csamfile.Samfile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":319
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if htsfile has been opened.'''
 *         return self.htsfile != NULL
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_2_isOpen[] = "Samfile._isOpen(self)\nreturn true if htsfile has been opened.";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_isOpen (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_2_isOpen(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_2_isOpen(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_isOpen", 0);
  __Pyx_TraceCall("_isOpen", __pyx_f[0], 319);

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

  /* "pysam/csamfile.pyx":319
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 * 
 *     def _isOpen( self ):             # <<<<<<<<<<<<<<
 *         '''return true if htsfile has been opened.'''
 *         return self.htsfile != NULL
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.Samfile._isOpen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":323
 *         return self.htsfile != NULL
 * 
 *     def _hasIndex( self ):             # <<<<<<<<<<<<<<
 *         '''return true if htsfile has an existing (and opened) index.'''
 *         return self.index != NULL
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_5_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_4_hasIndex[] = "Samfile._hasIndex(self)\nreturn true if htsfile has an existing (and opened) index.";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_5_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_hasIndex (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_4_hasIndex(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_4_hasIndex(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_hasIndex", 0);
  __Pyx_TraceCall("_hasIndex", __pyx_f[0], 323);

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

  /* "pysam/csamfile.pyx":323
 *         return self.htsfile != NULL
 * 
 *     def _hasIndex( self ):             # <<<<<<<<<<<<<<
 *         '''return true if htsfile has an existing (and opened) index.'''
 *         return self.index != NULL
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.Samfile._hasIndex", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":327
 *         return self.index != NULL
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filename,
 *               mode=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_6_open[] = "Samfile._open(self, filename, mode=None, Samfile template=None, referencenames=None, referencelengths=None, text=None, header=None, port=None, add_sq_text=True, check_header=True, check_sq=True)\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_pw_5pysam_8csamfile_7Samfile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_mode = 0;
  struct __pyx_obj_5pysam_8csamfile_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;
  PyObject *__pyx_v_add_sq_text = 0;
  PyObject *__pyx_v_check_header = 0;
  PyObject *__pyx_v_check_sq = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_open (wrapper)", 0);
  {
    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,&__pyx_n_s_add_sq_text,&__pyx_n_s_check_header,&__pyx_n_s_check_sq,0};
    PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};

    /* "pysam/csamfile.pyx":329
 *     def _open(self,
 *               filename,
 *               mode=None,             # <<<<<<<<<<<<<<
 *               Samfile template=None,
 *               referencenames=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":330
 *               filename,
 *               mode=None,
 *               Samfile template=None,             # <<<<<<<<<<<<<<
 *               referencenames=None,
 *               referencelengths=None,
 */
    values[2] = (PyObject *)((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None);

    /* "pysam/csamfile.pyx":331
 *               mode=None,
 *               Samfile template=None,
 *               referencenames=None,             # <<<<<<<<<<<<<<
 *               referencelengths=None,
 *               text=None,
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":332
 *               Samfile template=None,
 *               referencenames=None,
 *               referencelengths=None,             # <<<<<<<<<<<<<<
 *               text=None,
 *               header=None,
 */
    values[4] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":333
 *               referencenames=None,
 *               referencelengths=None,
 *               text=None,             # <<<<<<<<<<<<<<
 *               header=None,
 *               port=None,
 */
    values[5] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":334
 *               referencelengths=None,
 *               text=None,
 *               header=None,             # <<<<<<<<<<<<<<
 *               port=None,
 *               add_sq_text=True,
 */
    values[6] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":335
 *               text=None,
 *               header=None,
 *               port=None,             # <<<<<<<<<<<<<<
 *               add_sq_text=True,
 *               check_header=True,
 */
    values[7] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":336
 *               header=None,
 *               port=None,
 *               add_sq_text=True,             # <<<<<<<<<<<<<<
 *               check_header=True,
 *               check_sq=True):
 */
    values[8] = ((PyObject *)Py_True);

    /* "pysam/csamfile.pyx":337
 *               port=None,
 *               add_sq_text=True,
 *               check_header=True,             # <<<<<<<<<<<<<<
 *               check_sq=True):
 *         '''open a sam/bam file.
 */
    values[9] = ((PyObject *)Py_True);

    /* "pysam/csamfile.pyx":338
 *               add_sq_text=True,
 *               check_header=True,
 *               check_sq=True):             # <<<<<<<<<<<<<<
 *         '''open a sam/bam file.
 * 
 */
    values[10] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_filename)) != 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--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_add_sq_text);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_check_header);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_check_sq);
          if (value) { values[10] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filename = values[0];
    __pyx_v_mode = values[1];
    __pyx_v_template = ((struct __pyx_obj_5pysam_8csamfile_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];
    __pyx_v_add_sq_text = values[8];
    __pyx_v_check_header = values[9];
    __pyx_v_check_sq = values[10];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_6_open(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_template, __pyx_v_referencenames, __pyx_v_referencelengths, __pyx_v_text, __pyx_v_header, __pyx_v_port, __pyx_v_add_sq_text, __pyx_v_check_header, __pyx_v_check_sq);

  /* "pysam/csamfile.pyx":327
 *         return self.index != NULL
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filename,
 *               mode=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_6_open(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_template, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_text, PyObject *__pyx_v_header, PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq) {
  CYTHON_UNUSED PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_bmode = 0;
  char *__pyx_v_ctext;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_ref = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  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;
  int __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  size_t __pyx_t_15;
  int32_t __pyx_t_16;
  long __pyx_t_17;
  uint32_t __pyx_t_18;
  char const *__pyx_t_19;
  int __pyx_t_20;
  char *__pyx_t_21;
  char const *__pyx_t_22;
  char const *__pyx_t_23;
  int __pyx_t_24;
  BGZF *__pyx_t_25;
  char const *__pyx_t_26;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_open", 0);
  __Pyx_TraceCall("_open", __pyx_f[0], 327);
  __Pyx_INCREF(__pyx_v_filename);
  __Pyx_INCREF(__pyx_v_referencenames);
  __Pyx_INCREF(__pyx_v_text);

  /* "pysam/csamfile.pyx":346
 * 
 *         # read mode autodetection
 *         if mode is None:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._open(filename, 'rb',
 */
  __pyx_t_1 = (__pyx_v_mode == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":347
 *         # read mode autodetection
 *         if mode is None:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._open(filename, 'rb',
 *                            template=template,
 */
    {
      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "pysam/csamfile.pyx":348
 *         if mode is None:
 *             try:
 *                 self._open(filename, 'rb',             # <<<<<<<<<<<<<<
 *                            template=template,
 *                            referencenames=referencenames,
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_filename);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_filename);
        __Pyx_GIVEREF(__pyx_v_filename);
        __Pyx_INCREF(__pyx_n_s_rb);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_rb);
        __Pyx_GIVEREF(__pyx_n_s_rb);
        __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
        __Pyx_GOTREF(__pyx_t_8);

        /* "pysam/csamfile.pyx":349
 *             try:
 *                 self._open(filename, 'rb',
 *                            template=template,             # <<<<<<<<<<<<<<
 *                            referencenames=referencenames,
 *                            referencelengths=referencelengths,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_template, ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":350
 *                 self._open(filename, 'rb',
 *                            template=template,
 *                            referencenames=referencenames,             # <<<<<<<<<<<<<<
 *                            referencelengths=referencelengths,
 *                            text=text,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_referencenames, __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":351
 *                            template=template,
 *                            referencenames=referencenames,
 *                            referencelengths=referencelengths,             # <<<<<<<<<<<<<<
 *                            text=text,
 *                            header=header,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_referencelengths, __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":352
 *                            referencenames=referencenames,
 *                            referencelengths=referencelengths,
 *                            text=text,             # <<<<<<<<<<<<<<
 *                            header=header,
 *                            port=port,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_text, __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":353
 *                            referencelengths=referencelengths,
 *                            text=text,
 *                            header=header,             # <<<<<<<<<<<<<<
 *                            port=port,
 *                            check_header=check_header,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_header, __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":354
 *                            text=text,
 *                            header=header,
 *                            port=port,             # <<<<<<<<<<<<<<
 *                            check_header=check_header,
 *                            check_sq=check_sq)
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_port, __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":355
 *                            header=header,
 *                            port=port,
 *                            check_header=check_header,             # <<<<<<<<<<<<<<
 *                            check_sq=check_sq)
 *                 return
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_check_header, __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":356
 *                            port=port,
 *                            check_header=check_header,
 *                            check_sq=check_sq)             # <<<<<<<<<<<<<<
 *                 return
 *             except ValueError, msg:
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_check_sq, __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}

        /* "pysam/csamfile.pyx":348
 *         if mode is None:
 *             try:
 *                 self._open(filename, 'rb',             # <<<<<<<<<<<<<<
 *                            template=template,
 *                            referencenames=referencenames,
 */
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pysam/csamfile.pyx":357
 *                            check_header=check_header,
 *                            check_sq=check_sq)
 *                 return             # <<<<<<<<<<<<<<
 *             except ValueError, msg:
 *                 pass
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L8_try_return;
      }
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L11_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pysam/csamfile.pyx":358
 *                            check_sq=check_sq)
 *                 return
 *             except ValueError, msg:             # <<<<<<<<<<<<<<
 *                 pass
 * 
 */
      __pyx_t_10 = PyErr_ExceptionMatches(__pyx_builtin_ValueError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("pysam.csamfile.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __pyx_v_msg = __pyx_t_8;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L8_try_return:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L0;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      __pyx_L11_try_end:;
    }

    /* "pysam/csamfile.pyx":361
 *                 pass
 * 
 *             self._open(filename, 'r',             # <<<<<<<<<<<<<<
 *                        template=template,
 *                        referencenames=referencenames,
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __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 = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_filename);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_filename);
    __Pyx_GIVEREF(__pyx_v_filename);
    __Pyx_INCREF(__pyx_n_s_r);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_n_s_r);
    __Pyx_GIVEREF(__pyx_n_s_r);
    __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);

    /* "pysam/csamfile.pyx":362
 * 
 *             self._open(filename, 'r',
 *                        template=template,             # <<<<<<<<<<<<<<
 *                        referencenames=referencenames,
 *                        referencelengths=referencelengths,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_template, ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":363
 *             self._open(filename, 'r',
 *                        template=template,
 *                        referencenames=referencenames,             # <<<<<<<<<<<<<<
 *                        referencelengths=referencelengths,
 *                        text=text,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_referencenames, __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":364
 *                        template=template,
 *                        referencenames=referencenames,
 *                        referencelengths=referencelengths,             # <<<<<<<<<<<<<<
 *                        text=text,
 *                        header=header,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_referencelengths, __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":365
 *                        referencenames=referencenames,
 *                        referencelengths=referencelengths,
 *                        text=text,             # <<<<<<<<<<<<<<
 *                        header=header,
 *                        port=port,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_text, __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":366
 *                        referencelengths=referencelengths,
 *                        text=text,
 *                        header=header,             # <<<<<<<<<<<<<<
 *                        port=port,
 *                        check_header=check_header,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_header, __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":367
 *                        text=text,
 *                        header=header,
 *                        port=port,             # <<<<<<<<<<<<<<
 *                        check_header=check_header,
 *                        check_sq=check_sq)
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_port, __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":368
 *                        header=header,
 *                        port=port,
 *                        check_header=check_header,             # <<<<<<<<<<<<<<
 *                        check_sq=check_sq)
 *             return
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_check_header, __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":369
 *                        port=port,
 *                        check_header=check_header,
 *                        check_sq=check_sq)             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_check_sq, __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":361
 *                 pass
 * 
 *             self._open(filename, 'r',             # <<<<<<<<<<<<<<
 *                        template=template,
 *                        referencenames=referencenames,
 */
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/csamfile.pyx":370
 *                        check_header=check_header,
 *                        check_sq=check_sq)
 *             return             # <<<<<<<<<<<<<<
 * 
 *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), \
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":372
 *             return
 * 
 *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), \             # <<<<<<<<<<<<<<
 *             "invalid file opening mode `%s`" % mode
 * 
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __Pyx_INCREF(__pyx_v_mode);
    __pyx_t_6 = __pyx_v_mode;
    __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_2) {
      __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = __pyx_t_1;
    } else {
      __pyx_t_11 = __pyx_t_2;
    }
    if (!__pyx_t_11) {
      __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_rb, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __pyx_t_2;
    } else {
      __pyx_t_1 = __pyx_t_11;
    }
    if (!__pyx_t_1) {
      __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wb, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __pyx_t_11;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (!__pyx_t_2) {
      __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wh, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = __pyx_t_1;
    } else {
      __pyx_t_11 = __pyx_t_2;
    }
    if (!__pyx_t_11) {
      __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __pyx_t_2;
    } else {
      __pyx_t_1 = __pyx_t_11;
    }
    if (!__pyx_t_1) {
      __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_rU, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __pyx_t_11;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!(__pyx_t_2 != 0))) {

      /* "pysam/csamfile.pyx":373
 * 
 *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), \
 *             "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
 * 
 *         # close a previously opened file
 */
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyErr_SetObject(PyExc_AssertionError, __pyx_t_6);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

  /* "pysam/csamfile.pyx":376
 * 
 *         # close a previously opened file
 *         if self.htsfile != NULL:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->htsfile != NULL) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":377
 *         # close a previously opened file
 *         if self.htsfile != NULL:
 *             self.close()             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes bmode = mode.encode('ascii')
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 377; __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_9); __pyx_t_9 = 0;
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "pysam/csamfile.pyx":379
 *             self.close()
 * 
 *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
 *         self._filename = filename = _encodeFilename(filename)
 *         self.isstream = filename == b"-"
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_mode, __pyx_n_s_encode); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_6)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_bmode = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":380
 * 
 *         cdef bytes bmode = mode.encode('ascii')
 *         self._filename = filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
 *         self.isstream = filename == b"-"
 * 
 */
  __pyx_t_6 = __pyx_f_5pysam_8csamfile__encodeFilename(__pyx_v_filename); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = __pyx_t_6;
  __Pyx_INCREF(__pyx_t_6);
  __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_6);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":381
 *         cdef bytes bmode = mode.encode('ascii')
 *         self._filename = filename = _encodeFilename(filename)
 *         self.isstream = filename == b"-"             # <<<<<<<<<<<<<<
 * 
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 */
  __pyx_t_6 = PyObject_RichCompare(__pyx_v_filename, __pyx_kp_b__6, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_self->isstream = __pyx_t_10;

  /* "pysam/csamfile.pyx":383
 *         self.isstream = filename == b"-"
 * 
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'             # <<<<<<<<<<<<<<
 * 
 *         self.isremote = filename.startswith(b"http:") or \
 */
  __pyx_t_12 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __Pyx_PyBool_FromLong((__pyx_t_12 > 1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __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 = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_mode, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, __pyx_n_s_b, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __pyx_t_8;
    __pyx_t_8 = 0;
  } else {
    __pyx_t_9 = __pyx_t_6;
    __pyx_t_6 = 0;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_self->isbam = __pyx_t_10;

  /* "pysam/csamfile.pyx":385
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 * 
 *         self.isremote = filename.startswith(b"http:") or \             # <<<<<<<<<<<<<<
 *                         filename.startswith(b"ftp:")
 * 
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_2) {
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/csamfile.pyx":386
 * 
 *         self.isremote = filename.startswith(b"http:") or \
 *                         filename.startswith(b"ftp:")             # <<<<<<<<<<<<<<
 * 
 *         cdef char * ctext
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __pyx_t_8;
    __pyx_t_8 = 0;
  } else {
    __pyx_t_9 = __pyx_t_6;
    __pyx_t_6 = 0;
  }

  /* "pysam/csamfile.pyx":385
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 * 
 *         self.isremote = filename.startswith(b"http:") or \             # <<<<<<<<<<<<<<
 *                         filename.startswith(b"ftp:")
 * 
 */
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_self->isremote = __pyx_t_10;

  /* "pysam/csamfile.pyx":389
 * 
 *         cdef char * ctext
 *         ctext = NULL             # <<<<<<<<<<<<<<
 * 
 *         if mode[0] == 'w':
 */
  __pyx_v_ctext = NULL;

  /* "pysam/csamfile.pyx":391
 *         ctext = NULL
 * 
 *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
 *             # open file for writing
 * 
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_9, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":395
 * 
 *             # header structure (used for writing)
 *             if template:             # <<<<<<<<<<<<<<
 *                 self.header = bam_hdr_dup(template.header)
 *             elif header:
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":396
 *             # header structure (used for writing)
 *             if template:
 *                 self.header = bam_hdr_dup(template.header)             # <<<<<<<<<<<<<<
 *             elif header:
 *                 self.header = self._buildHeader(header)
 */
      __pyx_v_self->header = bam_hdr_dup(__pyx_v_template->header);
      goto __pyx_L16;
    }

    /* "pysam/csamfile.pyx":397
 *             if template:
 *                 self.header = bam_hdr_dup(template.header)
 *             elif header:             # <<<<<<<<<<<<<<
 *                 self.header = self._buildHeader(header)
 *             else:
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":398
 *                 self.header = bam_hdr_dup(template.header)
 *             elif header:
 *                 self.header = self._buildHeader(header)             # <<<<<<<<<<<<<<
 *             else:
 *                 # build header from a target names and lengths
 */
      __pyx_v_self->header = ((struct __pyx_vtabstruct_5pysam_8csamfile_Samfile *)__pyx_v_self->__pyx_vtab)->_buildHeader(__pyx_v_self, __pyx_v_header);
      goto __pyx_L16;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":401
 *             else:
 *                 # build header from a target names and lengths
 *                 assert referencenames and referencelengths, \             # <<<<<<<<<<<<<<
 *                     ("either supply options `template`, `header` "
 *                      "or  both `referencenames` and `referencelengths` "
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_referencenames); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (__pyx_t_2) {
          __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_referencelengths); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_11 = __pyx_t_1;
        } else {
          __pyx_t_11 = __pyx_t_2;
        }
        if (unlikely(!__pyx_t_11)) {
          PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_either_supply_options_template_h);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

      /* "pysam/csamfile.pyx":405
 *                      "or  both `referencenames` and `referencelengths` "
 *                      "for writing")
 *                 assert len(referencenames) == len(referencelengths), \             # <<<<<<<<<<<<<<
 *                     "unequal names and lengths of reference sequences"
 * 
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_12 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_13 = PyObject_Length(__pyx_v_referencelengths); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (unlikely(!((__pyx_t_12 == __pyx_t_13) != 0))) {
          PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_unequal_names_and_lengths_of_ref);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

      /* "pysam/csamfile.pyx":409
 * 
 *                 # allocate and fill header
 *                 referencenames = [_forceBytes(ref) for ref in referencenames]             # <<<<<<<<<<<<<<
 *                 self.header = bam_hdr_init()
 *                 self.header.n_targets = len(referencenames)
 */
      __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
        __pyx_t_6 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_6); __pyx_t_13 = 0;
        __pyx_t_14 = NULL;
      } else {
        __pyx_t_13 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_14 = Py_TYPE(__pyx_t_6)->tp_iternext;
      }
      for (;;) {
        if (!__pyx_t_14 && PyList_CheckExact(__pyx_t_6)) {
          if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_13); __Pyx_INCREF(__pyx_t_8); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_14 && PyTuple_CheckExact(__pyx_t_6)) {
          if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_13); __Pyx_INCREF(__pyx_t_8); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_6, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_8 = __pyx_t_14(__pyx_t_6);
          if (unlikely(!__pyx_t_8)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_8 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_ref); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_9, (PyObject*)__pyx_t_8))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF_SET(__pyx_v_referencenames, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pysam/csamfile.pyx":410
 *                 # allocate and fill header
 *                 referencenames = [_forceBytes(ref) for ref in referencenames]
 *                 self.header = bam_hdr_init()             # <<<<<<<<<<<<<<
 *                 self.header.n_targets = len(referencenames)
 *                 n = 0
 */
      __pyx_v_self->header = bam_hdr_init();

      /* "pysam/csamfile.pyx":411
 *                 referencenames = [_forceBytes(ref) for ref in referencenames]
 *                 self.header = bam_hdr_init()
 *                 self.header.n_targets = len(referencenames)             # <<<<<<<<<<<<<<
 *                 n = 0
 *                 for x in referencenames:
 */
      __pyx_t_13 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->header->n_targets = __pyx_t_13;

      /* "pysam/csamfile.pyx":412
 *                 self.header = bam_hdr_init()
 *                 self.header.n_targets = len(referencenames)
 *                 n = 0             # <<<<<<<<<<<<<<
 *                 for x in referencenames:
 *                     n += len(x) + 1
 */
      __Pyx_INCREF(__pyx_int_0);
      __pyx_v_n = __pyx_int_0;

      /* "pysam/csamfile.pyx":413
 *                 self.header.n_targets = len(referencenames)
 *                 n = 0
 *                 for x in referencenames:             # <<<<<<<<<<<<<<
 *                     n += len(x) + 1
 *                 self.header.target_name = <char**>calloc(n, sizeof(char*))
 */
      if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
        __pyx_t_9 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_9); __pyx_t_13 = 0;
        __pyx_t_14 = NULL;
      } else {
        __pyx_t_13 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext;
      }
      for (;;) {
        if (!__pyx_t_14 && PyList_CheckExact(__pyx_t_9)) {
          if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_9)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_14 && PyTuple_CheckExact(__pyx_t_9)) {
          if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_6 = __pyx_t_14(__pyx_t_9);
          if (unlikely(!__pyx_t_6)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_6);
        }
        __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pysam/csamfile.pyx":414
 *                 n = 0
 *                 for x in referencenames:
 *                     n += len(x) + 1             # <<<<<<<<<<<<<<
 *                 self.header.target_name = <char**>calloc(n, sizeof(char*))
 *                 self.header.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 */
        __pyx_t_12 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_12 + 1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_8);
        __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pysam/csamfile.pyx":415
 *                 for x in referencenames:
 *                     n += len(x) + 1
 *                 self.header.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
 *                 self.header.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < self.header.n_targets:
 */
      __pyx_t_15 = __Pyx_PyInt_As_size_t(__pyx_v_n); if (unlikely((__pyx_t_15 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->header->target_name = ((char **)calloc(__pyx_t_15, (sizeof(char *))));

      /* "pysam/csamfile.pyx":416
 *                     n += len(x) + 1
 *                 self.header.target_name = <char**>calloc(n, sizeof(char*))
 *                 self.header.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
 *                 for x from 0 <= x < self.header.n_targets:
 *                     self.header.target_len[x] = referencelengths[x]
 */
      __pyx_t_15 = __Pyx_PyInt_As_size_t(__pyx_v_n); if (unlikely((__pyx_t_15 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->header->target_len = ((uint32_t *)calloc(__pyx_t_15, (sizeof(uint32_t))));

      /* "pysam/csamfile.pyx":417
 *                 self.header.target_name = <char**>calloc(n, sizeof(char*))
 *                 self.header.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                     self.header.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]
 */
      __pyx_t_16 = __pyx_v_self->header->n_targets;
      for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17++) {
        __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
        __pyx_t_9 = 0;

        /* "pysam/csamfile.pyx":418
 *                 self.header.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < self.header.n_targets:
 *                     self.header.target_len[x] = referencelengths[x]             # <<<<<<<<<<<<<<
 *                     name = referencenames[x]
 *                     self.header.target_name[x] = <char*>calloc(
 */
        __pyx_t_9 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_18 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_18 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_13 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_13 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        (__pyx_v_self->header->target_len[__pyx_t_13]) = __pyx_t_18;

        /* "pysam/csamfile.pyx":419
 *                 for x from 0 <= x < self.header.n_targets:
 *                     self.header.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]             # <<<<<<<<<<<<<<
 *                     self.header.target_name[x] = <char*>calloc(
 *                         len(name) + 1, sizeof(char))
 */
        __pyx_t_9 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_9);
        __pyx_t_9 = 0;

        /* "pysam/csamfile.pyx":421
 *                     name = referencenames[x]
 *                     self.header.target_name[x] = <char*>calloc(
 *                         len(name) + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *                     strncpy(self.header.target_name[x], name, len(name))
 * 
 */
        __pyx_t_13 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/csamfile.pyx":420
 *                     self.header.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]
 *                     self.header.target_name[x] = <char*>calloc(             # <<<<<<<<<<<<<<
 *                         len(name) + 1, sizeof(char))
 *                     strncpy(self.header.target_name[x], name, len(name))
 */
        __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        (__pyx_v_self->header->target_name[__pyx_t_12]) = ((char *)calloc((__pyx_t_13 + 1), (sizeof(char))));

        /* "pysam/csamfile.pyx":422
 *                     self.header.target_name[x] = <char*>calloc(
 *                         len(name) + 1, sizeof(char))
 *                     strncpy(self.header.target_name[x], name, len(name))             # <<<<<<<<<<<<<<
 * 
 *                 # Optionally, if there is no text, add a SAM
 */
        __pyx_t_13 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_13 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_12 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        strncpy((__pyx_v_self->header->target_name[__pyx_t_13]), __pyx_t_19, __pyx_t_12);
        __pyx_t_17 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_17 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }

      /* "pysam/csamfile.pyx":417
 *                 self.header.target_name = <char**>calloc(n, sizeof(char*))
 *                 self.header.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *                 for x from 0 <= x < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                     self.header.target_len[x] = referencelengths[x]
 *                     name = referencenames[x]
 */
      __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
      __pyx_t_9 = 0;

      /* "pysam/csamfile.pyx":426
 *                 # Optionally, if there is no text, add a SAM
 *                 # compatible header to output file.
 *                 if text is None and add_sq_text:             # <<<<<<<<<<<<<<
 *                     text = []
 *                     for x from 0 <= x < self.header.n_targets:
 */
      __pyx_t_11 = (__pyx_v_text == Py_None);
      if (__pyx_t_11) {
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_1 = __pyx_t_2;
      } else {
        __pyx_t_1 = __pyx_t_11;
      }
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":427
 *                 # compatible header to output file.
 *                 if text is None and add_sq_text:
 *                     text = []             # <<<<<<<<<<<<<<
 *                     for x from 0 <= x < self.header.n_targets:
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \
 */
        __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_9);
        __pyx_t_9 = 0;

        /* "pysam/csamfile.pyx":428
 *                 if text is None and add_sq_text:
 *                     text = []
 *                     for x from 0 <= x < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \
 *                                     (_forceStr(referencenames[x]),
 */
        __pyx_t_16 = __pyx_v_self->header->n_targets;
        for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17++) {
          __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "pysam/csamfile.pyx":430
 *                     for x from 0 <= x < self.header.n_targets:
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \
 *                                     (_forceStr(referencenames[x]),             # <<<<<<<<<<<<<<
 *                                      referencelengths[x]))
 *                     text = ''.join(text)
 */
          __pyx_t_9 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_8 = __pyx_f_5pysam_8csamfile__forceStr(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "pysam/csamfile.pyx":431
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \
 *                                     (_forceStr(referencenames[x]),
 *                                      referencelengths[x]))             # <<<<<<<<<<<<<<
 *                     text = ''.join(text)
 * 
 */
          __pyx_t_9 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_9);

          /* "pysam/csamfile.pyx":430
 *                     for x from 0 <= x < self.header.n_targets:
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \
 *                                     (_forceStr(referencenames[x]),             # <<<<<<<<<<<<<<
 *                                      referencelengths[x]))
 *                     text = ''.join(text)
 */
          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_9);
          __pyx_t_8 = 0;
          __pyx_t_9 = 0;

          /* "pysam/csamfile.pyx":429
 *                     text = []
 *                     for x from 0 <= x < self.header.n_targets:
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \             # <<<<<<<<<<<<<<
 *                                     (_forceStr(referencenames[x]),
 *                                      referencelengths[x]))
 */
          __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_SQ_SN_s_LN_s, __pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_20 = __Pyx_PyObject_Append(__pyx_v_text, __pyx_t_9); if (unlikely(__pyx_t_20 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_17 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_17 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }

        /* "pysam/csamfile.pyx":428
 *                 if text is None and add_sq_text:
 *                     text = []
 *                     for x from 0 <= x < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                         text.append("@SQ\tSN:%s\tLN:%s\n" % \
 *                                     (_forceStr(referencenames[x]),
 */
        __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
        __pyx_t_9 = 0;

        /* "pysam/csamfile.pyx":432
 *                                     (_forceStr(referencenames[x]),
 *                                      referencelengths[x]))
 *                     text = ''.join(text)             # <<<<<<<<<<<<<<
 * 
 *                 if text != None:
 */
        __pyx_t_9 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_v_text); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_9);
        __pyx_t_9 = 0;
        goto __pyx_L23;
      }
      __pyx_L23:;

      /* "pysam/csamfile.pyx":434
 *                     text = ''.join(text)
 * 
 *                 if text != None:             # <<<<<<<<<<<<<<
 *                     # copy without \0
 *                     text = _forceBytes(text)
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_text, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":436
 *                 if text != None:
 *                     # copy without \0
 *                     text = _forceBytes(text)             # <<<<<<<<<<<<<<
 *                     ctext = text
 *                     self.header.l_text = strlen(ctext)
 */
        __pyx_t_9 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_text); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_9);
        __pyx_t_9 = 0;

        /* "pysam/csamfile.pyx":437
 *                     # copy without \0
 *                     text = _forceBytes(text)
 *                     ctext = text             # <<<<<<<<<<<<<<
 *                     self.header.l_text = strlen(ctext)
 *                     self.header.text = <char*>calloc(
 */
        __pyx_t_21 = __Pyx_PyObject_AsString(__pyx_v_text); if (unlikely((!__pyx_t_21) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_ctext = __pyx_t_21;

        /* "pysam/csamfile.pyx":438
 *                     text = _forceBytes(text)
 *                     ctext = text
 *                     self.header.l_text = strlen(ctext)             # <<<<<<<<<<<<<<
 *                     self.header.text = <char*>calloc(
 *                         strlen(ctext), sizeof(char))
 */
        __pyx_v_self->header->l_text = strlen(__pyx_v_ctext);

        /* "pysam/csamfile.pyx":439
 *                     ctext = text
 *                     self.header.l_text = strlen(ctext)
 *                     self.header.text = <char*>calloc(             # <<<<<<<<<<<<<<
 *                         strlen(ctext), sizeof(char))
 *                     memcpy(self.header.text, ctext, strlen(ctext))
 */
        __pyx_v_self->header->text = ((char *)calloc(strlen(__pyx_v_ctext), (sizeof(char))));

        /* "pysam/csamfile.pyx":441
 *                     self.header.text = <char*>calloc(
 *                         strlen(ctext), sizeof(char))
 *                     memcpy(self.header.text, ctext, strlen(ctext))             # <<<<<<<<<<<<<<
 * 
 *             # open file. Header gets written to file at the same time for bam files
 */
        memcpy(__pyx_v_self->header->text, __pyx_v_ctext, strlen(__pyx_v_ctext));
        goto __pyx_L26;
      }
      __pyx_L26:;
    }
    __pyx_L16:;

    /* "pysam/csamfile.pyx":445
 *             # 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)
 *             self.htsfile = hts_open(filename, bmode)             # <<<<<<<<<<<<<<
 * 
 *             # for compatibility - "w" writes sam file without header
 */
    __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_23 = __Pyx_PyObject_AsString(__pyx_v_bmode); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_22, __pyx_t_23);

    /* "pysam/csamfile.pyx":448
 * 
 *             # for compatibility - "w" writes sam file without header
 *             if self.isbam or "h" in mode:             # <<<<<<<<<<<<<<
 *                 # write header to htsfile
 *                 sam_hdr_write(self.htsfile, self.header)
 */
    if (!(__pyx_v_self->isbam != 0)) {
      __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_n_s_h, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = __pyx_t_1;
    } else {
      __pyx_t_11 = (__pyx_v_self->isbam != 0);
    }
    if (__pyx_t_11) {

      /* "pysam/csamfile.pyx":450
 *             if self.isbam or "h" in mode:
 *                 # write header to htsfile
 *                 sam_hdr_write(self.htsfile, self.header)             # <<<<<<<<<<<<<<
 * 
 *         elif mode[0] == "r":
 */
      sam_hdr_write(__pyx_v_self->htsfile, __pyx_v_self->header);
      goto __pyx_L27;
    }
    __pyx_L27:;
    goto __pyx_L15;
  }

  /* "pysam/csamfile.pyx":452
 *                 sam_hdr_write(self.htsfile, self.header)
 * 
 *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
 *             # open file for reading
 *             if (filename != b"-"
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_t_9, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (__pyx_t_11) {

    /* "pysam/csamfile.pyx":454
 *         elif mode[0] == "r":
 *             # open file for reading
 *             if (filename != b"-"             # <<<<<<<<<<<<<<
 *                 and not self.isremote
 *                 and not os.path.exists(filename)):
 */
    __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_filename, __pyx_kp_b__6, Py_NE)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_11) {

      /* "pysam/csamfile.pyx":455
 *             # open file for reading
 *             if (filename != b"-"
 *                 and not self.isremote             # <<<<<<<<<<<<<<
 *                 and not os.path.exists(filename)):
 *                 raise IOError("file `%s` not found" % filename)
 */
      __pyx_t_1 = (!(__pyx_v_self->isremote != 0));
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":456
 *             if (filename != b"-"
 *                 and not self.isremote
 *                 and not os.path.exists(filename)):             # <<<<<<<<<<<<<<
 *                 raise IOError("file `%s` not found" % filename)
 * 
 */
        __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __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 = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_v_filename);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_filename);
        __Pyx_GIVEREF(__pyx_v_filename);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_24 = (!__pyx_t_2);
        __pyx_t_2 = __pyx_t_24;
      } else {
        __pyx_t_2 = __pyx_t_1;
      }
      __pyx_t_1 = __pyx_t_2;
    } else {
      __pyx_t_1 = __pyx_t_11;
    }
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":457
 *                 and not self.isremote
 *                 and not os.path.exists(filename)):
 *                 raise IOError("file `%s` not found" % filename)             # <<<<<<<<<<<<<<
 * 
 *             # try to detect errors
 */
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":460
 * 
 *             # try to detect errors
 *             self.htsfile = hts_open(filename, bmode)             # <<<<<<<<<<<<<<
 *             if self.htsfile == NULL:
 *                 raise ValueError(
 */
    __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_23 = __Pyx_PyObject_AsString(__pyx_v_bmode); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_22, __pyx_t_23);

    /* "pysam/csamfile.pyx":461
 *             # try to detect errors
 *             self.htsfile = hts_open(filename, bmode)
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "could not open file (mode='%s') - "
 */
    __pyx_t_1 = ((__pyx_v_self->htsfile == NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":464
 *                 raise ValueError(
 *                     "could not open file (mode='%s') - "
 *                     "is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
 * 
 *             # get file pointer
 */
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_mode_s_is_it, __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);

      /* "pysam/csamfile.pyx":462
 *             self.htsfile = hts_open(filename, bmode)
 *             if self.htsfile == NULL:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "could not open file (mode='%s') - "
 *                     "is it SAM/BAM format?" % mode)
 */
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":469
 *             # TODO: this is specific to BAM files
 *             #       refactor to make generalizable
 *             self.fp = self.htsfile.fp.bgzf             # <<<<<<<<<<<<<<
 * 
 *             # bam files require a valid header
 */
    __pyx_t_25 = __pyx_v_self->htsfile->fp.bgzf;
    __pyx_v_self->fp = __pyx_t_25;

    /* "pysam/csamfile.pyx":472
 * 
 *             # bam files require a valid header
 *             if self.isbam:             # <<<<<<<<<<<<<<
 *                 self.header = sam_hdr_read(self.htsfile)
 *                 if self.header == NULL:
 */
    __pyx_t_1 = (__pyx_v_self->isbam != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":473
 *             # bam files require a valid header
 *             if self.isbam:
 *                 self.header = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                 if self.header == NULL:
 *                     raise ValueError(
 */
      __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile);

      /* "pysam/csamfile.pyx":474
 *             if self.isbam:
 *                 self.header = sam_hdr_read(self.htsfile)
 *                 if self.header == NULL:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "file does not have valid header (mode='%s') "
 */
      __pyx_t_1 = ((__pyx_v_self->header == NULL) != 0);
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":477
 *                     raise ValueError(
 *                         "file does not have valid header (mode='%s') "
 *                         "- is it BAM format?" % mode )             # <<<<<<<<<<<<<<
 *             else:
 *                 # in sam files it is optional (htsfile full of unmapped reads)
 */
        __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_file_does_not_have_valid_header, __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);

        /* "pysam/csamfile.pyx":475
 *                 self.header = sam_hdr_read(self.htsfile)
 *                 if self.header == NULL:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "file does not have valid header (mode='%s') "
 *                         "- is it BAM format?" % mode )
 */
        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      goto __pyx_L30;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":480
 *             else:
 *                 # in sam files it is optional (htsfile full of unmapped reads)
 *                 if check_header:             # <<<<<<<<<<<<<<
 *                     self.header = sam_hdr_read(self.htsfile)
 *                     if self.header == NULL:
 */
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_header); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":481
 *                 # in sam files it is optional (htsfile full of unmapped reads)
 *                 if check_header:
 *                     self.header = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                     if self.header == NULL:
 *                         raise ValueError(
 */
        __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile);

        /* "pysam/csamfile.pyx":482
 *                 if check_header:
 *                     self.header = sam_hdr_read(self.htsfile)
 *                     if self.header == NULL:             # <<<<<<<<<<<<<<
 *                         raise ValueError(
 *                             "file does not have valid header (mode='%s') "
 */
        __pyx_t_1 = ((__pyx_v_self->header == NULL) != 0);
        if (__pyx_t_1) {

          /* "pysam/csamfile.pyx":485
 *                         raise ValueError(
 *                             "file does not have valid header (mode='%s') "
 *                             "- is it SAM format?" % mode )             # <<<<<<<<<<<<<<
 *                     # self.header.ignore_sam_err = True
 * 
 */
          __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_file_does_not_have_valid_header_2, __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);

          /* "pysam/csamfile.pyx":483
 *                     self.header = sam_hdr_read(self.htsfile)
 *                     if self.header == NULL:
 *                         raise ValueError(             # <<<<<<<<<<<<<<
 *                             "file does not have valid header (mode='%s') "
 *                             "- is it SAM format?" % mode )
 */
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        goto __pyx_L32;
      }
      __pyx_L32:;
    }
    __pyx_L30:;

    /* "pysam/csamfile.pyx":490
 *             # disabled for autodetection to work needs to be disabled
 *             # so that reading from sam-files without headers works
 *             if check_sq and self.header.n_targets == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     ("file header is empty (mode='%s') - "
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_1) {
      __pyx_t_11 = (__pyx_v_self->header->n_targets == 0);
      __pyx_t_2 = __pyx_t_11;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":493
 *                 raise ValueError(
 *                     ("file header is empty (mode='%s') - "
 *                      "is it SAM/BAM format?") % mode)             # <<<<<<<<<<<<<<
 * 
 *         if self.htsfile == NULL:
 */
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_file_header_is_empty_mode_s_is_i, __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);

      /* "pysam/csamfile.pyx":491
 *             # so that reading from sam-files without headers works
 *             if check_sq and self.header.n_targets == 0:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     ("file header is empty (mode='%s') - "
 *                      "is it SAM/BAM format?") % mode)
 */
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    goto __pyx_L15;
  }
  __pyx_L15:;

  /* "pysam/csamfile.pyx":495
 *                      "is it SAM/BAM format?") % mode)
 * 
 *         if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *             raise IOError("could not open file `%s`" % filename )
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->htsfile == NULL) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":496
 * 
 *         if self.htsfile == NULL:
 *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
 * 
 *         # check for index and open if present
 */
    __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":499
 * 
 *         # check for index and open if present
 *         if mode[0] == "r" and self.isbam:             # <<<<<<<<<<<<<<
 * 
 *             if not self.isremote:
 */
  __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_8, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (__pyx_t_2) {
    __pyx_t_1 = (__pyx_v_self->isbam != 0);
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":501
 *         if mode[0] == "r" and self.isbam:
 * 
 *             if not self.isremote:             # <<<<<<<<<<<<<<
 *                 if not os.path.exists(filename + b".bai") \
 *                         and not os.path.exists( filename[:-4] + b".bai"):
 */
    __pyx_t_1 = ((!(__pyx_v_self->isremote != 0)) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":502
 * 
 *             if not self.isremote:
 *                 if not os.path.exists(filename + b".bai") \             # <<<<<<<<<<<<<<
 *                         and not os.path.exists( filename[:-4] + b".bai"):
 *                     self.index = NULL
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Add(__pyx_v_filename, __pyx_kp_b_bai); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_2 = ((!__pyx_t_1) != 0);
      if (__pyx_t_2) {

        /* "pysam/csamfile.pyx":503
 *             if not self.isremote:
 *                 if not os.path.exists(filename + b".bai") \
 *                         and not os.path.exists( filename[:-4] + b".bai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 else:
 */
        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_path); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_exists); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_GetSlice(__pyx_v_filename, 0, -4, NULL, NULL, &__pyx_slice__10, 0, 1, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = PyNumber_Add(__pyx_t_9, __pyx_kp_b_bai); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_11 = ((!__pyx_t_1) != 0);
        __pyx_t_1 = __pyx_t_11;
      } else {
        __pyx_t_1 = __pyx_t_2;
      }
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":504
 *                 if not os.path.exists(filename + b".bai") \
 *                         and not os.path.exists( filename[:-4] + b".bai"):
 *                     self.index = NULL             # <<<<<<<<<<<<<<
 *                 else:
 *                     # returns NULL if there is no index or index could not be opened
 */
        __pyx_v_self->index = NULL;
        goto __pyx_L38;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":507
 *                 else:
 *                     # returns NULL if there is no index or index could not be opened
 *                     self.index = hts_idx_load(filename, HTS_FMT_BAI)             # <<<<<<<<<<<<<<
 *                     if self.index == NULL:
 *                         raise IOError("error while opening index `%s` " % filename )
 */
        __pyx_t_26 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_26) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_self->index = hts_idx_load(__pyx_t_26, HTS_FMT_BAI);

        /* "pysam/csamfile.pyx":508
 *                     # returns NULL if there is no index or index could not be opened
 *                     self.index = hts_idx_load(filename, HTS_FMT_BAI)
 *                     if self.index == NULL:             # <<<<<<<<<<<<<<
 *                         raise IOError("error while opening index `%s` " % filename )
 *             else:
 */
        __pyx_t_1 = ((__pyx_v_self->index == NULL) != 0);
        if (__pyx_t_1) {

          /* "pysam/csamfile.pyx":509
 *                     self.index = hts_idx_load(filename, HTS_FMT_BAI)
 *                     if self.index == NULL:
 *                         raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
 *             else:
 *                 self.index = hts_idx_load(filename, HTS_FMT_BAI)
 */
          __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_error_while_opening_index_s, __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      __pyx_L38:;
      goto __pyx_L37;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":511
 *                         raise IOError("error while opening index `%s` " % filename )
 *             else:
 *                 self.index = hts_idx_load(filename, HTS_FMT_BAI)             # <<<<<<<<<<<<<<
 *                 if self.index == NULL:
 *                     warnings.warn("unable to open index for `%s` " % filename)
 */
      __pyx_t_26 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_26) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->index = hts_idx_load(__pyx_t_26, HTS_FMT_BAI);

      /* "pysam/csamfile.pyx":512
 *             else:
 *                 self.index = hts_idx_load(filename, HTS_FMT_BAI)
 *                 if self.index == NULL:             # <<<<<<<<<<<<<<
 *                     warnings.warn("unable to open index for `%s` " % filename)
 * 
 */
      __pyx_t_1 = ((__pyx_v_self->index == NULL) != 0);
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":513
 *                 self.index = hts_idx_load(filename, HTS_FMT_BAI)
 *                 if self.index == NULL:
 *                     warnings.warn("unable to open index for `%s` " % filename)             # <<<<<<<<<<<<<<
 * 
 *             if not self.isstream:
 */
        __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_warn); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_unable_to_open_index_for_s, __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L40;
      }
      __pyx_L40:;
    }
    __pyx_L37:;

    /* "pysam/csamfile.pyx":515
 *                     warnings.warn("unable to open index for `%s` " % filename)
 * 
 *             if not self.isstream:             # <<<<<<<<<<<<<<
 *                 self.start_offset = bgzf_tell(self.fp)
 * 
 */
    __pyx_t_1 = ((!(__pyx_v_self->isstream != 0)) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":516
 * 
 *             if not self.isstream:
 *                 self.start_offset = bgzf_tell(self.fp)             # <<<<<<<<<<<<<<
 * 
 *     def gettid( self, reference ):
 */
      __pyx_v_self->start_offset = bgzf_tell(__pyx_v_self->fp);
      goto __pyx_L41;
    }
    __pyx_L41:;
    goto __pyx_L36;
  }
  __pyx_L36:;

  /* "pysam/csamfile.pyx":327
 *         return self.index != NULL
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filename,
 *               mode=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.csamfile.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_bmode);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_ref);
  __Pyx_XDECREF(__pyx_v_filename);
  __Pyx_XDECREF(__pyx_v_referencenames);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":518
 *                 self.start_offset = bgzf_tell(self.fp)
 * 
 *     def gettid( self, reference ):             # <<<<<<<<<<<<<<
 *         '''
 *         convert :term:`reference` name into numerical :term:`tid`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_9gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_8gettid[] = "Samfile.gettid(self, reference)\n\n        convert :term:`reference` name into numerical :term:`tid`\n\n        returns -1 if reference is not known.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_9gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gettid (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_8gettid(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_8gettid(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  char const *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("gettid", 0);
  __Pyx_TraceCall("gettid", __pyx_f[0], 518);
  __Pyx_INCREF(__pyx_v_reference);

  /* "pysam/csamfile.pyx":524
 *         returns -1 if reference is not known.
 *         '''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 *         reference = _forceBytes(reference)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); 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_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __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 = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":525
 *         '''
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         reference = _forceBytes(reference)
 *         return bam_name2id(self.header, reference)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":526
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 *         reference = _forceBytes(reference)             # <<<<<<<<<<<<<<
 *         return bam_name2id(self.header, reference)
 * 
 */
  __pyx_t_2 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_reference); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":527
 *             raise ValueError( "I/O operation on closed file" )
 *         reference = _forceBytes(reference)
 *         return bam_name2id(self.header, reference)             # <<<<<<<<<<<<<<
 * 
 *     def getrname( self, tid ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int(bam_name2id(__pyx_v_self->header, __pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":518
 *                 self.start_offset = bgzf_tell(self.fp)
 * 
 *     def gettid( self, reference ):             # <<<<<<<<<<<<<<
 *         '''
 *         convert :term:`reference` name into numerical :term:`tid`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.gettid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_reference);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":529
 *         return bam_name2id(self.header, reference)
 * 
 *     def getrname( self, tid ):             # <<<<<<<<<<<<<<
 *         '''
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_11getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_10getrname[] = "Samfile.getrname(self, tid)\n\n        convert numerical :term:`tid` into :term:`reference` name.";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_11getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getrname (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_10getrname(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_10getrname(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getrname", 0);
  __Pyx_TraceCall("getrname", __pyx_f[0], 529);

  /* "pysam/csamfile.pyx":532
 *         '''
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 *         if not 0 <= tid < self.header.n_targets:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __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 = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":533
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":534
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 *         if not 0 <= tid < self.header.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets ) )
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
    __Pyx_DECREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); 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_2 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __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 = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = ((!__pyx_t_4) != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":536
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets ) )             # <<<<<<<<<<<<<<
 *         return _charptr_to_str(self.header.target_name[tid])
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_tid);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tid);
    __Pyx_GIVEREF(__pyx_v_tid);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/csamfile.pyx":535
 *             raise ValueError( "I/O operation on closed file" )
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %             # <<<<<<<<<<<<<<
 *                              (tid, self.header.n_targets ) )
 *         return _charptr_to_str(self.header.target_name[tid])
 */
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_tid_i_out_of_range_0_tid_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __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 = 535; __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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __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, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":537
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets ) )
 *         return _charptr_to_str(self.header.target_name[tid])             # <<<<<<<<<<<<<<
 * 
 *     cdef char * _getrname( self, int tid ): # TODO unused
 */
  __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 = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_5pysam_8csamfile__charptr_to_str((__pyx_v_self->header->target_name[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":529
 *         return bam_name2id(self.header, reference)
 * 
 *     def getrname( self, tid ):             # <<<<<<<<<<<<<<
 *         '''
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.getrname", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":539
 *         return _charptr_to_str(self.header.target_name[tid])
 * 
 *     cdef char * _getrname( self, int tid ): # TODO unused             # <<<<<<<<<<<<<<
 *         '''
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 */

static char *__pyx_f_5pysam_8csamfile_7Samfile__getrname(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, int __pyx_v_tid) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_getrname", 0);
  __Pyx_TraceCall("_getrname", __pyx_f[0], 539);

  /* "pysam/csamfile.pyx":542
 *         '''
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __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 = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":543
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         if not 0 <= tid < self.header.n_targets:
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":545
 *             raise ValueError("I/O operation on closed file")
 * 
 *         if not 0 <= tid < self.header.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets ))
 */
  __pyx_t_4 = (0 <= __pyx_v_tid);
  if (__pyx_t_4) {
    __pyx_t_4 = (__pyx_v_tid < __pyx_v_self->header->n_targets);
  }
  __pyx_t_3 = ((!(__pyx_t_4 != 0)) != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":547
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets ))             # <<<<<<<<<<<<<<
 *         return self.header.target_name[tid]
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 547; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 547; __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 = 547; __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_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = 0;
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":546
 * 
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %             # <<<<<<<<<<<<<<
 *                              (tid, self.header.n_targets ))
 *         return self.header.target_name[tid]
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_tid_i_out_of_range_0_tid_i, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__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 = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __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, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":548
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets ))
 *         return self.header.target_name[tid]             # <<<<<<<<<<<<<<
 * 
 *     def _parseRegion(self,
 */
  __pyx_r = (__pyx_v_self->header->target_name[__pyx_v_tid]);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":539
 *         return _charptr_to_str(self.header.target_name[tid])
 * 
 *     cdef char * _getrname( self, int tid ): # TODO unused             # <<<<<<<<<<<<<<
 *         '''
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("pysam.csamfile.Samfile._getrname", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":550
 *         return self.header.target_name[tid]
 * 
 *     def _parseRegion(self,             # <<<<<<<<<<<<<<
 *                      reference=None,
 *                      start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_13_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_12_parseRegion[] = "Samfile._parseRegion(self, reference=None, start=None, end=None, region=None, tid=None)\n\n        parse region information.\n\n        raise ValueError for for invalid regions.\n\n        returns a tuple of flag, tid, start and end. Flag indicates\n        whether some coordinates were supplied.\n\n        Note that regions are 1-based, while start,end are python coordinates.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_13_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;
  PyObject *__pyx_v_tid = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_parseRegion (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_tid,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysam/csamfile.pyx":551
 * 
 *     def _parseRegion(self,
 *                      reference=None,             # <<<<<<<<<<<<<<
 *                      start=None,
 *                      end=None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":552
 *     def _parseRegion(self,
 *                      reference=None,
 *                      start=None,             # <<<<<<<<<<<<<<
 *                      end=None,
 *                      region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":553
 *                      reference=None,
 *                      start=None,
 *                      end=None,             # <<<<<<<<<<<<<<
 *                      region=None,
 *                      tid=None):
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":554
 *                      start=None,
 *                      end=None,
 *                      region=None,             # <<<<<<<<<<<<<<
 *                      tid=None):
 *         '''
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":555
 *                      end=None,
 *                      region=None,
 *                      tid=None):             # <<<<<<<<<<<<<<
 *         '''
 *         parse region information.
 */
    values[4] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_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_tid);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_tid = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_parseRegion", 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("pysam.csamfile.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_12_parseRegion(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid);

  /* "pysam/csamfile.pyx":550
 *         return self.header.target_name[tid]
 * 
 *     def _parseRegion(self,             # <<<<<<<<<<<<<<
 *                      reference=None,
 *                      start=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_12_parseRegion(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid) {
  int __pyx_v_rtid;
  PY_LONG_LONG __pyx_v_rstart;
  PY_LONG_LONG __pyx_v_rend;
  PyObject *__pyx_v_parts = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PY_LONG_LONG __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  Py_ssize_t __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_parseRegion", 0);
  __Pyx_TraceCall("_parseRegion", __pyx_f[0], 550);
  __Pyx_INCREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_region);

  /* "pysam/csamfile.pyx":570
 *         cdef long long rend
 * 
 *         rtid = -1             # <<<<<<<<<<<<<<
 *         rstart = 0
 *         rend = max_pos
 */
  __pyx_v_rtid = -1;

  /* "pysam/csamfile.pyx":571
 * 
 *         rtid = -1
 *         rstart = 0             # <<<<<<<<<<<<<<
 *         rend = max_pos
 *         if start != None:
 */
  __pyx_v_rstart = 0;

  /* "pysam/csamfile.pyx":572
 *         rtid = -1
 *         rstart = 0
 *         rend = max_pos             # <<<<<<<<<<<<<<
 *         if start != None:
 *             try:
 */
  __pyx_v_rend = __pyx_v_5pysam_8csamfile_max_pos;

  /* "pysam/csamfile.pyx":573
 *         rstart = 0
 *         rend = max_pos
 *         if start != None:             # <<<<<<<<<<<<<<
 *             try:
 *                 rstart = start
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":574
 *         rend = max_pos
 *         if start != None:
 *             try:             # <<<<<<<<<<<<<<
 *                 rstart = start
 *             except OverflowError:
 */
    {
      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "pysam/csamfile.pyx":575
 *         if start != None:
 *             try:
 *                 rstart = start             # <<<<<<<<<<<<<<
 *             except OverflowError:
 *                 raise ValueError( 'start out of range (%i)' % start )
 */
        __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_start); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
        __pyx_v_rstart = __pyx_t_6;
      }
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L11_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":576
 *             try:
 *                 rstart = start
 *             except OverflowError:             # <<<<<<<<<<<<<<
 *                 raise ValueError( 'start out of range (%i)' % start )
 * 
 */
      __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
      if (__pyx_t_7) {
        __Pyx_AddTraceback("pysam.csamfile.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_9);

        /* "pysam/csamfile.pyx":577
 *                 rstart = start
 *             except OverflowError:
 *                 raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
 * 
 *         if end != None:
 */
        __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_start); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
        __Pyx_GOTREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_11, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_Raise(__pyx_t_10, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 577; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      __pyx_L11_try_end:;
    }
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":579
 *                 raise ValueError( 'start out of range (%i)' % start )
 * 
 *         if end != None:             # <<<<<<<<<<<<<<
 *             try:
 *                 rend = end
 */
  __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":580
 * 
 *         if end != None:
 *             try:             # <<<<<<<<<<<<<<
 *                 rend = end
 *             except OverflowError:
 */
    {
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_3);
      /*try:*/ {

        /* "pysam/csamfile.pyx":581
 *         if end != None:
 *             try:
 *                 rend = end             # <<<<<<<<<<<<<<
 *             except OverflowError:
 *                 raise ValueError( 'end out of range (%i)' % end )
 */
        __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_end); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
        __pyx_v_rend = __pyx_t_6;
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L22_try_end;
      __pyx_L15_error:;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "pysam/csamfile.pyx":582
 *             try:
 *                 rend = end
 *             except OverflowError:             # <<<<<<<<<<<<<<
 *                 raise ValueError( 'end out of range (%i)' % end )
 * 
 */
      __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
      if (__pyx_t_7) {
        __Pyx_AddTraceback("pysam.csamfile.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_1);

        /* "pysam/csamfile.pyx":583
 *                 rend = end
 *             except OverflowError:
 *                 raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
 * 
 *         if region:
 */
        __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
        __Pyx_GOTREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_11, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_Raise(__pyx_t_10, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L16_exception_handled;
      }
      goto __pyx_L17_except_error;
      __pyx_L17_except_error:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_4, __pyx_t_3);
      goto __pyx_L1_error;
      __pyx_L16_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_4, __pyx_t_3);
      __pyx_L22_try_end:;
    }
    goto __pyx_L14;
  }
  __pyx_L14:;

  /* "pysam/csamfile.pyx":585
 *                 raise ValueError( 'end out of range (%i)' % end )
 * 
 *         if region:             # <<<<<<<<<<<<<<
 *             region = _forceStr(region)
 *             parts = re.split("[:-]", region)
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":586
 * 
 *         if region:
 *             region = _forceStr(region)             # <<<<<<<<<<<<<<
 *             parts = re.split("[:-]", region)
 *             reference = parts[0]
 */
    __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceStr(__pyx_v_region); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":587
 *         if region:
 *             region = _forceStr(region)
 *             parts = re.split("[:-]", region)             # <<<<<<<<<<<<<<
 *             reference = parts[0]
 *             if len(parts) >= 2:
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __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 = 587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_kp_s__14);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s__14);
    __Pyx_GIVEREF(__pyx_kp_s__14);
    __Pyx_INCREF(__pyx_v_region);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_region);
    __Pyx_GIVEREF(__pyx_v_region);
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_parts = __pyx_t_9;
    __pyx_t_9 = 0;

    /* "pysam/csamfile.pyx":588
 *             region = _forceStr(region)
 *             parts = re.split("[:-]", region)
 *             reference = parts[0]             # <<<<<<<<<<<<<<
 *             if len(parts) >= 2:
 *                 rstart = int(parts[1]) - 1
 */
    __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pysam/csamfile.pyx":589
 *             parts = re.split("[:-]", region)
 *             reference = parts[0]
 *             if len(parts) >= 2:             # <<<<<<<<<<<<<<
 *                 rstart = int(parts[1]) - 1
 *             if len(parts) >= 3:
 */
    __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = ((__pyx_t_12 >= 2) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":590
 *             reference = parts[0]
 *             if len(parts) >= 2:
 *                 rstart = int(parts[1]) - 1             # <<<<<<<<<<<<<<
 *             if len(parts) >= 3:
 *                 rend = int(parts[2])
 */
      __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = PyNumber_Int(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyNumber_Subtract(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_9); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_rstart = __pyx_t_6;
      goto __pyx_L26;
    }
    __pyx_L26:;

    /* "pysam/csamfile.pyx":591
 *             if len(parts) >= 2:
 *                 rstart = int(parts[1]) - 1
 *             if len(parts) >= 3:             # <<<<<<<<<<<<<<
 *                 rend = int(parts[2])
 * 
 */
    __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = ((__pyx_t_12 >= 3) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":592
 *                 rstart = int(parts[1]) - 1
 *             if len(parts) >= 3:
 *                 rend = int(parts[2])             # <<<<<<<<<<<<<<
 * 
 *         if not reference:
 */
      __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = PyNumber_Int(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_rend = __pyx_t_6;
      goto __pyx_L27;
    }
    __pyx_L27:;
    goto __pyx_L25;
  }
  __pyx_L25:;

  /* "pysam/csamfile.pyx":594
 *                 rend = int(parts[2])
 * 
 *         if not reference:             # <<<<<<<<<<<<<<
 *             return 0, 0, 0, 0
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_13 = ((!__pyx_t_2) != 0);
  if (__pyx_t_13) {

    /* "pysam/csamfile.pyx":595
 * 
 *         if not reference:
 *             return 0, 0, 0, 0             # <<<<<<<<<<<<<<
 * 
 *         if tid is not None:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_tuple__15);
    __pyx_r = __pyx_tuple__15;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":597
 *             return 0, 0, 0, 0
 * 
 *         if tid is not None:             # <<<<<<<<<<<<<<
 *             rtid = tid
 *         else:
 */
  __pyx_t_13 = (__pyx_v_tid != Py_None);
  __pyx_t_2 = (__pyx_t_13 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":598
 * 
 *         if tid is not None:
 *             rtid = tid             # <<<<<<<<<<<<<<
 *         else:
 *             rtid = self.gettid(reference)
 */
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_tid); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_rtid = __pyx_t_7;
    goto __pyx_L29;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":600
 *             rtid = tid
 *         else:
 *             rtid = self.gettid(reference)             # <<<<<<<<<<<<<<
 * 
 *         if rtid < 0:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_gettid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_reference);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_reference);
    __Pyx_GIVEREF(__pyx_v_reference);
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_v_rtid = __pyx_t_7;
  }
  __pyx_L29:;

  /* "pysam/csamfile.pyx":602
 *             rtid = self.gettid(reference)
 * 
 *         if rtid < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "invalid reference `%s`" % reference)
 */
  __pyx_t_2 = ((__pyx_v_rtid < 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":604
 *         if rtid < 0:
 *             raise ValueError(
 *                 "invalid reference `%s`" % reference)             # <<<<<<<<<<<<<<
 *         if rstart > rend:
 *             raise ValueError(
 */
    __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_invalid_reference_s, __pyx_v_reference); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);

    /* "pysam/csamfile.pyx":603
 * 
 *         if rtid < 0:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "invalid reference `%s`" % reference)
 *         if rstart > rend:
 */
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":605
 *             raise ValueError(
 *                 "invalid reference `%s`" % reference)
 *         if rstart > rend:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend))
 */
  __pyx_t_2 = ((__pyx_v_rstart > __pyx_v_rend) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":607
 *         if rstart > rend:
 *             raise ValueError(
 *                 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend))             # <<<<<<<<<<<<<<
 *         if not 0 <= rstart < max_pos:
 *             raise ValueError('start out of range (%i)' % rstart)
 */
    __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = PyTuple_New(2); 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);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_8 = 0;
    __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_invalid_coordinates_start_i_end, __pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":606
 *                 "invalid reference `%s`" % reference)
 *         if rstart > rend:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend))
 *         if not 0 <= rstart < max_pos:
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_9, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":608
 *             raise ValueError(
 *                 'invalid coordinates: 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:
 */
  __pyx_t_2 = (0 <= __pyx_v_rstart);
  if (__pyx_t_2) {
    __pyx_t_2 = (__pyx_v_rstart < __pyx_v_5pysam_8csamfile_max_pos);
  }
  __pyx_t_13 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_13) {

    /* "pysam/csamfile.pyx":609
 *                 'invalid coordinates: 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_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":610
 *         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_13 = (0 <= __pyx_v_rend);
  if (__pyx_t_13) {
    __pyx_t_13 = (__pyx_v_rend <= __pyx_v_5pysam_8csamfile_max_pos);
  }
  __pyx_t_2 = ((!(__pyx_t_13 != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":611
 *             raise ValueError('start out of range (%i)' % rstart)
 *         if not 0 <= rend <= max_pos:
 *             raise ValueError('end out of range (%i)' % rend)             # <<<<<<<<<<<<<<
 * 
 *         return 1, rtid, rstart, rend
 */
    __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __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 = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_9, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":613
 *             raise ValueError('end out of range (%i)' % rend)
 * 
 *         return 1, rtid, rstart, rend             # <<<<<<<<<<<<<<
 * 
 *     def reset(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_9 = 0;
  __pyx_t_1 = 0;
  __pyx_t_8 = 0;
  __pyx_r = __pyx_t_10;
  __pyx_t_10 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":550
 *         return self.header.target_name[tid]
 * 
 *     def _parseRegion(self,             # <<<<<<<<<<<<<<
 *                      reference=None,
 *                      start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.csamfile.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_parts);
  __Pyx_XDECREF(__pyx_v_reference);
  __Pyx_XDECREF(__pyx_v_region);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":615
 *         return 1, rtid, rstart, rend
 * 
 *     def reset(self):             # <<<<<<<<<<<<<<
 *         '''reset file position to beginning of read section.'''
 *         return self.seek(self.start_offset, 0)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_14reset[] = "Samfile.reset(self)\nreset file position to beginning of read section.";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("reset (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_14reset(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_14reset(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("reset", 0);
  __Pyx_TraceCall("reset", __pyx_f[0], 615);

  /* "pysam/csamfile.pyx":617
 *     def reset(self):
 *         '''reset file position to beginning of read section.'''
 *         return self.seek(self.start_offset, 0)             # <<<<<<<<<<<<<<
 * 
 *     def seek(self, uint64_t offset, int where = 0):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seek); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_self->start_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __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 = 617; __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_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 617; __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_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":615
 *         return 1, rtid, rstart, rend
 * 
 *     def reset(self):             # <<<<<<<<<<<<<<
 *         '''reset file position to beginning of read section.'''
 *         return self.seek(self.start_offset, 0)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":619
 *         return self.seek(self.start_offset, 0)
 * 
 *     def seek(self, uint64_t offset, int where = 0):             # <<<<<<<<<<<<<<
 *         '''
 *         move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_17seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_16seek[] = "Samfile.seek(self, uint64_t offset, int where=0)\n\n        move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_17seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  uint64_t __pyx_v_offset;
  int __pyx_v_where;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("seek (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,&__pyx_n_s_where,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_offset)) != 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, pos_args, "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_offset = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[1]) {
      __pyx_v_where = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_where = ((int)0);
    }
  }
  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 = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.Samfile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_16seek(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_offset, __pyx_v_where);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_16seek(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, uint64_t __pyx_v_offset, int __pyx_v_where) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("seek", 0);
  __Pyx_TraceCall("seek", __pyx_f[0], 619);

  /* "pysam/csamfile.pyx":624
 *         '''
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __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 = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":625
 * 
 *         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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":626
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError("seek only available in bam files")
 *         if self.isstream:
 */
  __pyx_t_4 = ((!(__pyx_v_self->isbam != 0)) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":627
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
 *         if self.isstream:
 *             raise OSError("seek no available in streams")
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":628
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")
 *         if self.isstream:             # <<<<<<<<<<<<<<
 *             raise OSError("seek no available in streams")
 * 
 */
  __pyx_t_4 = (__pyx_v_self->isstream != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":629
 *             raise NotImplementedError("seek only available in bam files")
 *         if self.isstream:
 *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
 * 
 *         return bgzf_seek(self.fp, offset, where)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__18, 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_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":631
 *             raise OSError("seek no available in streams")
 * 
 *         return bgzf_seek(self.fp, offset, where)             # <<<<<<<<<<<<<<
 * 
 *     def tell(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_int64_t(bgzf_seek(__pyx_v_self->fp, __pyx_v_offset, __pyx_v_where)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":619
 *         return self.seek(self.start_offset, 0)
 * 
 *     def seek(self, uint64_t offset, int where = 0):             # <<<<<<<<<<<<<<
 *         '''
 *         move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":633
 *         return bgzf_seek(self.fp, offset, where)
 * 
 *     def tell(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return current file position
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_19tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_18tell[] = "Samfile.tell(self)\n\n        return current file position\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_19tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tell (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_18tell(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_18tell(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("tell", 0);
  __Pyx_TraceCall("tell", __pyx_f[0], 633);

  /* "pysam/csamfile.pyx":637
 *         return current file position
 *         '''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __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 = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":638
 *         '''
 *         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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, 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_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":639
 *         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 = ((!(__pyx_v_self->isbam != 0)) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":640
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
 * 
 *         return bgzf_tell(self.fp)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":642
 *             raise NotImplementedError("seek only available in bam files")
 * 
 *         return bgzf_tell(self.fp)             # <<<<<<<<<<<<<<
 * 
 *     def fetch(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_int64_t(bgzf_tell(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":633
 *         return bgzf_seek(self.fp, offset, where)
 * 
 *     def tell(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return current file position
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":644
 *         return bgzf_tell(self.fp)
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_21fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_20fetch[] = "Samfile.fetch(self, reference=None, start=None, end=None, region=None, tid=None, callback=None, until_eof=False, reopen=True)\nfetch aligned reads in a :term:`region` using 0-based indexing. The\n        region is specified by :term:`reference`, *start* and\n        *end*. Alternatively, a samtools :term:`region` string can be\n        supplied.\n\n        Without *reference* or *region* all mapped reads will be\n        fetched. The reads will be returned ordered by reference\n        sequence, which will not necessarily be the order within the\n        file.\n\n        If *until_eof* is given, all reads from the current file\n        position will be returned in order as they are within the\n        file. Using this option will also fetch unmapped reads.\n\n        If *reopen* is set to true, the iterator returned will receive\n        its own filehandle to the htsfile effectively opening its own\n        copy of the file. The default behaviour is to re-open in order\n        to safely work with multiple concurrent iterators on the same\n        file. Re-opening a htsfile creates some overhead, so when\n        using many calls to fetch() *reopen* can be set to False to\n        gain some speed. Also, the tell() method will only work if\n        *reopen* is set to False.\n\n        If only *reference* is set, all reads aligned to *reference*\n        will be fetched.\n\n        Note that a :term:`SAM` file does not allow random access. If\n        *region* or *reference* are given, an exception is raised.\n\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_21fetch(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_tid = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_until_eof = 0;
  PyObject *__pyx_v_reopen = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fetch (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_callback,&__pyx_n_s_until_eof,&__pyx_n_s_reopen,0};
    PyObject* values[8] = {0,0,0,0,0,0,0,0};

    /* "pysam/csamfile.pyx":645
 * 
 *     def fetch(self,
 *               reference=None,             # <<<<<<<<<<<<<<
 *               start=None,
 *               end=None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":646
 *     def fetch(self,
 *               reference=None,
 *               start=None,             # <<<<<<<<<<<<<<
 *               end=None,
 *               region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":647
 *               reference=None,
 *               start=None,
 *               end=None,             # <<<<<<<<<<<<<<
 *               region=None,
 *               tid=None,
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":648
 *               start=None,
 *               end=None,
 *               region=None,             # <<<<<<<<<<<<<<
 *               tid=None,
 *               callback=None,
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":649
 *               end=None,
 *               region=None,
 *               tid=None,             # <<<<<<<<<<<<<<
 *               callback=None,
 *               until_eof=False,
 */
    values[4] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":650
 *               region=None,
 *               tid=None,
 *               callback=None,             # <<<<<<<<<<<<<<
 *               until_eof=False,
 *               reopen=True):
 */
    values[5] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":651
 *               tid=None,
 *               callback=None,
 *               until_eof=False,             # <<<<<<<<<<<<<<
 *               reopen=True):
 *         '''fetch aligned reads in a :term:`region` using 0-based indexing. The
 */
    values[6] = ((PyObject *)Py_False);

    /* "pysam/csamfile.pyx":652
 *               callback=None,
 *               until_eof=False,
 *               reopen=True):             # <<<<<<<<<<<<<<
 *         '''fetch aligned reads in a :term:`region` using 0-based indexing. The
 *         region is specified by :term:`reference`, *start* and
 */
    values[7] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_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_tid);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_callback);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_until_eof);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[7] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_tid = values[4];
    __pyx_v_callback = values[5];
    __pyx_v_until_eof = values[6];
    __pyx_v_reopen = values[7];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.Samfile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_20fetch(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid, __pyx_v_callback, __pyx_v_until_eof, __pyx_v_reopen);

  /* "pysam/csamfile.pyx":644
 *         return bgzf_tell(self.fp)
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_20fetch(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_callback, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_reopen) {
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  int __pyx_v_has_coord;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("fetch", 0);
  __Pyx_TraceCall("fetch", __pyx_f[0], 644);
  __Pyx_INCREF(__pyx_v_reopen);

  /* "pysam/csamfile.pyx":685
 *         cdef int rtid, rstart, rend, has_coord
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); 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_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __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 = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":686
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(reference,
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":688
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(reference,             # <<<<<<<<<<<<<<
 *                                                           start,
 *                                                           end,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/csamfile.pyx":692
 *                                                           end,
 *                                                           region,
 *                                                           tid)             # <<<<<<<<<<<<<<
 * 
 *         # Turn of re-opening if htsfile is a stream
 */
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_reference);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
  __Pyx_GIVEREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  __Pyx_INCREF(__pyx_v_tid);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);

  /* "pysam/csamfile.pyx":688
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(reference,             # <<<<<<<<<<<<<<
 *                                                           start,
 *                                                           end,
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
    PyObject* sequence = __pyx_t_5;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_7);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_9(__pyx_t_8); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_has_coord = __pyx_t_10;
  __pyx_v_rtid = __pyx_t_11;
  __pyx_v_rstart = __pyx_t_12;
  __pyx_v_rend = __pyx_t_13;

  /* "pysam/csamfile.pyx":695
 * 
 *         # Turn of re-opening if htsfile is a stream
 *         if self.isstream:             # <<<<<<<<<<<<<<
 *             reopen = False
 * 
 */
  __pyx_t_4 = (__pyx_v_self->isstream != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":696
 *         # Turn of re-opening if htsfile is a stream
 *         if self.isstream:
 *             reopen = False             # <<<<<<<<<<<<<<
 * 
 *         if self.isbam:
 */
    __Pyx_INCREF(Py_False);
    __Pyx_DECREF_SET(__pyx_v_reopen, Py_False);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "pysam/csamfile.pyx":698
 *             reopen = False
 * 
 *         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_v_self->isbam != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":699
 * 
 *         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 = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = ((!__pyx_t_4) != 0);
    if (__pyx_t_3) {
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __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 = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_14 = ((!__pyx_t_4) != 0);
      if (__pyx_t_14) {
        __pyx_t_4 = ((!(__pyx_v_self->isremote != 0)) != 0);
        __pyx_t_15 = __pyx_t_4;
      } else {
        __pyx_t_15 = __pyx_t_14;
      }
      __pyx_t_14 = __pyx_t_15;
    } else {
      __pyx_t_14 = __pyx_t_3;
    }
    if (__pyx_t_14) {

      /* "pysam/csamfile.pyx":700
 *         if self.isbam:
 *             if not until_eof and not self._hasIndex() and not self.isremote:
 *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
 * 
 *             if has_coord:
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); 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_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":702
 *                 raise ValueError( "fetch called on bamfile without index" )
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorRowRegion(self, rtid, rstart, rend,
 *                                          reopen=reopen)
 */
    __pyx_t_14 = (__pyx_v_has_coord != 0);
    if (__pyx_t_14) {

      /* "pysam/csamfile.pyx":703
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(self, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                                          reopen=reopen)
 *             else:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rtid); 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_t_5 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_7 = 0;
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);

      /* "pysam/csamfile.pyx":704
 *             if has_coord:
 *                 return IteratorRowRegion(self, rtid, rstart, rend,
 *                                          reopen=reopen)             # <<<<<<<<<<<<<<
 *             else:
 *                 if until_eof:
 */
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reopen, __pyx_v_reopen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/csamfile.pyx":703
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(self, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                                          reopen=reopen)
 *             else:
 */
      __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowRegion)), __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_r = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L0;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":706
 *                                          reopen=reopen)
 *             else:
 *                 if until_eof:             # <<<<<<<<<<<<<<
 *                     return IteratorRowAll(self, reopen=reopen)
 *                 else:
 */
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_14) {

        /* "pysam/csamfile.pyx":707
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(self, reopen=reopen)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # AH: check - reason why no reopen for AllRefs?
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(((PyObject *)__pyx_v_self));
        PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
        __pyx_t_6 = PyDict_New(); 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);
        if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_reopen, __pyx_v_reopen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowAll)), __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_r = __pyx_t_2;
        __pyx_t_2 = 0;
        goto __pyx_L0;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":710
 *                 else:
 *                     # AH: check - reason why no reopen for AllRefs?
 *                     return IteratorRowAllRefs(self) # , reopen=reopen )             # <<<<<<<<<<<<<<
 *         else:
 *             if has_coord:
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(((PyObject *)__pyx_v_self));
        PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
        __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowAllRefs)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_6;
        __pyx_t_6 = 0;
        goto __pyx_L0;
      }
    }
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":712
 *                     return IteratorRowAllRefs(self) # , reopen=reopen )
 *         else:
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 raise ValueError ("fetching by region is not available for sam files")
 * 
 */
    __pyx_t_14 = (__pyx_v_has_coord != 0);
    if (__pyx_t_14) {

      /* "pysam/csamfile.pyx":713
 *         else:
 *             if has_coord:
 *                 raise ValueError ("fetching by region is not available for sam files")             # <<<<<<<<<<<<<<
 * 
 *             if callback:
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":715
 *                 raise ValueError ("fetching by region is not available for sam files")
 * 
 *             if callback:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError("callback not implemented yet")
 * 
 */
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_14) {

      /* "pysam/csamfile.pyx":716
 * 
 *             if callback:
 *                 raise NotImplementedError("callback not implemented yet")             # <<<<<<<<<<<<<<
 * 
 *             if self.header == NULL:
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":718
 *                 raise NotImplementedError("callback not implemented yet")
 * 
 *             if self.header == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError("fetch called for htsfile without header")
 * 
 */
    __pyx_t_14 = ((__pyx_v_self->header == NULL) != 0);
    if (__pyx_t_14) {

      /* "pysam/csamfile.pyx":719
 * 
 *             if self.header == NULL:
 *                 raise ValueError("fetch called for htsfile without header")             # <<<<<<<<<<<<<<
 * 
 *             # check if targets are defined
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":723
 *             # check if targets are defined
 *             # give warning, sam_read1 segfaults
 *             if self.header.n_targets == 0:             # <<<<<<<<<<<<<<
 *                 warnings.warn("fetch called for htsfile without header")
 * 
 */
    __pyx_t_14 = ((__pyx_v_self->header->n_targets == 0) != 0);
    if (__pyx_t_14) {

      /* "pysam/csamfile.pyx":724
 *             # give warning, sam_read1 segfaults
 *             if self.header.n_targets == 0:
 *                 warnings.warn("fetch called for htsfile without header")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorRowAll(self, reopen=reopen)
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __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_6); __pyx_t_6 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "pysam/csamfile.pyx":726
 *                 warnings.warn("fetch called for htsfile without header")
 * 
 *             return IteratorRowAll(self, reopen=reopen)             # <<<<<<<<<<<<<<
 * 
 *     def head(self, n):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(1); 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_INCREF(((PyObject *)__pyx_v_self));
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    __pyx_t_2 = PyDict_New(); 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);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reopen, __pyx_v_reopen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowAll)), __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":644
 *         return bgzf_tell(self.fp)
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

  /* function exit code */
  __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_8);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_reopen);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":728
 *             return IteratorRowAll(self, reopen=reopen)
 * 
 *     def head(self, n):             # <<<<<<<<<<<<<<
 *         '''
 *         return iterator over the first n alignments.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_23head(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_22head[] = "Samfile.head(self, n)\n\n        return iterator over the first n alignments. \n\n        This is useful for inspecting the bam-file.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_23head(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("head (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_22head(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), ((PyObject *)__pyx_v_n));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_22head(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_n) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("head", 0);
  __Pyx_TraceCall("head", __pyx_f[0], 728);

  /* "pysam/csamfile.pyx":734
 *         This is useful for inspecting the bam-file.
 *         '''
 *         return IteratorRowHead(self, n)             # <<<<<<<<<<<<<<
 * 
 *     def mate(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(__pyx_v_n);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_n);
  __Pyx_GIVEREF(__pyx_v_n);
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowHead)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":728
 *             return IteratorRowAll(self, reopen=reopen)
 * 
 *     def head(self, n):             # <<<<<<<<<<<<<<
 *         '''
 *         return iterator over the first n alignments.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.head", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":736
 *         return IteratorRowHead(self, n)
 * 
 *     def mate(self,             # <<<<<<<<<<<<<<
 *              AlignedRead read):
 *         '''return the mate of :class:`AlignedRead` *read*.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_25mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_24mate[] = "Samfile.mate(self, AlignedRead read)\nreturn the mate of :class:`AlignedRead` *read*.\n\n        Throws a ValueError if read is unpaired or the mate\n        is unmapped.\n\n        .. note::\n\n            Calling this method will change the file position.\n            This might interfere with any iterators that have\n            not re-opened the file.\n\n        .. note::\n  \n           This method is too slow for high-throughput processing.\n           If a read needs to be processed with its mate, work\n           from a read name sorted file or, better, cache reads.\n\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_25mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mate (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_8csamfile_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_24mate(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_read));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_24mate(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_read) {
  uint32_t __pyx_v_flag;
  int __pyx_v_x;
  PyObject *__pyx_v_mate = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("mate", 0);
  __Pyx_TraceCall("mate", __pyx_f[0], 736);

  /* "pysam/csamfile.pyx":756
 * 
 *         '''
 *         cdef uint32_t flag = read._delegate.core.flag             # <<<<<<<<<<<<<<
 * 
 *         if flag & BAM_FPAIRED == 0:
 */
  __pyx_t_1 = __pyx_v_read->_delegate->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysam/csamfile.pyx":758
 *         cdef uint32_t flag = read._delegate.core.flag
 * 
 *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("read %s: is unpaired" % (read.qname))
 *         if flag & BAM_FMUNMAP != 0:
 */
  __pyx_t_2 = (((__pyx_v_flag & BAM_FPAIRED) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":759
 * 
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" % (read.qname))             # <<<<<<<<<<<<<<
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" % (read.qname))
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_qname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_read_s_is_unpaired, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __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 = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":760
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" % (read.qname))
 *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("mate %s: is unmapped" % (read.qname))
 * 
 */
  __pyx_t_2 = (((__pyx_v_flag & BAM_FMUNMAP) != 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":761
 *             raise ValueError("read %s: is unpaired" % (read.qname))
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" % (read.qname))             # <<<<<<<<<<<<<<
 * 
 *         # xor flags to get the other mate
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_mate_s_is_unmapped, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __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 = 761; __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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __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, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":764
 * 
 *         # xor flags to get the other mate
 *         cdef int x = BAM_FREAD1 + BAM_FREAD2             # <<<<<<<<<<<<<<
 *         flag = (flag ^ x) & x
 * 
 */
  __pyx_v_x = (BAM_FREAD1 + BAM_FREAD2);

  /* "pysam/csamfile.pyx":765
 *         # xor flags to get the other mate
 *         cdef int x = BAM_FREAD1 + BAM_FREAD2
 *         flag = (flag ^ x) & x             # <<<<<<<<<<<<<<
 * 
 *         # the following code is not using the C API and
 */
  __pyx_v_flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x);

  /* "pysam/csamfile.pyx":769
 *         # the following code is not using the C API and
 *         # could thus be made much quicker
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/csamfile.pyx":770
 *         # could thus be made much quicker
 *         for mate in self.fetch(
 *                 read._delegate.core.mpos,             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid):
 */
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mpos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/csamfile.pyx":771
 *         for mate in self.fetch(
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,             # <<<<<<<<<<<<<<
 *                 tid=read._delegate.core.mtid):
 *             if mate.flag & flag != 0 and \
 */
  __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_v_read->_delegate->core.mpos + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/csamfile.pyx":769
 *         # the following code is not using the C API and
 *         # could thus be made much quicker
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/csamfile.pyx":772
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid):             # <<<<<<<<<<<<<<
 *             if mate.flag & flag != 0 and \
 *                mate.qname == read.qname:
 */
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":769
 *         # the following code is not using the C API and
 *         # could thus be made much quicker
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_5)) {
      if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_5)) {
      if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_4 = __pyx_t_8(__pyx_t_5);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_mate, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":773
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.qname == read.qname:
 *                 break
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_flag); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_flag); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyNumber_And(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __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_6 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":774
 *                 tid=read._delegate.core.mtid):
 *             if mate.flag & flag != 0 and \
 *                mate.qname == read.qname:             # <<<<<<<<<<<<<<
 *                 break
 *         else:
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_qname); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_qname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_10 = __pyx_t_9;
    } else {
      __pyx_t_10 = __pyx_t_2;
    }
    if (__pyx_t_10) {

      /* "pysam/csamfile.pyx":775
 *             if mate.flag & flag != 0 and \
 *                mate.qname == read.qname:
 *                 break             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("mate not found")
 */
      goto __pyx_L6_break;
    }
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":777
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L6_break:;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysam/csamfile.pyx":779
 *             raise ValueError("mate not found")
 * 
 *         return mate             # <<<<<<<<<<<<<<
 * 
 *     def count(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_mate);
  __pyx_r = __pyx_v_mate;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":736
 *         return IteratorRowHead(self, n)
 * 
 *     def mate(self,             # <<<<<<<<<<<<<<
 *              AlignedRead read):
 *         '''return the mate of :class:`AlignedRead` *read*.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.mate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mate);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":781
 *         return mate
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_27count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_26count[] = "Samfile.count(self, reference=None, start=None, end=None, region=None, until_eof=False)\n*(reference = None, start = None, end = None,\n        region = None, callback = None, until_eof = False)*\n\n        count reads :term:`region` using 0-based indexing. The region\n        is specified by :term:`reference`, *start* and\n        *end*. Alternatively, a samtools :term:`region` string can be\n        supplied.\n\n        Note that a :term:`TAM` file does not allow random access. If\n        *region* or *reference* are given, an exception is raised.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_27count(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_until_eof = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("count (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_until_eof,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysam/csamfile.pyx":782
 * 
 *     def count(self,
 *               reference=None,             # <<<<<<<<<<<<<<
 *               start=None,
 *               end=None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":783
 *     def count(self,
 *               reference=None,
 *               start=None,             # <<<<<<<<<<<<<<
 *               end=None,
 *               region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":784
 *               reference=None,
 *               start=None,
 *               end=None,             # <<<<<<<<<<<<<<
 *               region=None,
 *               until_eof=False):
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":785
 *               start=None,
 *               end=None,
 *               region=None,             # <<<<<<<<<<<<<<
 *               until_eof=False):
 *         '''*(reference = None, start = None, end = None,
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":786
 *               end=None,
 *               region=None,
 *               until_eof=False):             # <<<<<<<<<<<<<<
 *         '''*(reference = None, start = None, end = None,
 *         region = None, callback = None, until_eof = False)*
 */
    values[4] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_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_until_eof);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_until_eof = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.Samfile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_26count(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_until_eof);

  /* "pysam/csamfile.pyx":781
 *         return mate
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_26count(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof) {
  CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_read = 0;
  long __pyx_v_counter;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("count", 0);
  __Pyx_TraceCall("count", __pyx_f[0], 781);

  /* "pysam/csamfile.pyx":799
 *         '''
 *         cdef AlignedRead read
 *         cdef long counter = 0             # <<<<<<<<<<<<<<
 * 
 *         if not self._isOpen():
 */
  __pyx_v_counter = 0;

  /* "pysam/csamfile.pyx":801
 *         cdef long counter = 0
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 801; __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 = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":802
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         for read in self.fetch(reference=reference,
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); 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_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":804
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         for read in self.fetch(reference=reference,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                end=end,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reference, __pyx_v_reference) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":805
 * 
 *         for read in self.fetch(reference=reference,
 *                                start=start,             # <<<<<<<<<<<<<<
 *                                end=end,
 *                                region=region,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":806
 *         for read in self.fetch(reference=reference,
 *                                start=start,
 *                                end=end,             # <<<<<<<<<<<<<<
 *                                region=region,
 *                                until_eof=until_eof):
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_end, __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":807
 *                                start=start,
 *                                end=end,
 *                                region=region,             # <<<<<<<<<<<<<<
 *                                until_eof=until_eof):
 *             counter += 1
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_region, __pyx_v_region) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":808
 *                                end=end,
 *                                region=region,
 *                                until_eof=until_eof):             # <<<<<<<<<<<<<<
 *             counter += 1
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_until_eof, __pyx_v_until_eof) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":804
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         for read in self.fetch(reference=reference,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                end=end,
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_5) || PyTuple_CheckExact(__pyx_t_5)) {
    __pyx_t_1 = __pyx_t_5; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_5 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_8csamfile_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "pysam/csamfile.pyx":809
 *                                region=region,
 *                                until_eof=until_eof):
 *             counter += 1             # <<<<<<<<<<<<<<
 * 
 *         return counter
 */
    __pyx_v_counter = (__pyx_v_counter + 1);
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":811
 *             counter += 1
 * 
 *         return counter             # <<<<<<<<<<<<<<
 * 
 *     def pileup( self,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":781
 *         return mate
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_read);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":813
 *         return counter
 * 
 *     def pileup( self,             # <<<<<<<<<<<<<<
 *                 reference = None,
 *                 start = None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_29pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_28pileup[] = "Samfile.pileup(self, reference=None, start=None, end=None, region=None, **kwargs)\n\n        perform a :term:`pileup` within a :term:`region`. The region is specified by\n        :term:`reference`, *start* and *end* (using 0-based indexing).\n        Alternatively, a samtools *region* string can be supplied.\n\n        Without *reference* or *region* all reads will be used for the pileup. 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 a *callback* is given, the callback will be executed\n        for each column within the :term:`region`.\n\n        Note that :term:`SAM` formatted files do not allow random access.\n        In these files, if a *region* or *reference* are given an exception is raised.\n\n        Optional *kwargs* to the iterator:\n\n        stepper\n           The stepper controlls how the iterator advances.\n           Possible options for the stepper are\n\n           ``all``\n              use all reads for pileup.\n           ``samtools``\n              same filter and read processing as in :term:`csamtools` pileup\n\n        fastafile\n           A :class:`FastaFile` object\n\n         mask\n           Skip all reads with bits set in mask if mask=True.\n\n         max_depth\n           Maximum read depth permitted. The default limit is *8000*.\n\n         truncate\n           By default, the samtools pileup engine outputs all reads overlapping a region (see note below).\n           If truncate is True and a region is given, only output columns in the exact region\n           specificied.\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\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_29pileup(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_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("pileup (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pysam/csamfile.pyx":814
 * 
 *     def pileup( self,
 *                 reference = None,             # <<<<<<<<<<<<<<
 *                 start = None,
 *                 end = None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":815
 *     def pileup( self,
 *                 reference = None,
 *                 start = None,             # <<<<<<<<<<<<<<
 *                 end = None,
 *                 region = None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":816
 *                 reference = None,
 *                 start = None,
 *                 end = None,             # <<<<<<<<<<<<<<
 *                 region = None,
 *                 **kwargs ):
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":817
 *                 start = None,
 *                 end = None,
 *                 region = None,             # <<<<<<<<<<<<<<
 *                 **kwargs ):
 *         '''
 */
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_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, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.csamfile.Samfile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_28pileup(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_kwargs);

  /* "pysam/csamfile.pyx":813
 *         return counter
 * 
 *     def pileup( self,             # <<<<<<<<<<<<<<
 *                 reference = None,
 *                 start = None,
 */

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_28pileup(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_kwargs) {
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  int __pyx_v_has_coord;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("pileup", 0);
  __Pyx_TraceCall("pileup", __pyx_f[0], 813);

  /* "pysam/csamfile.pyx":867
 *         cdef int rtid, rstart, rend, has_coord
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __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 = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":868
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":870
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(             # <<<<<<<<<<<<<<
 *             reference, start, end, region )
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/csamfile.pyx":871
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(
 *             reference, start, end, region )             # <<<<<<<<<<<<<<
 * 
 *         if self.isbam:
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_reference);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
  __Pyx_GIVEREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);

  /* "pysam/csamfile.pyx":870
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(             # <<<<<<<<<<<<<<
 *             reference, start, end, region )
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
    PyObject* sequence = __pyx_t_5;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_7);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_1,&__pyx_t_2,&__pyx_t_6,&__pyx_t_7};
    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_9(__pyx_t_8); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_has_coord = __pyx_t_10;
  __pyx_v_rtid = __pyx_t_11;
  __pyx_v_rstart = __pyx_t_12;
  __pyx_v_rend = __pyx_t_13;

  /* "pysam/csamfile.pyx":873
 *             reference, start, end, region )
 * 
 *         if self.isbam:             # <<<<<<<<<<<<<<
 *             if not self._hasIndex():
 *                 raise ValueError("no index available for pileup")
 */
  __pyx_t_4 = (__pyx_v_self->isbam != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":874
 * 
 *         if self.isbam:
 *             if not self._hasIndex():             # <<<<<<<<<<<<<<
 *                 raise ValueError("no index available for pileup")
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __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 = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_3 = ((!__pyx_t_4) != 0);
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":875
 *         if self.isbam:
 *             if not self._hasIndex():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             if has_coord:
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":877
 *                 raise ValueError("no index available for pileup")
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorColumnRegion(self,
 *                                             tid = rtid,
 */
    __pyx_t_3 = (__pyx_v_has_coord != 0);
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":878
 * 
 *             if has_coord:
 *                 return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                             tid = rtid,
 *                                             start = rstart,
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));

      /* "pysam/csamfile.pyx":882
 *                                             start = rstart,
 *                                             end = rend,
 *                                             **kwargs )             # <<<<<<<<<<<<<<
 *             else:
 *                 return IteratorColumnAllRefs(self, **kwargs )
 */
      __pyx_t_5 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);

      /* "pysam/csamfile.pyx":879
 *             if has_coord:
 *                 return IteratorColumnRegion(self,
 *                                             tid = rtid,             # <<<<<<<<<<<<<<
 *                                             start = rstart,
 *                                             end = rend,
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_tid))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_tid); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":880
 *                 return IteratorColumnRegion(self,
 *                                             tid = rtid,
 *                                             start = rstart,             # <<<<<<<<<<<<<<
 *                                             end = rend,
 *                                             **kwargs )
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_start))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_start); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_start, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":881
 *                                             tid = rtid,
 *                                             start = rstart,
 *                                             end = rend,             # <<<<<<<<<<<<<<
 *                                             **kwargs )
 *             else:
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      if (unlikely(PyDict_GetItem(__pyx_t_5, __pyx_n_s_end))) {
        __Pyx_RaiseDoubleKeywordsError("function", __pyx_n_s_end); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":878
 * 
 *             if has_coord:
 *                 return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                             tid = rtid,
 *                                             start = rstart,
 */
      __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorColumnRegion)), __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":884
 *                                             **kwargs )
 *             else:
 *                 return IteratorColumnAllRefs(self, **kwargs )             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      __pyx_t_5 = __pyx_v_kwargs;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorColumnAllRefs)), __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __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_5); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;
    }
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":887
 * 
 *         else:
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
 * 
 *     def close( self ):
 */
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_Raise(__pyx_t_7, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":813
 *         return counter
 * 
 *     def pileup( self,             # <<<<<<<<<<<<<<
 *                 reference = None,
 *                 start = None,
 */

  /* function exit code */
  __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_8);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":889
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         '''
 *         closes the :class:`pysam.Samfile`.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_31close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_30close[] = "Samfile.close(self)\n\n        closes the :class:`pysam.Samfile`.";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_31close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_30close(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_30close(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("close", 0);
  __Pyx_TraceCall("close", __pyx_f[0], 889);

  /* "pysam/csamfile.pyx":892
 *         '''
 *         closes the :class:`pysam.Samfile`.'''
 *         if self.htsfile != NULL:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 *             hts_idx_destroy(self.index);
 */
  __pyx_t_1 = ((__pyx_v_self->htsfile != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":893
 *         closes the :class:`pysam.Samfile`.'''
 *         if self.htsfile != NULL:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index);
 *             self.htsfile = NULL
 */
    hts_close(__pyx_v_self->htsfile);

    /* "pysam/csamfile.pyx":894
 *         if self.htsfile != NULL:
 *             hts_close(self.htsfile)
 *             hts_idx_destroy(self.index);             # <<<<<<<<<<<<<<
 *             self.htsfile = NULL
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/csamfile.pyx":895
 *             hts_close(self.htsfile)
 *             hts_idx_destroy(self.index);
 *             self.htsfile = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__( self ):
 */
    __pyx_v_self->htsfile = NULL;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":889
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )
 * 
 *     def close( self ):             # <<<<<<<<<<<<<<
 *         '''
 *         closes the :class:`pysam.Samfile`.'''
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":897
 *             self.htsfile = NULL
 * 
 *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
 *         # remember: dealloc cannot call other methods
 *         # note: no doc string
 */

/* Python wrapper */
static void __pyx_pw_5pysam_8csamfile_7Samfile_33__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_8csamfile_7Samfile_33__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_8csamfile_7Samfile_32__dealloc__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_8csamfile_7Samfile_32__dealloc__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 897);

  /* "pysam/csamfile.pyx":901
 *         # note: no doc string
 *         # note: __del__ is not called.
 *         self.close()             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.header != NULL:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __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;

  /* "pysam/csamfile.pyx":902
 *         # note: __del__ is not called.
 *         self.close()
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         if self.header != NULL:
 *             bam_hdr_destroy(self.header)
 */
  bam_destroy1(__pyx_v_self->b);

  /* "pysam/csamfile.pyx":903
 *         self.close()
 *         bam_destroy1(self.b)
 *         if self.header != NULL:             # <<<<<<<<<<<<<<
 *             bam_hdr_destroy(self.header)
 * 
 */
  __pyx_t_3 = ((__pyx_v_self->header != NULL) != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":904
 *         bam_destroy1(self.b)
 *         if self.header != NULL:
 *             bam_hdr_destroy(self.header)             # <<<<<<<<<<<<<<
 * 
 *     cpdef int write( self, AlignedRead read ) except -1:
 */
    bam_hdr_destroy(__pyx_v_self->header);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":897
 *             self.htsfile = NULL
 * 
 *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
 *         # remember: dealloc cannot call other methods
 *         # note: no doc string
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("pysam.csamfile.Samfile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/csamfile.pyx":906
 *             bam_hdr_destroy(self.header)
 * 
 *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedRead` to disk.
 */

static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_35write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static int __pyx_f_5pysam_8csamfile_7Samfile_write(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_read, int __pyx_skip_dispatch) {
  int __pyx_v_x;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("write", 0);
  __Pyx_TraceCall("write", __pyx_f[0], 906);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_35write)) {
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(((PyObject *)__pyx_v_read));
      PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_read));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_read));
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_4;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/csamfile.pyx":912
 *         returns the number of bytes written.
 *         '''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":913
 *         '''
 *         if not self._isOpen():
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         x = sam_write1(self.htsfile,
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":915
 *             return 0
 * 
 *         x = sam_write1(self.htsfile,             # <<<<<<<<<<<<<<
 *                        self.header,
 *                        read._delegate)
 */
  __pyx_v_x = sam_write1(__pyx_v_self->htsfile, __pyx_v_self->header, __pyx_v_read->_delegate);

  /* "pysam/csamfile.pyx":919
 *                        read._delegate)
 * 
 *         return x             # <<<<<<<<<<<<<<
 * 
 *     def __enter__(self):
 */
  __pyx_r = __pyx_v_x;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":906
 *             bam_hdr_destroy(self.header)
 * 
 *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedRead` to disk.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysam.csamfile.Samfile.write", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_35write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_34write[] = "Samfile.write(self, AlignedRead read) -> int\n\n        write a single :class:`pysam.AlignedRead` to disk.\n\n        returns the number of bytes written.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_35write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_8csamfile_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_34write(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_read));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_34write(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_read) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("write", 0);
  __Pyx_TraceCall("write", __pyx_f[0], 906);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_5pysam_8csamfile_Samfile *)__pyx_v_self->__pyx_vtab)->write(__pyx_v_self, __pyx_v_read, 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":921
 *         return x
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_37__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_36__enter__[] = "Samfile.__enter__(self)";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_37__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_36__enter__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_36__enter__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__enter__", 0);
  __Pyx_TraceCall("__enter__", __pyx_f[0], 921);

  /* "pysam/csamfile.pyx":922
 * 
 *     def __enter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":921
 *         return x
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":924
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_39__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_38__exit__[] = "Samfile.__exit__(self, exc_type, exc_value, traceback)";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_39__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0;
  CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0;
  CYTHON_UNUSED PyObject *__pyx_v_traceback = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_value,&__pyx_n_s_traceback,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_exc_type = values[0];
    __pyx_v_exc_value = values[1];
    __pyx_v_traceback = values[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 = 924; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.Samfile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_38__exit__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_38__exit__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__exit__", 0);
  __Pyx_TraceCall("__exit__", __pyx_f[0], 924);

  /* "pysam/csamfile.pyx":925
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()             # <<<<<<<<<<<<<<
 *         return False
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __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;

  /* "pysam/csamfile.pyx":926
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()
 *         return False             # <<<<<<<<<<<<<<
 * 
 *     ###############################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_False);
  __pyx_r = Py_False;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":924
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":935
 *     property filename:
 *         '''number of :term:`filename` associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_8filename_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_8filename_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_8filename___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_8filename___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 935);

  /* "pysam/csamfile.pyx":936
 *         '''number of :term:`filename` associated with this object.'''
 *         def __get__(self):
 *             return self._filename             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->_filename);
  __pyx_r = __pyx_v_self->_filename;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":935
 *     property filename:
 *         '''number of :term:`filename` associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":940
 *     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.header.n_targets
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_11nreferences_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_11nreferences___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_11nreferences___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 940);

  /* "pysam/csamfile.pyx":941
 *         '''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.header.n_targets
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __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 = __Pyx_PyObject_Call(__pyx_t_1, __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) != 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__32, 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_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":942
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             return self.header.n_targets             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); 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_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":940
 *     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.header.n_targets
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":946
 *     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 = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_10references_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_10references___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_10references___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 946);

  /* "pysam/csamfile.pyx":947
 *         """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.header.n_targets:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __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 = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

  /* "pysam/csamfile.pyx":949
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                 t.append(_charptr_to_str(self.header.target_name[x]))
 *             return tuple(t)
 */
  __pyx_t_5 = __pyx_v_self->header->n_targets;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {

    /* "pysam/csamfile.pyx":950
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 *                 t.append(_charptr_to_str(self.header.target_name[x]))             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    __pyx_t_2 = __pyx_f_5pysam_8csamfile__charptr_to_str((__pyx_v_self->header->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  /* "pysam/csamfile.pyx":951
 *             for x from 0 <= x < self.header.n_targets:
 *                 t.append(_charptr_to_str(self.header.target_name[x]))
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":946
 *     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 = []
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":957
 *         :attr:`pysam.Samfile.references`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_7lengths_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_7lengths___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_7lengths___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 957);

  /* "pysam/csamfile.pyx":958
 *         """
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __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 = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

    /* "pysam/csamfile.pyx":961
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 *                 t.append( self.header.target_len[x] )             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->header->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  /* "pysam/csamfile.pyx":962
 *             for x from 0 <= x < self.header.n_targets:
 *                 t.append( self.header.target_len[x] )
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     property mapped:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":957
 *         :attr:`pysam.Samfile.references`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             t = []
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":967
 *         """total number of mapped alignments in file.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_6mapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_6mapped___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_6mapped___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  int __pyx_v_tid;
  uint64_t __pyx_v_total;
  uint64_t __pyx_v_mapped;
  uint64_t __pyx_v_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int32_t __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 967);

  /* "pysam/csamfile.pyx":968
 *         """
 *         def __get__(self):
 *             self._checkIndex()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = 0
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_checkIndex); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __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;

  /* "pysam/csamfile.pyx":970
 *             self._checkIndex()
 *             cdef int tid
 *             cdef uint64_t total = 0             # <<<<<<<<<<<<<<
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.n_targets:
 */
  __pyx_v_total = 0;

  /* "pysam/csamfile.pyx":972
 *             cdef uint64_t total = 0
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 */
  __pyx_t_3 = __pyx_v_self->header->n_targets;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_3; __pyx_v_tid++) {

    /* "pysam/csamfile.pyx":973
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.n_targets:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *                 total += mapped
 *             return total
 */
    hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped));

    /* "pysam/csamfile.pyx":974
 *             for tid from 0 <= tid < self.header.n_targets:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped             # <<<<<<<<<<<<<<
 *             return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + __pyx_v_mapped);
  }

  /* "pysam/csamfile.pyx":975
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 *             return total             # <<<<<<<<<<<<<<
 * 
 *     def _checkIndex(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":967
 *         """total number of mapped alignments in file.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.mapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":977
 *             return total
 * 
 *     def _checkIndex(self):             # <<<<<<<<<<<<<<
 *         '''check if index is present. Otherwise raise
 *         an error.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_41_checkIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_40_checkIndex[] = "Samfile._checkIndex(self)\ncheck if index is present. Otherwise raise\n        an error.";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_41_checkIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_checkIndex (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_40_checkIndex(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_40_checkIndex(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_checkIndex", 0);
  __Pyx_TraceCall("_checkIndex", __pyx_f[0], 977);

  /* "pysam/csamfile.pyx":980
 *         '''check if index is present. Otherwise raise
 *         an error.'''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.isbam:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 980; __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 = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":981
 *         an error.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.isbam:
 *             raise AttributeError("Samfile.mapped only available in bam files")
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":982
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")
 *         if not self.isbam:             # <<<<<<<<<<<<<<
 *             raise AttributeError("Samfile.mapped only available in bam files")
 *         if self.index == NULL:
 */
  __pyx_t_4 = ((!(__pyx_v_self->isbam != 0)) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":983
 *             raise ValueError("I/O operation on closed file")
 *         if not self.isbam:
 *             raise AttributeError("Samfile.mapped only available in bam files")             # <<<<<<<<<<<<<<
 *         if self.index == NULL:
 *             raise ValueError("mapping information not recorded in index "
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":984
 *         if not self.isbam:
 *             raise AttributeError("Samfile.mapped only available in bam files")
 *         if self.index == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError("mapping information not recorded in index "
 *                                  "or index not available")
 */
  __pyx_t_4 = ((__pyx_v_self->index == NULL) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":985
 *             raise AttributeError("Samfile.mapped only available in bam files")
 *         if self.index == NULL:
 *             raise ValueError("mapping information not recorded in index "             # <<<<<<<<<<<<<<
 *                                  "or index not available")
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":977
 *             return total
 * 
 *     def _checkIndex(self):             # <<<<<<<<<<<<<<
 *         '''check if index is present. Otherwise raise
 *         an error.'''
 */

  /* function exit code */
  __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("pysam.csamfile.Samfile._checkIndex", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":992
 *         """total number of unmapped reads in file.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_8unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_8unmapped___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_8unmapped___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  int __pyx_v_tid;
  uint64_t __pyx_v_total;
  uint64_t __pyx_v_mapped;
  uint64_t __pyx_v_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int32_t __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 992);

  /* "pysam/csamfile.pyx":993
 *         """
 *         def __get__(self):
 *             self._checkIndex()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = 0
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_checkIndex); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __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;

  /* "pysam/csamfile.pyx":995
 *             self._checkIndex()
 *             cdef int tid
 *             cdef uint64_t total = 0             # <<<<<<<<<<<<<<
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.n_targets:
 */
  __pyx_v_total = 0;

  /* "pysam/csamfile.pyx":997
 *             cdef uint64_t total = 0
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 */
  __pyx_t_3 = __pyx_v_self->header->n_targets;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_3; __pyx_v_tid++) {

    /* "pysam/csamfile.pyx":998
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.n_targets:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *                 total += unmapped
 *             return total
 */
    hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped));

    /* "pysam/csamfile.pyx":999
 *             for tid from 0 <= tid < self.header.n_targets:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped             # <<<<<<<<<<<<<<
 *             return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + __pyx_v_unmapped);
  }

  /* "pysam/csamfile.pyx":1000
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 *             return total             # <<<<<<<<<<<<<<
 * 
 *     property nocoordinate:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); 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_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":992
 *         """total number of unmapped reads in file.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1005
 *         """total number of reads without coordinates
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             return hts_idx_get_n_no_coor(self.index)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_12nocoordinate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_12nocoordinate_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_12nocoordinate___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_12nocoordinate___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1005);

  /* "pysam/csamfile.pyx":1006
 *         """
 *         def __get__(self):
 *             self._checkIndex()             # <<<<<<<<<<<<<<
 *             return hts_idx_get_n_no_coor(self.index)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_checkIndex); 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 = __Pyx_PyObject_Call(__pyx_t_1, __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_t_2); __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1007
 *         def __get__(self):
 *             self._checkIndex()
 *             return hts_idx_get_n_no_coor(self.index)             # <<<<<<<<<<<<<<
 * 
 *     property text:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyInt_From_uint64_t(hts_idx_get_n_no_coor(__pyx_v_self->index)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1005
 *         """total number of reads without coordinates
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             return hts_idx_get_n_no_coor(self.index)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.nocoordinate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1011
 *     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 from_string_and_size(self.header.text, self.header.l_text)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_4text_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_4text___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_4text___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1011);

  /* "pysam/csamfile.pyx":1012
 *         '''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 from_string_and_size(self.header.text, self.header.l_text)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1012; __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 = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1013
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 *             return from_string_and_size(self.header.text, self.header.l_text)             # <<<<<<<<<<<<<<
 * 
 *     property header:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_5pysam_8csamfile_from_string_and_size(__pyx_v_self->header->text, __pyx_v_self->header->l_text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1011
 *     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 from_string_and_size(self.header.text, self.header.l_text)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1019
 *         a two-level dictionary.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_6header_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_6header___get__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_6header___get__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_field = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_sq = NULL;
  PyObject *__pyx_v_ref = NULL;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  PyObject *(*__pyx_t_11)(PyObject *);
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *(*__pyx_t_14)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1019);

  /* "pysam/csamfile.pyx":1020
 *         '''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *             result = {}
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __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 = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1022
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 * 
 *             result = {}             # <<<<<<<<<<<<<<
 * 
 *             if self.header.text != NULL:
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_result = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1024
 *             result = {}
 * 
 *             if self.header.text != NULL:             # <<<<<<<<<<<<<<
 *                 # convert to python string (note: call self.text to create 0-terminated string)
 *                 t = self.text
 */
  __pyx_t_4 = ((__pyx_v_self->header->text != NULL) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":1026
 *             if self.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_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_t = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysam/csamfile.pyx":1027
 *                 # 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_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __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_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } 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 = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_2)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_2)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_1 = __pyx_t_6(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":1028
 *                 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_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_3 = ((!__pyx_t_4) != 0);
      if (__pyx_t_3) {
        goto __pyx_L5_continue;
      }

      /* "pysam/csamfile.pyx":1029
 *                 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 CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_3)) {
          __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_header_line_without_s, __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          PyErr_SetObject(PyExc_AssertionError, __pyx_t_1);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

      /* "pysam/csamfile.pyx":1030
 *                     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_1 = __Pyx_PyObject_GetSlice(__pyx_v_line, 1, 0, NULL, NULL, &__pyx_slice__43, 1, 0, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_split); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __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_PyObject_Call(__pyx_t_7, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":1031
 *                     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, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/csamfile.pyx":1032
 *                     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 CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!(__pyx_t_3 != 0))) {
          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __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 = __Pyx_PyString_Format(__pyx_kp_s_header_line_with_invalid_type_s, __pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          PyErr_SetObject(PyExc_AssertionError, __pyx_t_7);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

      /* "pysam/csamfile.pyx":1035
 * 
 *                     # treat comments
 *                     if record == "CO":             # <<<<<<<<<<<<<<
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )
 */
      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_3) {

        /* "pysam/csamfile.pyx":1036
 *                     # treat comments
 *                     if record == "CO":
 *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                         result[record].append( "\t".join( fields[1:] ) )
 *                         continue
 */
        __pyx_t_3 = (__Pyx_PyDict_Contains(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_4 = (__pyx_t_3 != 0);
        if (__pyx_t_4) {
          __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_7) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          goto __pyx_L9;
        }
        __pyx_L9:;

        /* "pysam/csamfile.pyx":1037
 *                     if record == "CO":
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )             # <<<<<<<<<<<<<<
 *                         continue
 *                     # the following is clumsy as generators do not work?
 */
        __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__45, 1, 0, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pysam/csamfile.pyx":1038
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )
 *                         continue             # <<<<<<<<<<<<<<
 *                     # the following is clumsy as generators do not work?
 *                     x = {}
 */
        goto __pyx_L5_continue;
      }

      /* "pysam/csamfile.pyx":1040
 *                         continue
 *                     # the following is clumsy as generators do not work?
 *                     x = {}             # <<<<<<<<<<<<<<
 *                     for field in fields[1:]:
 *                         if ":" not in field:
 */
      __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_XDECREF_SET(__pyx_v_x, ((PyObject*)__pyx_t_8));
      __pyx_t_8 = 0;

      /* "pysam/csamfile.pyx":1041
 *                     # the following is clumsy as generators do not work?
 *                     x = {}
 *                     for field in fields[1:]:             # <<<<<<<<<<<<<<
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )
 */
      __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__46, 1, 0, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __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_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
      } else {
        __pyx_t_10 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = Py_TYPE(__pyx_t_7)->tp_iternext;
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (;;) {
        if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_7)) {
          if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_8); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_7)) {
          if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_8); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_8 = __pyx_t_11(__pyx_t_7);
          if (unlikely(!__pyx_t_8)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "pysam/csamfile.pyx":1042
 *                     x = {}
 *                     for field in fields[1:]:
 *                         if ":" not in field:             # <<<<<<<<<<<<<<
 *                             raise ValueError("malformatted header: no ':' in field" )
 *                         key, value = field.split(":",1)
 */
        __pyx_t_4 = (__Pyx_PySequence_Contains(__pyx_kp_s__47, __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_3 = (__pyx_t_4 != 0);
        if (__pyx_t_3) {

          /* "pysam/csamfile.pyx":1043
 *                     for field in fields[1:]:
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
 *                         key, value = field.split(":",1)
 *                         # uppercase keys must be valid
 */
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }

        /* "pysam/csamfile.pyx":1044
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )
 *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
 *                         # uppercase keys must be valid
 *                         # lowercase are permitted for user fields
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_field, __pyx_n_s_split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
          PyObject* sequence = __pyx_t_1;
          #if CYTHON_COMPILING_IN_CPYTHON
          Py_ssize_t size = Py_SIZE(sequence);
          #else
          Py_ssize_t size = PySequence_Size(sequence);
          #endif
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          #if CYTHON_COMPILING_IN_CPYTHON
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_12);
          #else
          __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          #endif
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_13 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext;
          index = 0; __pyx_t_8 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_8)) goto __pyx_L13_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_8);
          index = 1; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L13_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_12);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_14 = NULL;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          goto __pyx_L14_unpacking_done;
          __pyx_L13_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_14 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_L14_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_8);
        __pyx_t_8 = 0;
        __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_12);
        __pyx_t_12 = 0;

        /* "pysam/csamfile.pyx":1047
 *                         # uppercase keys must be valid
 *                         # lowercase are permitted for user fields
 *                         if key in VALID_HEADER_FIELDS[record]:             # <<<<<<<<<<<<<<
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
 *                         elif not key.isupper():
 */
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_12 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_t_12, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_4 = (__pyx_t_3 != 0);
        if (__pyx_t_4) {

          /* "pysam/csamfile.pyx":1048
 *                         # lowercase are permitted for user fields
 *                         if key in VALID_HEADER_FIELDS[record]:
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
 *                         elif not key.isupper():
 *                             x[key] = value
 */
          __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_1 = PyObject_GetItem(__pyx_t_12, __pyx_v_record); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_12 = PyObject_GetItem(__pyx_t_1, __pyx_v_key); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_12);
          __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 = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_INCREF(__pyx_v_value);
          PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
          __Pyx_GIVEREF(__pyx_v_value);
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_8) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          goto __pyx_L15;
        }

        /* "pysam/csamfile.pyx":1049
 *                         if key in VALID_HEADER_FIELDS[record]:
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
 *                         elif not key.isupper():             # <<<<<<<<<<<<<<
 *                             x[key] = value
 *                         else:
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_3 = ((!__pyx_t_4) != 0);
        if (__pyx_t_3) {

          /* "pysam/csamfile.pyx":1050
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
 *                         elif not key.isupper():
 *                             x[key] = value             # <<<<<<<<<<<<<<
 *                         else:
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
 */
          if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_v_value) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L15;
        }
        /*else*/ {

          /* "pysam/csamfile.pyx":1052
 *                             x[key] = value
 *                         else:
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )             # <<<<<<<<<<<<<<
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:
 */
          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_INCREF(__pyx_v_key);
          PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
          __Pyx_GIVEREF(__pyx_v_key);
          __Pyx_INCREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_unknown_field_code_s_in_record_s, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __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 = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L15:;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/csamfile.pyx":1054
 *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:             # <<<<<<<<<<<<<<
 *                         if record in result:
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
 */
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)((PyObject*)(&PyDict_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_3) {

        /* "pysam/csamfile.pyx":1055
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:
 *                         if record in result:             # <<<<<<<<<<<<<<
 *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
 *                         result[record] = x
 */
        __pyx_t_3 = (__Pyx_PyDict_Contains(__pyx_v_record, __pyx_v_result, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_4 = (__pyx_t_3 != 0);
        if (__pyx_t_4) {

          /* "pysam/csamfile.pyx":1056
 *                     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_7 = __Pyx_PyString_Format(__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_v_record); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __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, 0);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }

        /* "pysam/csamfile.pyx":1057
 *                         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 (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_v_x) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L16;
      }

      /* "pysam/csamfile.pyx":1058
 *                             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_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)((PyObject*)(&PyList_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_4) {

        /* "pysam/csamfile.pyx":1059
 *                         result[record] = x
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                         result[record].append( x )
 * 
 */
        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_3 = (__pyx_t_4 != 0);
        if (__pyx_t_3) {
          __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_7) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          goto __pyx_L18;
        }
        __pyx_L18:;

        /* "pysam/csamfile.pyx":1060
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []
 *                         result[record].append( x )             # <<<<<<<<<<<<<<
 * 
 *                 # if there are no SQ lines in the header, add the reference names
 */
        __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_v_x); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L16;
      }
      __pyx_L16:;
      __pyx_L5_continue:;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/csamfile.pyx":1068
 *                 # SQ lines, the SQ information is not part of the textual header and thus
 *                 # are missing from the output. See issue 84.
 *                 if "SQ" not in result:             # <<<<<<<<<<<<<<
 *                     sq = []
 *                     for ref, length in zip( self.references, self.lengths ):
 */
    __pyx_t_3 = (__Pyx_PyDict_Contains(__pyx_n_s_SQ, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1068; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (__pyx_t_4) {

      /* "pysam/csamfile.pyx":1069
 *                 # are missing from the output. See issue 84.
 *                 if "SQ" not in result:
 *                     sq = []             # <<<<<<<<<<<<<<
 *                     for ref, length in zip( self.references, self.lengths ):
 *                         sq.append( {'LN': length, 'SN': ref } )
 */
      __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_v_sq = ((PyObject*)__pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/csamfile.pyx":1070
 *                 if "SQ" not in result:
 *                     sq = []
 *                     for ref, length in zip( self.references, self.lengths ):             # <<<<<<<<<<<<<<
 *                         sq.append( {'LN': length, 'SN': ref } )
 *                     result["SQ"] = sq
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_lengths); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __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 = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_2 = 0;
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) {
        __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0;
        __pyx_t_6 = NULL;
      } else {
        __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = Py_TYPE(__pyx_t_8)->tp_iternext;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      for (;;) {
        if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_8)) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_8)) {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_7 = __pyx_t_6(__pyx_t_8);
          if (unlikely(!__pyx_t_7)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_7);
        }
        if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
          PyObject* sequence = __pyx_t_7;
          #if CYTHON_COMPILING_IN_CPYTHON
          Py_ssize_t size = Py_SIZE(sequence);
          #else
          Py_ssize_t size = PySequence_Size(sequence);
          #endif
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          #if CYTHON_COMPILING_IN_CPYTHON
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_1);
          #else
          __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          #endif
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_12 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_14 = Py_TYPE(__pyx_t_12)->tp_iternext;
          index = 0; __pyx_t_2 = __pyx_t_14(__pyx_t_12); if (unlikely(!__pyx_t_2)) goto __pyx_L22_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_2);
          index = 1; __pyx_t_1 = __pyx_t_14(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L22_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_1);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_14 = NULL;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          goto __pyx_L23_unpacking_done;
          __pyx_L22_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_14 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_L23_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "pysam/csamfile.pyx":1071
 *                     sq = []
 *                     for ref, length in zip( self.references, self.lengths ):
 *                         sq.append( {'LN': length, 'SN': ref } )             # <<<<<<<<<<<<<<
 *                     result["SQ"] = sq
 * 
 */
        __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_LN, __pyx_v_length) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_SN, __pyx_v_ref) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_sq, __pyx_t_7); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pysam/csamfile.pyx":1072
 *                     for ref, length in zip( self.references, self.lengths ):
 *                         sq.append( {'LN': length, 'SN': ref } )
 *                     result["SQ"] = sq             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
      if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_n_s_SQ, __pyx_v_sq) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L19;
    }
    __pyx_L19:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysam/csamfile.pyx":1074
 *                     result["SQ"] = sq
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     def _buildLine( self, fields, record ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1019
 *         a two-level dictionary.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_field);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_sq);
  __Pyx_XDECREF(__pyx_v_ref);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1076
 *             return result
 * 
 *     def _buildLine( self, fields, record ):             # <<<<<<<<<<<<<<
 *         '''build a header line from *fields* dictionary for *record*'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_43_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_42_buildLine[] = "Samfile._buildLine(self, fields, record)\nbuild a header line from *fields* dictionary for *record*";
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_43_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_record = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buildLine (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fields,&__pyx_n_s_record,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fields)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_record)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_fields = values[0];
    __pyx_v_record = values[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 = 1076; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.Samfile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_42_buildLine(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self), __pyx_v_fields, __pyx_v_record);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_42_buildLine(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record) {
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_buildLine", 0);
  __Pyx_TraceCall("_buildLine", __pyx_f[0], 1076);

  /* "pysam/csamfile.pyx":1080
 * 
 *         # TODO: add checking for field and sort order
 *         line = ["@%s" % record ]             # <<<<<<<<<<<<<<
 *         # comment
 *         if record == "CO":
 */
  __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_line = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1082
 *         line = ["@%s" % record ]
 *         # comment
 *         if record == "CO":             # <<<<<<<<<<<<<<
 *             line.append( fields )
 *         # user tags
 */
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":1083
 *         # comment
 *         if record == "CO":
 *             line.append( fields )             # <<<<<<<<<<<<<<
 *         # user tags
 *         elif record.islower():
 */
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }

  /* "pysam/csamfile.pyx":1085
 *             line.append( fields )
 *         # user tags
 *         elif record.islower():             # <<<<<<<<<<<<<<
 *             for key in sorted(fields):
 *                 line.append( "%s:%s" % (key, str(fields[key])))
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_record, __pyx_n_s_islower); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __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 = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":1086
 *         # user tags
 *         elif record.islower():
 *             for key in sorted(fields):             # <<<<<<<<<<<<<<
 *                 line.append( "%s:%s" % (key, str(fields[key])))
 *         # defined tags
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __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_t_2 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_2 = __pyx_t_6(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/csamfile.pyx":1087
 *         elif record.islower():
 *             for key in sorted(fields):
 *                 line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *         # defined tags
 *         else:
 */
      __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
      __Pyx_GIVEREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1091
 *         else:
 *             # write fields of the specification
 *             for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
 *                 if key in fields:
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_2 = __pyx_t_6(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/csamfile.pyx":1092
 *             # write fields of the specification
 *             for key in VALID_HEADER_ORDER[record]:
 *                 if key in fields:             # <<<<<<<<<<<<<<
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 *             # write user fields
 */
      __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_8 = (__pyx_t_3 != 0);
      if (__pyx_t_8) {

        /* "pysam/csamfile.pyx":1093
 *             for key in VALID_HEADER_ORDER[record]:
 *                 if key in fields:
 *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *             # write user fields
 *             for key in fields:
 */
        __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        goto __pyx_L8;
      }
      __pyx_L8:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":1095
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 *             # write user fields
 *             for key in fields:             # <<<<<<<<<<<<<<
 *                 if not key.isupper():
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 */
    if (PyList_CheckExact(__pyx_v_fields) || PyTuple_CheckExact(__pyx_v_fields)) {
      __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_2 = __pyx_t_6(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/csamfile.pyx":1096
 *             # write user fields
 *             for key in fields:
 *                 if not key.isupper():             # <<<<<<<<<<<<<<
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_3 = ((!__pyx_t_8) != 0);
      if (__pyx_t_3) {

        /* "pysam/csamfile.pyx":1097
 *             for key in fields:
 *                 if not key.isupper():
 *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( line )
 */
        __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __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 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_7); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L11;
      }
      __pyx_L11:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1099
 *                     line.append( "%s:%s" % (key, str(fields[key])))
 * 
 *         return "\t".join( line )             # <<<<<<<<<<<<<<
 * 
 *     cdef bam_hdr_t * _buildHeader( self, new_header ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1076
 *             return result
 * 
 *     def _buildLine( self, fields, record ):             # <<<<<<<<<<<<<<
 *         '''build a header line from *fields* dictionary for *record*'''
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.csamfile.Samfile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1101
 *         return "\t".join( line )
 * 
 *     cdef bam_hdr_t * _buildHeader( self, new_header ):             # <<<<<<<<<<<<<<
 *         '''return a new header built from a dictionary in *new_header*.
 * 
 */

static bam_hdr_t *__pyx_f_5pysam_8csamfile_7Samfile__buildHeader(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self, PyObject *__pyx_v_new_header) {
  PyObject *__pyx_v_lines = NULL;
  bam_hdr_t *__pyx_v_dest;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_v_ttype = NULL;
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_v_btext = 0;
  PyObject *__pyx_v_bseqname = 0;
  PyObject *__pyx_v_seqs = NULL;
  long __pyx_v_x;
  PyObject *__pyx_v_seqname = NULL;
  PyObject *__pyx_v_seqlen = NULL;
  bam_hdr_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  PyObject *(*__pyx_t_11)(PyObject *);
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  char const *__pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int32_t __pyx_t_20;
  uint32_t __pyx_t_21;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_buildHeader", 0);
  __Pyx_TraceCall("_buildHeader", __pyx_f[0], 1101);

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

  /* "pysam/csamfile.pyx":1114
 *         cdef bam_hdr_t * dest
 * 
 *         dest = bam_hdr_init()             # <<<<<<<<<<<<<<
 * 
 *         # first: defined tags
 */
  __pyx_v_dest = bam_hdr_init();

  /* "pysam/csamfile.pyx":1117
 * 
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __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 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_1 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":1118
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 *             if record in new_header:             # <<<<<<<<<<<<<<
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]
 */
    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "pysam/csamfile.pyx":1119
 *         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_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_ttype, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/csamfile.pyx":1120
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]             # <<<<<<<<<<<<<<
 *                 if type(data) != type(ttype()):
 *                     raise ValueError(
 */
      __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/csamfile.pyx":1121
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]
 *                 if type(data) != type(ttype()):             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s" %
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_v_ttype, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_7)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_6) {

        /* "pysam/csamfile.pyx":1124
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s" %
 *                         (record, type(data), type(ttype())))             # <<<<<<<<<<<<<<
 *                 if type(data) is dict:
 *                     lines.append(self._buildLine(data, record))
 */
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_v_ttype, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data)));
        PyTuple_SET_ITEM(__pyx_t_7, 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_7, 2, ((PyObject *)Py_TYPE(__pyx_t_1)));
        __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1)));
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pysam/csamfile.pyx":1123
 *                 if type(data) != type(ttype()):
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s" %             # <<<<<<<<<<<<<<
 *                         (record, type(data), type(ttype())))
 *                 if type(data) is dict:
 */
        __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pysam/csamfile.pyx":1122
 *                 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_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }

      /* "pysam/csamfile.pyx":1125
 *                         "invalid type for record %s: %s, expected %s" %
 *                         (record, type(data), type(ttype())))
 *                 if type(data) is dict:             # <<<<<<<<<<<<<<
 *                     lines.append(self._buildLine(data, record))
 *                 else:
 */
      __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
      __pyx_t_5 = (__pyx_t_6 != 0);
      if (__pyx_t_5) {

        /* "pysam/csamfile.pyx":1126
 *                         (record, type(data), type(ttype())))
 *                 if type(data) is dict:
 *                     lines.append(self._buildLine(data, record))             # <<<<<<<<<<<<<<
 *                 else:
 *                     for fields in new_header[record]:
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_data);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_data);
        __Pyx_GIVEREF(__pyx_v_data);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":1128
 *                     lines.append(self._buildLine(data, record))
 *                 else:
 *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(self._buildLine(fields, record))
 * 
 */
        __pyx_t_8 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __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_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7); __pyx_t_10 = 0;
          __pyx_t_11 = NULL;
        } else {
          __pyx_t_10 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_11 = Py_TYPE(__pyx_t_7)->tp_iternext;
        }
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        for (;;) {
          if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_7)) {
            if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_7)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_8); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_7)) {
            if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_8); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          } else {
            __pyx_t_8 = __pyx_t_11(__pyx_t_7);
            if (unlikely(!__pyx_t_8)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_8);
          }
          __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_8);
          __pyx_t_8 = 0;

          /* "pysam/csamfile.pyx":1129
 *                 else:
 *                     for fields in new_header[record]:
 *                         lines.append(self._buildLine(fields, record))             # <<<<<<<<<<<<<<
 * 
 *         # then: user tags (lower case), sorted alphabetically
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __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_12 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_12); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_L7:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1132
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(new_header.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_header, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__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 = 1132; __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 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_2 = __pyx_t_7; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_7 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
      if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_7 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
      PyObject* sequence = __pyx_t_7;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_12 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_1);
      #else
      __pyx_t_12 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      #endif
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_13 = Py_TYPE(__pyx_t_8)->tp_iternext;
      index = 0; __pyx_t_12 = __pyx_t_13(__pyx_t_8); if (unlikely(!__pyx_t_12)) goto __pyx_L12_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_12);
      index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_13 = NULL;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L13_unpacking_done;
      __pyx_L12_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_13 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L13_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_12);
    __pyx_t_12 = 0;
    __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":1133
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(new_header.items()):
 *             if record in VALID_HEADERS: continue             # <<<<<<<<<<<<<<
 *             if type( data ) is dict:
 *                 lines.append( self._buildLine( data, record ) )
 */
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_7, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {
      goto __pyx_L10_continue;
    }

    /* "pysam/csamfile.pyx":1134
 *         for record, data in sorted(new_header.items()):
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:             # <<<<<<<<<<<<<<
 *                 lines.append( self._buildLine( data, record ) )
 *             else:
 */
    __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (__pyx_t_5) {

      /* "pysam/csamfile.pyx":1135
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:
 *                 lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
 *             else:
 *                 for fields in new_header[record]:
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_data);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_data);
      __Pyx_GIVEREF(__pyx_v_data);
      __Pyx_INCREF(__pyx_v_record);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
      __Pyx_GIVEREF(__pyx_v_record);
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_12); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      goto __pyx_L15;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":1137
 *                 lines.append( self._buildLine( data, record ) )
 *             else:
 *                 for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                     lines.append( self._buildLine( fields, record ) )
 * 
 */
      __pyx_t_12 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_12);
      if (PyList_CheckExact(__pyx_t_12) || PyTuple_CheckExact(__pyx_t_12)) {
        __pyx_t_1 = __pyx_t_12; __Pyx_INCREF(__pyx_t_1); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
      } else {
        __pyx_t_10 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_11 = Py_TYPE(__pyx_t_1)->tp_iternext;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      for (;;) {
        if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_1)) {
          if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_12 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_12); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_12 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_1)) {
          if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_12); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_12 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          __pyx_t_12 = __pyx_t_11(__pyx_t_1);
          if (unlikely(!__pyx_t_12)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_12);
        }
        __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_12);
        __pyx_t_12 = 0;

        /* "pysam/csamfile.pyx":1138
 *             else:
 *                 for fields in new_header[record]:
 *                     lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
 * 
 *         text = "\n".join(lines) + "\n"
 */
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_fields);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_fields);
        __Pyx_GIVEREF(__pyx_v_fields);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __pyx_L15:;
    __pyx_L10_continue:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1140
 *                     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_2 = __Pyx_PyString_Join(__pyx_kp_s__4, __pyx_v_lines); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_kp_s__4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_text = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1141
 * 
 *         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_5 = ((__pyx_v_dest->text != NULL) != 0);
  if (__pyx_t_5) {
    free(__pyx_v_dest->text);
    goto __pyx_L18;
  }
  __pyx_L18:;

  /* "pysam/csamfile.pyx":1142
 *         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)
 *         cdef bytes btext = text.encode('ascii')
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest->text = ((char *)calloc(__pyx_t_3, (sizeof(char))));

  /* "pysam/csamfile.pyx":1143
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)             # <<<<<<<<<<<<<<
 *         cdef bytes btext = text.encode('ascii')
 *         strncpy( dest.text, btext, dest.l_text )
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest->l_text = __pyx_t_3;

  /* "pysam/csamfile.pyx":1144
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
 *         strncpy( dest.text, btext, dest.l_text )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_text, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_btext = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1145
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')
 *         strncpy( dest.text, btext, dest.l_text )             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes bseqname
 */
  __pyx_t_14 = __Pyx_PyObject_AsString(__pyx_v_btext); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_dest->text, __pyx_t_14, __pyx_v_dest->l_text);

  /* "pysam/csamfile.pyx":1149
 *         cdef bytes bseqname
 *         # collect targets
 *         if "SQ" in new_header:             # <<<<<<<<<<<<<<
 *             seqs = []
 *             for fields in new_header["SQ"]:
 */
  __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_n_s_SQ, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":1150
 *         # collect targets
 *         if "SQ" in new_header:
 *             seqs = []             # <<<<<<<<<<<<<<
 *             for fields in new_header["SQ"]:
 *                 try:
 */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_seqs = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/csamfile.pyx":1151
 *         if "SQ" in new_header:
 *             seqs = []
 *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 */
    __pyx_t_2 = PyObject_GetItem(__pyx_v_new_header, __pyx_n_s_SQ); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
      __pyx_t_4 = NULL;
    } else {
      __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_2 = __pyx_t_4(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/csamfile.pyx":1152
 *             seqs = []
 *             for fields in new_header["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:
 */
      {
        __Pyx_ExceptionSave(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
        __Pyx_XGOTREF(__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_16);
        __Pyx_XGOTREF(__pyx_t_17);
        /*try:*/ {

          /* "pysam/csamfile.pyx":1153
 *             for fields in new_header["SQ"]:
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 */
          __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1153; __pyx_clineno = __LINE__; goto __pyx_L22_error;};
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_8 = PyObject_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1153; __pyx_clineno = __LINE__; goto __pyx_L22_error;};
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1153; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_GOTREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_2 = 0;
          __pyx_t_8 = 0;
          __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_seqs, __pyx_t_7); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1153; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        goto __pyx_L29_try_end;
        __pyx_L22_error:;
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pysam/csamfile.pyx":1154
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_18 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_18) {
          __Pyx_AddTraceback("pysam.csamfile.Samfile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1154; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_GOTREF(__pyx_t_2);

          /* "pysam/csamfile.pyx":1155
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *             dest.n_targets = len(seqs)
 */
          __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_INCREF(__pyx_v_fields);
          PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_fields);
          __Pyx_GIVEREF(__pyx_v_fields);
          __pyx_t_19 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_12, NULL); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_12 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_sequence_information, __pyx_t_19); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __pyx_t_19 = PyTuple_New(1); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_19);
          PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_12);
          __Pyx_GIVEREF(__pyx_t_12);
          __pyx_t_12 = 0;
          __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_19, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_Raise(__pyx_t_12, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          goto __pyx_L23_exception_handled;
        }
        goto __pyx_L24_except_error;
        __pyx_L24_except_error:;
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_17);
        __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
        goto __pyx_L1_error;
        __pyx_L23_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_17);
        __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
        __pyx_L29_try_end:;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":1157
 *                     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) )
 */
    __pyx_t_3 = PyList_GET_SIZE(__pyx_v_seqs); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_dest->n_targets = __pyx_t_3;

    /* "pysam/csamfile.pyx":1158
 * 
 *             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 *))));

    /* "pysam/csamfile.pyx":1159
 *             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))));

    /* "pysam/csamfile.pyx":1161
 *             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_20 = __pyx_v_dest->n_targets;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_20; __pyx_v_x++) {

      /* "pysam/csamfile.pyx":1162
 * 
 *             for x from 0 <= x < dest.n_targets:
 *                 seqname, seqlen = seqs[x]             # <<<<<<<<<<<<<<
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 bseqname = seqname.encode('ascii')
 */
      __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_seqs, __pyx_v_x, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_8);
        #else
        __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_13 = Py_TYPE(__pyx_t_7)->tp_iternext;
        index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L34_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        index = 1; __pyx_t_8 = __pyx_t_13(__pyx_t_7); if (unlikely(!__pyx_t_8)) goto __pyx_L34_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_13 = NULL;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L35_unpacking_done;
        __pyx_L34_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_13 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L35_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_seqname, __pyx_t_2);
      __pyx_t_2 = 0;
      __Pyx_XDECREF_SET(__pyx_v_seqlen, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "pysam/csamfile.pyx":1163
 *             for x from 0 <= x < dest.n_targets:
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )             # <<<<<<<<<<<<<<
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
 */
      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_3 + 1), (sizeof(char))));

      /* "pysam/csamfile.pyx":1164
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
 *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
 *                 dest.target_len[x] = seqlen
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_seqname, __pyx_n_s_encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_8)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_XDECREF_SET(__pyx_v_bseqname, ((PyObject*)__pyx_t_8));
      __pyx_t_8 = 0;

      /* "pysam/csamfile.pyx":1165
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )             # <<<<<<<<<<<<<<
 *                 dest.target_len[x] = seqlen
 * 
 */
      __pyx_t_14 = __Pyx_PyObject_AsString(__pyx_v_bseqname); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_14, (__pyx_t_3 + 1));

      /* "pysam/csamfile.pyx":1166
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
 *                 dest.target_len[x] = seqlen             # <<<<<<<<<<<<<<
 * 
 *         return dest
 */
      __pyx_t_21 = __Pyx_PyInt_As_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_21 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_21;
    }
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "pysam/csamfile.pyx":1168
 *                 dest.target_len[x] = seqlen
 * 
 *         return dest             # <<<<<<<<<<<<<<
 * 
 *     ###############################################################
 */
  __pyx_r = __pyx_v_dest;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1101
 *         return "\t".join( line )
 * 
 *     cdef bam_hdr_t * _buildHeader( self, new_header ):             # <<<<<<<<<<<<<<
 *         '''return a new header built from a dictionary in *new_header*.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_WriteUnraisable("pysam.csamfile.Samfile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_lines);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_ttype);
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XDECREF(__pyx_v_btext);
  __Pyx_XDECREF(__pyx_v_bseqname);
  __Pyx_XDECREF(__pyx_v_seqs);
  __Pyx_XDECREF(__pyx_v_seqname);
  __Pyx_XDECREF(__pyx_v_seqlen);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1178
 *     ## Possible solutions: deprecate or open new file handle
 *     ###############################################################
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_45__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_45__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_44__iter__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_44__iter__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1178);

  /* "pysam/csamfile.pyx":1179
 *     ###############################################################
 *     def __iter__(self):
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __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 = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":1180
 *     def __iter__(self):
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         if not self.isbam and self.header.n_targets == 0:
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1182
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         if not self.isbam and self.header.n_targets == 0:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 */
  __pyx_t_4 = ((!(__pyx_v_self->isbam != 0)) != 0);
  if (__pyx_t_4) {
    __pyx_t_3 = ((__pyx_v_self->header->n_targets == 0) != 0);
    __pyx_t_5 = __pyx_t_3;
  } else {
    __pyx_t_5 = __pyx_t_4;
  }
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":1183
 * 
 *         if not self.isbam and self.header.n_targets == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1185
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1178
 *     ## Possible solutions: deprecate or open new file handle
 *     ###############################################################
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1187
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_8csamfile_7Samfile_getCurrent(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1187);

  /* "pysam/csamfile.pyx":1188
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1187
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1190
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.Samfile.IteratorColumn`.
 */

static int __pyx_f_5pysam_8csamfile_7Samfile_cnext(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1190);

  /* "pysam/csamfile.pyx":1195
 *         '''
 *         cdef int ret
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->htsfile, __pyx_v_self->header, __pyx_v_self->b);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1190
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.Samfile.IteratorColumn`.
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1199
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """
 *         python version of next().
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_47__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_7Samfile_46__next__[] = "\n        python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_7Samfile_46__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_7Samfile_47__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7Samfile_46__next__(((struct __pyx_obj_5pysam_8csamfile_Samfile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7Samfile_46__next__(struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1199);

  /* "pysam/csamfile.pyx":1204
 *         """
 *         cdef int ret
 *         ret = sam_read1(self.htsfile, self.header, self.b)             # <<<<<<<<<<<<<<
 *         if (ret >= 0):
 *             return makeAlignedRead(self.b)
 */
  __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_self->header, __pyx_v_self->b);

  /* "pysam/csamfile.pyx":1205
 *         cdef int ret
 *         ret = sam_read1(self.htsfile, self.header, self.b)
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedRead(self.b)
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1206
 *         ret = sam_read1(self.htsfile, self.header, self.b)
 *         if (ret >= 0):
 *             return makeAlignedRead(self.b)             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1208
 *             return makeAlignedRead(self.b)
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * ##-------------------------------------------------------------------
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1199
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """
 *         python version of next().
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.Samfile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1236
 *     '''
 * 
 *     def __init__(self, Samfile samfile, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._isOpen():
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_reopen;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_reopen,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    if (values[1]) {
      __pyx_v_reopen = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_reopen = ((int)1);
    }
  }
  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 = 1236; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_11IteratorRow___init__(((struct __pyx_obj_5pysam_8csamfile_IteratorRow *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11IteratorRow___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  char const *__pyx_t_5;
  htsFile *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1236);

  /* "pysam/csamfile.pyx":1238
 *     def __init__(self, Samfile samfile, int reopen=True):
 * 
 *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1238; __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 = 1238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":1239
 * 
 *         if not samfile._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as the
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1243
 *         # makes sure that samfile stays alive as long as the
 *         # iterator is alive
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 * 
 *         # reopen the file - note that this makes the iterator
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GOTREF(__pyx_v_self->samfile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/csamfile.pyx":1247
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if reopen:             # <<<<<<<<<<<<<<
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL
 */
  __pyx_t_4 = (__pyx_v_reopen != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":1248
 *         # slow and causes pileup to slow down significantly.
 *         if reopen:
 *             self.htsfile = hts_open(samfile._filename, 'r')             # <<<<<<<<<<<<<<
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 */
    __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_samfile->_filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_5, __pyx_k_r);

    /* "pysam/csamfile.pyx":1249
 *         if reopen:
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL             # <<<<<<<<<<<<<<
 *             # read header - required for accurate positioning
 *             sam_hdr_read(self.htsfile)
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "pysam/csamfile.pyx":1251
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 *             sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             self.owns_samfile = True
 *         else:
 */
    sam_hdr_read(__pyx_v_self->htsfile);

    /* "pysam/csamfile.pyx":1252
 *             # read header - required for accurate positioning
 *             sam_hdr_read(self.htsfile)
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 *         else:
 *             self.htsfile = self.samfile.htsfile
 */
    __pyx_v_self->owns_samfile = 1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1254
 *             self.owns_samfile = True
 *         else:
 *             self.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 * 
 */
    __pyx_t_6 = __pyx_v_self->samfile->htsfile;
    __pyx_v_self->htsfile = __pyx_t_6;

    /* "pysam/csamfile.pyx":1255
 *         else:
 *             self.htsfile = self.samfile.htsfile
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *         self.retval = 0
 */
    __pyx_v_self->owns_samfile = 0;
  }
  __pyx_L4:;

  /* "pysam/csamfile.pyx":1257
 *             self.owns_samfile = False
 * 
 *         self.retval = 0             # <<<<<<<<<<<<<<
 * 
 *         self.b = bam_init1()
 */
  __pyx_v_self->retval = 0;

  /* "pysam/csamfile.pyx":1259
 *         self.retval = 0
 * 
 *         self.b = bam_init1()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->b = bam_init1();

  /* "pysam/csamfile.pyx":1236
 *     '''
 * 
 *     def __init__(self, Samfile samfile, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._isOpen():
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1261
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

/* Python wrapper */
static void __pyx_pw_5pysam_8csamfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_8csamfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_8csamfile_11IteratorRow_2__dealloc__(((struct __pyx_obj_5pysam_8csamfile_IteratorRow *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_8csamfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_8csamfile_IteratorRow *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1261);

  /* "pysam/csamfile.pyx":1262
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */
  bam_destroy1(__pyx_v_self->b);

  /* "pysam/csamfile.pyx":1263
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1264
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 * 
 * cdef class IteratorRowRegion(IteratorRow):
 */
    hts_close(__pyx_v_self->htsfile);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1261
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/csamfile.pyx":1291
 *     """
 * 
 *     def __init__(self, Samfile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int end,
 *                  int reopen=True):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_beg;
  int __pyx_v_end;
  int __pyx_v_reopen;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_beg,&__pyx_n_s_end,&__pyx_n_s_reopen,0};
    PyObject* values[5] = {0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tid)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_beg)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_beg = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[4]) {
      __pyx_v_reopen = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysam/csamfile.pyx":1293
 *     def __init__(self, Samfile samfile,
 *                  int tid, int beg, int end,
 *                  int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */
      __pyx_v_reopen = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_17IteratorRowRegion___init__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_end, __pyx_v_reopen);

  /* "pysam/csamfile.pyx":1291
 *     """
 * 
 *     def __init__(self, Samfile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int end,
 *                  int reopen=True):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1291);

  /* "pysam/csamfile.pyx":1295
 *                  int reopen=True):
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._hasIndex():
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __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 = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reopen, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":1297
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 * 
 *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
 *             raise ValueError( "no index available for iteration" )
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __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_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":1298
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
 * 
 *         self.iter = sam_itr_queryi(
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1300
 *             raise ValueError( "no index available for iteration" )
 * 
 *         self.iter = sam_itr_queryi(             # <<<<<<<<<<<<<<
 *             self.samfile.index,
 *             tid,
 */
  __pyx_v_self->iter = sam_itr_queryi(__pyx_v_self->__pyx_base.samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end);

  /* "pysam/csamfile.pyx":1291
 *     """
 * 
 *     def __init__(self, Samfile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int end,
 *                  int reopen=True):
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1306
 *             end)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_17IteratorRowRegion_2__iter__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1306);

  /* "pysam/csamfile.pyx":1307
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1306
 *             end)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1309
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_8csamfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1309);

  /* "pysam/csamfile.pyx":1310
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1309
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1312
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = hts_itr_next(self.htsfile.fp.bgzf,
 */

static int __pyx_f_5pysam_8csamfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1312);

  /* "pysam/csamfile.pyx":1314
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = hts_itr_next(self.htsfile.fp.bgzf,             # <<<<<<<<<<<<<<
 *                                    self.iter,
 *                                    self.b,
 */
  __pyx_v_self->__pyx_base.retval = hts_itr_next(__pyx_v_self->__pyx_base.htsfile->fp.bgzf, __pyx_v_self->iter, __pyx_v_self->__pyx_base.b, NULL);

  /* "pysam/csamfile.pyx":1312
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = hts_itr_next(self.htsfile.fp.bgzf,
 */

  /* function exit code */
  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1319
 *                                    NULL)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_17IteratorRowRegion_4__next__[] = "python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_17IteratorRowRegion_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_17IteratorRowRegion_4__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1319);

  /* "pysam/csamfile.pyx":1322
 *         """python version of next().
 *         """
 *         self.cnext()             # <<<<<<<<<<<<<<
 *         if self.retval < 0:
 *             raise StopIteration
 */
  ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/csamfile.pyx":1323
 *         """
 *         self.cnext()
 *         if self.retval < 0:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         return makeAlignedRead(self.b)
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval < 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1324
 *         self.cnext()
 *         if self.retval < 0:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         return makeAlignedRead(self.b)
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1325
 *         if self.retval < 0:
 *             raise StopIteration
 *         return makeAlignedRead(self.b)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1319
 *                                    NULL)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1327
 *         return makeAlignedRead(self.b)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_8csamfile_17IteratorRowRegion_6__dealloc__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_8csamfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1327);

  /* "pysam/csamfile.pyx":1328
 * 
 *     def __dealloc__(self):
 *         hts_itr_destroy(self.iter)             # <<<<<<<<<<<<<<
 * 
 * cdef class IteratorRowHead(IteratorRow):
 */
  hts_itr_destroy(__pyx_v_self->iter);

  /* "pysam/csamfile.pyx":1327
 *         return makeAlignedRead(self.b)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/csamfile.pyx":1346
 *     """
 * 
 *     def __init__(self, Samfile samfile, int n, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_n;
  int __pyx_v_reopen;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_n,&__pyx_n_s_reopen,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[2]) {
      __pyx_v_reopen = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_reopen = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_15IteratorRowHead___init__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *)__pyx_v_self), __pyx_v_samfile, __pyx_v_n, __pyx_v_reopen);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1346);

  /* "pysam/csamfile.pyx":1348
 *     def __init__(self, Samfile samfile, int n, int reopen=True):
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)             # <<<<<<<<<<<<<<
 * 
 *         self.max_rows = n
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __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 = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reopen, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":1350
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 * 
 *         self.max_rows = n             # <<<<<<<<<<<<<<
 *         self.current_row = 0
 * 
 */
  __pyx_v_self->max_rows = __pyx_v_n;

  /* "pysam/csamfile.pyx":1351
 * 
 *         self.max_rows = n
 *         self.current_row = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_row = 0;

  /* "pysam/csamfile.pyx":1346
 *     """
 * 
 *     def __init__(self, Samfile samfile, int n, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1353
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_15IteratorRowHead_2__iter__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1353);

  /* "pysam/csamfile.pyx":1354
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1353
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1356
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_8csamfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1356);

  /* "pysam/csamfile.pyx":1357
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1356
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1359
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

static int __pyx_f_5pysam_8csamfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1359);

  /* "pysam/csamfile.pyx":1361
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.samfile.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1359
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1365
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_15IteratorRowHead_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_15IteratorRowHead_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_15IteratorRowHead_4__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1365);

  /* "pysam/csamfile.pyx":1370
 *         pyrex uses this non-standard name instead of next()
 *         """
 *         if self.current_row >= self.max_rows:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->current_row >= __pyx_v_self->max_rows) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1371
 *         """
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1374
 * 
 *         cdef int ret
 *         ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                         self.samfile.header, self.b)
 *         if (ret >= 0):
 */
  __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);

  /* "pysam/csamfile.pyx":1376
 *         ret = sam_read1(self.htsfile,
 *                         self.samfile.header, self.b)
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             self.current_row += 1
 *             return makeAlignedRead( self.b )
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1377
 *                         self.samfile.header, self.b)
 *         if (ret >= 0):
 *             self.current_row += 1             # <<<<<<<<<<<<<<
 *             return makeAlignedRead( self.b )
 *         else:
 */
    __pyx_v_self->current_row = (__pyx_v_self->current_row + 1);

    /* "pysam/csamfile.pyx":1378
 *         if (ret >= 0):
 *             self.current_row += 1
 *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1380
 *             return makeAlignedRead( self.b )
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1365
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowHead.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1399
 *     """
 * 
 *     def __init__(self, Samfile samfile, int reopen = True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_reopen;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_reopen,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    if (values[1]) {
      __pyx_v_reopen = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_reopen = ((int)1);
    }
  }
  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 = 1399; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorRowAll___init__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1399);

  /* "pysam/csamfile.pyx":1401
 *     def __init__(self, Samfile samfile, int reopen = True):
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __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 = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reopen, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":1399
 *     """
 * 
 *     def __init__(self, Samfile samfile, int reopen = True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1403
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorRowAll_2__iter__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1403);

  /* "pysam/csamfile.pyx":1404
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent( self ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1403
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1406
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_8csamfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1406);

  /* "pysam/csamfile.pyx":1407
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1406
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1409
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

static int __pyx_f_5pysam_8csamfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1409);

  /* "pysam/csamfile.pyx":1411
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.samfile.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1409
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1415
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_14IteratorRowAll_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_14IteratorRowAll_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorRowAll_4__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1415);

  /* "pysam/csamfile.pyx":1421
 *         """
 *         cdef int ret
 *         ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                         self.samfile.header,
 *                         self.b)
 */
  __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);

  /* "pysam/csamfile.pyx":1424
 *                         self.samfile.header,
 *                         self.b)
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedRead(self.b)
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1425
 *                         self.b)
 *         if (ret >= 0):
 *             return makeAlignedRead(self.b)             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1427
 *             return makeAlignedRead(self.b)
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1415
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowAll.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1438
 *     """
 * 
 *     def __init__(self, Samfile samfile, reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_reopen = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_reopen,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1438; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    __pyx_v_reopen = values[1];
  }
  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 = 1438; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs___init__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, PyObject *__pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1438);

  /* "pysam/csamfile.pyx":1440
 *     def __init__(self, Samfile samfile, reopen=True):
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._hasIndex():
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __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 = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reopen, __pyx_v_reopen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":1442
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 * 
 *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for fetch")
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __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_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":1443
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1445
 *             raise ValueError("no index available for fetch")
 * 
 *         self.tid = -1             # <<<<<<<<<<<<<<
 * 
 *     def nextiter(self):
 */
  __pyx_v_self->tid = -1;

  /* "pysam/csamfile.pyx":1438
 *     """
 * 
 *     def __init__(self, Samfile samfile, reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1447
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         self.rowiter = IteratorRowRegion(self.samfile,
 *                                          self.tid,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_18IteratorRowAllRefs_2nextiter[] = "IteratorRowAllRefs.nextiter(self)";
static PyObject *__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("nextiter (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_2nextiter(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("nextiter", 0);
  __Pyx_TraceCall("nextiter", __pyx_f[0], 1447);

  /* "pysam/csamfile.pyx":1449
 *     def nextiter(self):
 *         self.rowiter = IteratorRowRegion(self.samfile,
 *                                          self.tid,             # <<<<<<<<<<<<<<
 *                                          0,
 *                                          1<<29)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); 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);

  /* "pysam/csamfile.pyx":1448
 * 
 *     def nextiter(self):
 *         self.rowiter = IteratorRowRegion(self.samfile,             # <<<<<<<<<<<<<<
 *                                          self.tid,
 *                                          0,
 */
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->__pyx_base.samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->__pyx_base.samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->__pyx_base.samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_536870912);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_536870912);
  __Pyx_GIVEREF(__pyx_int_536870912);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowRegion)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->rowiter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->rowiter));
  __pyx_v_self->rowiter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1447
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         self.rowiter = IteratorRowRegion(self.samfile,
 *                                          self.tid,
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorRowAllRefs.nextiter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1453
 *                                          1<<29)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_4__iter__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1453);

  /* "pysam/csamfile.pyx":1454
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1453
 *                                          1<<29)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1456
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_18IteratorRowAllRefs_6__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_18IteratorRowAllRefs_6__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_6__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1456);

  /* "pysam/csamfile.pyx":1462
 *         """
 *         # Create an initial iterator
 *         if self.tid == -1:             # <<<<<<<<<<<<<<
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 */
  __pyx_t_1 = ((__pyx_v_self->tid == -1) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1463
 *         # Create an initial iterator
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 *             self.tid = 0
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __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 = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = ((!__pyx_t_1) != 0);
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":1464
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 *             self.tid = 0
 *             self.nextiter()
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":1465
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 *             self.tid = 0             # <<<<<<<<<<<<<<
 *             self.nextiter()
 * 
 */
    __pyx_v_self->tid = 0;

    /* "pysam/csamfile.pyx":1466
 *                 raise StopIteration
 *             self.tid = 0
 *             self.nextiter()             # <<<<<<<<<<<<<<
 * 
 *         while 1:
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __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;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1468
 *             self.nextiter()
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.rowiter.cnext()
 * 
 */
  while (1) {

    /* "pysam/csamfile.pyx":1469
 * 
 *         while 1:
 *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
 * 
 *             # If current iterator is not exhausted, return aligned read
 */
    ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter);

    /* "pysam/csamfile.pyx":1472
 * 
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval>0:             # <<<<<<<<<<<<<<
 *                 return makeAlignedRead(self.rowiter.b)
 * 
 */
    __pyx_t_3 = ((__pyx_v_self->rowiter->__pyx_base.retval > 0) != 0);
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":1473
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval>0:
 *                 return makeAlignedRead(self.rowiter.b)             # <<<<<<<<<<<<<<
 * 
 *             self.tid += 1
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_4 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_self->rowiter->__pyx_base.b); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;
    }

    /* "pysam/csamfile.pyx":1475
 *                 return makeAlignedRead(self.rowiter.b)
 * 
 *             self.tid += 1             # <<<<<<<<<<<<<<
 * 
 *             # Otherwise, proceed to next reference or stop
 */
    __pyx_v_self->tid = (__pyx_v_self->tid + 1);

    /* "pysam/csamfile.pyx":1478
 * 
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.nextiter()
 *             else:
 */
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1478; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":1479
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:
 *                 self.nextiter()             # <<<<<<<<<<<<<<
 *             else:
 *                 raise StopIteration
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":1481
 *                 self.nextiter()
 *             else:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L8:;
  }

  /* "pysam/csamfile.pyx":1456
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

  /* function exit code */
  __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_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1494
 *     """
 * 
 *     def __init__(self, Samfile samfile, positions, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_positions = 0;
  int __pyx_v_reopen;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_positions,&__pyx_n_s_reopen,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    __pyx_v_positions = values[1];
    if (values[2]) {
      __pyx_v_reopen = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_reopen = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_20IteratorRowSelection___init__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)__pyx_v_self), __pyx_v_samfile, __pyx_v_positions, __pyx_v_reopen);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  BGZF *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1494);

  /* "pysam/csamfile.pyx":1496
 *     def __init__(self, Samfile samfile, positions, int reopen=True):
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)             # <<<<<<<<<<<<<<
 * 
 *         self.positions = positions
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __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 = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reopen, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":1498
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 * 
 *         self.positions = positions             # <<<<<<<<<<<<<<
 *         self.current_pos = 0
 * 
 */
  __Pyx_INCREF(__pyx_v_positions);
  __Pyx_GIVEREF(__pyx_v_positions);
  __Pyx_GOTREF(__pyx_v_self->positions);
  __Pyx_DECREF(__pyx_v_self->positions);
  __pyx_v_self->positions = __pyx_v_positions;

  /* "pysam/csamfile.pyx":1499
 * 
 *         self.positions = positions
 *         self.current_pos = 0             # <<<<<<<<<<<<<<
 * 
 *         self.fp = self.htsfile.fp.bgzf
 */
  __pyx_v_self->current_pos = 0;

  /* "pysam/csamfile.pyx":1501
 *         self.current_pos = 0
 * 
 *         self.fp = self.htsfile.fp.bgzf             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_5 = __pyx_v_self->__pyx_base.htsfile->fp.bgzf;
  __pyx_v_self->fp = __pyx_t_5;

  /* "pysam/csamfile.pyx":1494
 *     """
 * 
 *     def __init__(self, Samfile samfile, positions, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, reopen=reopen)
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1503
 *         self.fp = self.htsfile.fp.bgzf
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_20IteratorRowSelection_2__iter__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1503);

  /* "pysam/csamfile.pyx":1504
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1503
 *         self.fp = self.htsfile.fp.bgzf
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1506
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_8csamfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1506);

  /* "pysam/csamfile.pyx":1507
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1506
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1509
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 * 
 */

static int __pyx_f_5pysam_8csamfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  int64_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1509);

  /* "pysam/csamfile.pyx":1513
 * 
 *         # end iteration if out of positions
 *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
 * 
 *         bgzf_seek(self.fp,
 */
  __pyx_t_1 = __pyx_v_self->positions;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((__pyx_v_self->current_pos >= __pyx_t_2) != 0);
  if (__pyx_t_3) {
    __pyx_r = -1;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":1516
 * 
 *         bgzf_seek(self.fp,
 *                   self.positions[self.current_pos],             # <<<<<<<<<<<<<<
 *                   0)
 *         self.current_pos += 1
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_int64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (int64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1515
 *         if self.current_pos >= len(self.positions): return -1
 * 
 *         bgzf_seek(self.fp,             # <<<<<<<<<<<<<<
 *                   self.positions[self.current_pos],
 *                   0)
 */
  bgzf_seek(__pyx_v_self->fp, __pyx_t_4, 0);

  /* "pysam/csamfile.pyx":1518
 *                   self.positions[self.current_pos],
 *                   0)
 *         self.current_pos += 1             # <<<<<<<<<<<<<<
 *         return sam_read1(self.htsfile,
 *                          self.samfile.header,
 */
  __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);

  /* "pysam/csamfile.pyx":1519
 *                   0)
 *         self.current_pos += 1
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.samfile.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1509
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("pysam.csamfile.IteratorRowSelection.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1523
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_20IteratorRowSelection_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_20IteratorRowSelection_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_20IteratorRowSelection_4__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1523);

  /* "pysam/csamfile.pyx":1529
 *         """
 * 
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if (ret >= 0):
 *             return makeAlignedRead(self.b)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/csamfile.pyx":1530
 * 
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedRead(self.b)
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1531
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):
 *             return makeAlignedRead(self.b)             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_8csamfile_makeAlignedRead(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1533
 *             return makeAlignedRead(self.b)
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1523
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.IteratorRowSelection.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1536
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

static int __pyx_f_5pysam_8csamfile___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_8csamfile___iterdata *__pyx_v_d;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__advance_all", 0);
  __Pyx_TraceCall("__advance_all", __pyx_f[0], 1536);

  /* "pysam/csamfile.pyx":1540
 *     '''
 *     cdef __iterdata * d
 *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     return sam_itr_next(d.htsfile, d.iter, b)
 * 
 */
  __pyx_v_d = ((__pyx_t_5pysam_8csamfile___iterdata *)__pyx_v_data);

  /* "pysam/csamfile.pyx":1541
 *     cdef __iterdata * d
 *     d = <__iterdata*>data
 *     return sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1536
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1544
 * 
 * 
 * cdef int __advance_snpcalls(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

static int __pyx_f_5pysam_8csamfile___advance_snpcalls(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_8csamfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_v_skip;
  int __pyx_v_q;
  int __pyx_v_is_cns;
  int __pyx_v_is_nobaq;
  int __pyx_v_capQ_thres;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int32_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__advance_snpcalls", 0);
  __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1544);

  /* "pysam/csamfile.pyx":1556
 *     # 2. bam_cap_mapQ
 *     cdef __iterdata * d
 *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
 * 
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 */
  __pyx_v_d = ((__pyx_t_5pysam_8csamfile___iterdata *)__pyx_v_data);

  /* "pysam/csamfile.pyx":1558
 *     d = <__iterdata*>data
 * 
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 *     cdef int skip = 0
 *     cdef int q
 */
  __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);

  /* "pysam/csamfile.pyx":1559
 * 
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 *     cdef int skip = 0             # <<<<<<<<<<<<<<
 *     cdef int q
 *     cdef int is_cns = 1
 */
  __pyx_v_skip = 0;

  /* "pysam/csamfile.pyx":1561
 *     cdef int skip = 0
 *     cdef int q
 *     cdef int is_cns = 1             # <<<<<<<<<<<<<<
 *     cdef int is_nobaq = 0
 *     cdef int capQ_thres = 0
 */
  __pyx_v_is_cns = 1;

  /* "pysam/csamfile.pyx":1562
 *     cdef int q
 *     cdef int is_cns = 1
 *     cdef int is_nobaq = 0             # <<<<<<<<<<<<<<
 *     cdef int capQ_thres = 0
 * 
 */
  __pyx_v_is_nobaq = 0;

  /* "pysam/csamfile.pyx":1563
 *     cdef int is_cns = 1
 *     cdef int is_nobaq = 0
 *     cdef int capQ_thres = 0             # <<<<<<<<<<<<<<
 * 
 *     # reload sequence
 */
  __pyx_v_capQ_thres = 0;

  /* "pysam/csamfile.pyx":1566
 * 
 *     # reload sequence
 *     if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
 *         if d.seq != NULL:
 *             free(d.seq)
 */
  __pyx_t_1 = ((__pyx_v_d->fastafile != NULL) != 0);
  if (__pyx_t_1) {
    __pyx_t_2 = ((__pyx_v_b->core.tid != __pyx_v_d->tid) != 0);
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":1567
 *     # reload sequence
 *     if d.fastafile != NULL and b.core.tid != d.tid:
 *         if d.seq != NULL:             # <<<<<<<<<<<<<<
 *             free(d.seq)
 *         d.tid = b.core.tid
 */
    __pyx_t_3 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":1568
 *     if d.fastafile != NULL and b.core.tid != d.tid:
 *         if d.seq != NULL:
 *             free(d.seq)             # <<<<<<<<<<<<<<
 *         d.tid = b.core.tid
 *         d.seq = faidx_fetch_seq(
 */
      free(__pyx_v_d->seq);
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "pysam/csamfile.pyx":1569
 *         if d.seq != NULL:
 *             free(d.seq)
 *         d.tid = b.core.tid             # <<<<<<<<<<<<<<
 *         d.seq = faidx_fetch_seq(
 *             d.fastafile,
 */
    __pyx_t_4 = __pyx_v_b->core.tid;
    __pyx_v_d->tid = __pyx_t_4;

    /* "pysam/csamfile.pyx":1570
 *             free(d.seq)
 *         d.tid = b.core.tid
 *         d.seq = faidx_fetch_seq(             # <<<<<<<<<<<<<<
 *             d.fastafile,
 *             d.header.target_name[d.tid],
 */
    __pyx_v_d->seq = faidx_fetch_seq(__pyx_v_d->fastafile, (__pyx_v_d->header->target_name[__pyx_v_d->tid]), 0, __pyx_v_5pysam_8csamfile_max_pos, (&__pyx_v_d->seq_len));

    /* "pysam/csamfile.pyx":1576
 *             &d.seq_len)
 * 
 *         if d.seq == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 */
    __pyx_t_3 = ((__pyx_v_d->seq == NULL) != 0);
    if (__pyx_t_3) {

      /* "pysam/csamfile.pyx":1579
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],             # <<<<<<<<<<<<<<
 *                  d.tid))
 * 
 */
      __pyx_t_5 = __Pyx_PyBytes_FromString((__pyx_v_d->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);

      /* "pysam/csamfile.pyx":1580
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],
 *                  d.tid))             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_d->tid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);

      /* "pysam/csamfile.pyx":1579
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],             # <<<<<<<<<<<<<<
 *                  d.tid))
 * 
 */
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __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_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_5 = 0;
      __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":1578
 *         if d.seq == NULL:
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \             # <<<<<<<<<<<<<<
 *                 (d.header.target_name[d.tid],
 *                  d.tid))
 */
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_reference_sequence_for_s_tid_i_n, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/csamfile.pyx":1577
 * 
 *         if d.seq == NULL:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],
 */
      __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __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, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1583
 * 
 * 
 *     while ret >= 0:             # <<<<<<<<<<<<<<
 *         skip = 0
 * 
 */
  while (1) {
    __pyx_t_3 = ((__pyx_v_ret >= 0) != 0);
    if (!__pyx_t_3) break;

    /* "pysam/csamfile.pyx":1584
 * 
 *     while ret >= 0:
 *         skip = 0             # <<<<<<<<<<<<<<
 * 
 *         # realign read - changes base qualities
 */
    __pyx_v_skip = 0;

    /* "pysam/csamfile.pyx":1587
 * 
 *         # realign read - changes base qualities
 *         if d.seq != NULL and is_cns and not is_nobaq:             # <<<<<<<<<<<<<<
 *             bam_prob_realn(b, d.seq)
 * 
 */
    __pyx_t_3 = (__pyx_v_d->seq != NULL);
    if (__pyx_t_3) {
      if ((__pyx_v_is_cns != 0)) {
        __pyx_t_1 = (!(__pyx_v_is_nobaq != 0));
        __pyx_t_2 = __pyx_t_1;
      } else {
        __pyx_t_2 = (__pyx_v_is_cns != 0);
      }
      __pyx_t_1 = __pyx_t_2;
    } else {
      __pyx_t_1 = __pyx_t_3;
    }
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1588
 *         # realign read - changes base qualities
 *         if d.seq != NULL and is_cns and not is_nobaq:
 *             bam_prob_realn(b, d.seq)             # <<<<<<<<<<<<<<
 * 
 *         if d.seq != NULL and capQ_thres > 10:
 */
      bam_prob_realn(__pyx_v_b, __pyx_v_d->seq);
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "pysam/csamfile.pyx":1590
 *             bam_prob_realn(b, d.seq)
 * 
 *         if d.seq != NULL and capQ_thres > 10:             # <<<<<<<<<<<<<<
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
 *             if q < 0:
 */
    __pyx_t_1 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_1) {
      __pyx_t_3 = ((__pyx_v_capQ_thres > 10) != 0);
      __pyx_t_2 = __pyx_t_3;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":1591
 * 
 *         if d.seq != NULL and capQ_thres > 10:
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)             # <<<<<<<<<<<<<<
 *             if q < 0:
 *                 skip = 1
 */
      __pyx_v_q = bam_cap_mapQ(__pyx_v_b, __pyx_v_d->seq, __pyx_v_capQ_thres);

      /* "pysam/csamfile.pyx":1592
 *         if d.seq != NULL and capQ_thres > 10:
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
 *             if q < 0:             # <<<<<<<<<<<<<<
 *                 skip = 1
 *             elif b.core.qual > q:
 */
      __pyx_t_2 = ((__pyx_v_q < 0) != 0);
      if (__pyx_t_2) {

        /* "pysam/csamfile.pyx":1593
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
 *             if q < 0:
 *                 skip = 1             # <<<<<<<<<<<<<<
 *             elif b.core.qual > q:
 *                 b.core.qual = q
 */
        __pyx_v_skip = 1;
        goto __pyx_L10;
      }

      /* "pysam/csamfile.pyx":1594
 *             if q < 0:
 *                 skip = 1
 *             elif b.core.qual > q:             # <<<<<<<<<<<<<<
 *                 b.core.qual = q
 *         if b.core.flag & BAM_FUNMAP:
 */
      __pyx_t_2 = ((__pyx_v_b->core.qual > __pyx_v_q) != 0);
      if (__pyx_t_2) {

        /* "pysam/csamfile.pyx":1595
 *                 skip = 1
 *             elif b.core.qual > q:
 *                 b.core.qual = q             # <<<<<<<<<<<<<<
 *         if b.core.flag & BAM_FUNMAP:
 *             skip = 1
 */
        __pyx_v_b->core.qual = __pyx_v_q;
        goto __pyx_L10;
      }
      __pyx_L10:;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "pysam/csamfile.pyx":1596
 *             elif b.core.qual > q:
 *                 b.core.qual = q
 *         if b.core.flag & BAM_FUNMAP:             # <<<<<<<<<<<<<<
 *             skip = 1
 *         elif b.core.flag & 1 and not b.core.flag & 2:
 */
    __pyx_t_2 = ((__pyx_v_b->core.flag & BAM_FUNMAP) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":1597
 *                 b.core.qual = q
 *         if b.core.flag & BAM_FUNMAP:
 *             skip = 1             # <<<<<<<<<<<<<<
 *         elif b.core.flag & 1 and not b.core.flag & 2:
 *             skip = 1
 */
      __pyx_v_skip = 1;
      goto __pyx_L11;
    }

    /* "pysam/csamfile.pyx":1598
 *         if b.core.flag & BAM_FUNMAP:
 *             skip = 1
 *         elif b.core.flag & 1 and not b.core.flag & 2:             # <<<<<<<<<<<<<<
 *             skip = 1
 * 
 */
    if (((__pyx_v_b->core.flag & 1) != 0)) {
      __pyx_t_2 = (!((__pyx_v_b->core.flag & 2) != 0));
      __pyx_t_1 = __pyx_t_2;
    } else {
      __pyx_t_1 = ((__pyx_v_b->core.flag & 1) != 0);
    }
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1599
 *             skip = 1
 *         elif b.core.flag & 1 and not b.core.flag & 2:
 *             skip = 1             # <<<<<<<<<<<<<<
 * 
 *         if not skip: break
 */
      __pyx_v_skip = 1;
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "pysam/csamfile.pyx":1601
 *             skip = 1
 * 
 *         if not skip: break             # <<<<<<<<<<<<<<
 *         # additional filters
 * 
 */
    __pyx_t_1 = ((!(__pyx_v_skip != 0)) != 0);
    if (__pyx_t_1) {
      goto __pyx_L7_break;
    }

    /* "pysam/csamfile.pyx":1604
 *         # additional filters
 * 
 *         ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 * 
 *     return ret
 */
    __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
  }
  __pyx_L7_break:;

  /* "pysam/csamfile.pyx":1606
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 * 
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * cdef class IteratorColumn:
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1544
 * 
 * 
 * cdef int __advance_snpcalls(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_WriteUnraisable("pysam.csamfile.__advance_snpcalls", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1658
 *     '''
 * 
 *     def __cinit__( self, Samfile samfile, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         # TODO
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1658; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[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 = 1658; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorColumn___cinit__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1658);

  /* "pysam/csamfile.pyx":1659
 * 
 *     def __cinit__( self, Samfile samfile, **kwargs ):
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 *         # TODO
 *         # self.mask = kwargs.get("mask", BAM_DEF_MASK )
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GOTREF(__pyx_v_self->samfile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/csamfile.pyx":1662
 *         # TODO
 *         # self.mask = kwargs.get("mask", BAM_DEF_MASK )
 *         self.fastafile = kwargs.get("fastafile", None)             # <<<<<<<<<<<<<<
 *         self.stepper = kwargs.get("stepper", None)
 *         self.max_depth = kwargs.get("max_depth", 8000)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_fastafile, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1662; __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_5pysam_6cfaidx_Fastafile))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->fastafile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_v_self->fastafile = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1663
 *         # self.mask = kwargs.get("mask", BAM_DEF_MASK )
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", None)             # <<<<<<<<<<<<<<
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.iterdata.seq = NULL
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_stepper, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->stepper);
  __Pyx_DECREF(__pyx_v_self->stepper);
  __pyx_v_self->stepper = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1664
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", None)
 *         self.max_depth = kwargs.get("max_depth", 8000)             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.tid = 0
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_max_depth, __pyx_int_8000); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->max_depth = __pyx_t_2;

  /* "pysam/csamfile.pyx":1665
 *         self.stepper = kwargs.get("stepper", None)
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.tid = 0
 *         self.pos = 0
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/csamfile.pyx":1666
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.iterdata.seq = NULL
 *         self.tid = 0             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         self.n_plp = 0
 */
  __pyx_v_self->tid = 0;

  /* "pysam/csamfile.pyx":1667
 *         self.iterdata.seq = NULL
 *         self.tid = 0
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         self.n_plp = 0
 *         self.plp = NULL
 */
  __pyx_v_self->pos = 0;

  /* "pysam/csamfile.pyx":1668
 *         self.tid = 0
 *         self.pos = 0
 *         self.n_plp = 0             # <<<<<<<<<<<<<<
 *         self.plp = NULL
 *         self.pileup_iter = <bam_plp_t>NULL
 */
  __pyx_v_self->n_plp = 0;

  /* "pysam/csamfile.pyx":1669
 *         self.pos = 0
 *         self.n_plp = 0
 *         self.plp = NULL             # <<<<<<<<<<<<<<
 *         self.pileup_iter = <bam_plp_t>NULL
 * 
 */
  __pyx_v_self->plp = NULL;

  /* "pysam/csamfile.pyx":1670
 *         self.n_plp = 0
 *         self.plp = NULL
 *         self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->pileup_iter = ((bam_plp_t)NULL);

  /* "pysam/csamfile.pyx":1658
 *     '''
 * 
 *     def __cinit__( self, Samfile samfile, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         # TODO
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1672
 *         self.pileup_iter = <bam_plp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorColumn_2__iter__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1672);

  /* "pysam/csamfile.pyx":1673
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1672
 *         self.pileup_iter = <bam_plp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1675
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

static int __pyx_f_5pysam_8csamfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1675);

  /* "pysam/csamfile.pyx":1678
 *         '''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));

  /* "pysam/csamfile.pyx":1675
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

  /* function exit code */
  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1683
 *                                  &self.n_plp )
 * 
 *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

static char *__pyx_f_5pysam_8csamfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("getSequence", 0);
  __Pyx_TraceCall("getSequence", __pyx_f[0], 1683);

  /* "pysam/csamfile.pyx":1686
 *         '''return current reference sequence underlying the iterator.
 *         '''
 *         return self.iterdata.seq             # <<<<<<<<<<<<<<
 * 
 *     property seq_len:
 */
  __pyx_r = __pyx_v_self->iterdata.seq;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1683
 *                                  &self.n_plp )
 * 
 *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1690
 *     property seq_len:
 *         '''current sequence length.'''
 *         def __get__(self): return self.iterdata.seq_len             # <<<<<<<<<<<<<<
 * 
 *     def addReference(self, Fastafile fastafile):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorColumn_7seq_len___get__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1690);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumn.seq_len.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1692
 *         def __get__(self): return self.iterdata.seq_len
 * 
 *     def addReference(self, Fastafile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in *fastafile* to iterator.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/
static char __pyx_doc_5pysam_8csamfile_14IteratorColumn_4addReference[] = "IteratorColumn.addReference(self, Fastafile fastafile)\n\n       add reference sequences in *fastafile* to iterator.";
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("addReference (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_6cfaidx_Fastafile, 1, "fastafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorColumn_4addReference(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)__pyx_v_fastafile));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_4addReference(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_6cfaidx_Fastafile *__pyx_v_fastafile) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  faidx_t *__pyx_t_2;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("addReference", 0);
  __Pyx_TraceCall("addReference", __pyx_f[0], 1692);

  /* "pysam/csamfile.pyx":1695
 *        '''
 *        add reference sequences in *fastafile* to iterator.'''
 *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_fastafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fastafile));
  __Pyx_GOTREF(__pyx_v_self->fastafile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_v_self->fastafile = __pyx_v_fastafile;

  /* "pysam/csamfile.pyx":1696
 *        add reference sequences in *fastafile* to iterator.'''
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile
 */
  __pyx_t_1 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
  if (__pyx_t_1) {
    free(__pyx_v_self->iterdata.seq);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1697
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
 *        self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/csamfile.pyx":1698
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 * 
 *     def hasReference(self):
 */
  __pyx_t_2 = __pyx_v_self->fastafile->fastafile;
  __pyx_v_self->iterdata.fastafile = __pyx_t_2;

  /* "pysam/csamfile.pyx":1692
 *         def __get__(self): return self.iterdata.seq_len
 * 
 *     def addReference(self, Fastafile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in *fastafile* to iterator.'''
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1700
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_14IteratorColumn_6hasReference[] = "IteratorColumn.hasReference(self)\n\n        return true if iterator is associated with a reference";
static PyObject *__pyx_pw_5pysam_8csamfile_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("hasReference (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_14IteratorColumn_6hasReference(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_14IteratorColumn_6hasReference(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("hasReference", 0);
  __Pyx_TraceCall("hasReference", __pyx_f[0], 1700);

  /* "pysam/csamfile.pyx":1703
 *         '''
 *         return true if iterator is associated with a reference'''
 *         return self.fastafile             # <<<<<<<<<<<<<<
 * 
 *     cdef setMask(self, mask):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_r = ((PyObject *)__pyx_v_self->fastafile);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1700
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1705
 *         return self.fastafile
 * 
 *     cdef setMask(self, mask):             # <<<<<<<<<<<<<<
 *         '''set masking flag in iterator.
 * 
 */

static PyObject *__pyx_f_5pysam_8csamfile_14IteratorColumn_setMask(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_mask) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setMask", 0);
  __Pyx_TraceCall("setMask", __pyx_f[0], 1705);

  /* "pysam/csamfile.pyx":1710
 *         reads with bits set in *mask* will be skipped.
 *         '''
 *         raise NotImplementedError()             # <<<<<<<<<<<<<<
 *         # self.mask = mask
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":1705
 *         return self.fastafile
 * 
 *     cdef setMask(self, mask):             # <<<<<<<<<<<<<<
 *         '''set masking flag in iterator.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumn.setMask", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1714
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
 *                             int tid,
 *                             int start,
 */

static PyObject *__pyx_f_5pysam_8csamfile_14IteratorColumn_setupIteratorData(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData *__pyx_optional_args) {
  int __pyx_v_reopen = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  htsFile *__pyx_t_6;
  hts_itr_t *__pyx_t_7;
  bam_hdr_t *__pyx_t_8;
  int __pyx_t_9;
  faidx_t *__pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setupIteratorData", 0);
  __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 1714);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_reopen = __pyx_optional_args->reopen;
    }
  }

  /* "pysam/csamfile.pyx":1721
 *         '''setup the iterator structure'''
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, end, reopen)             # <<<<<<<<<<<<<<
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_tid); 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_t_2 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowRegion)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF(__pyx_v_self->iter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":1722
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, end, reopen)
 *         self.iterdata.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 */
  __pyx_t_6 = __pyx_v_self->samfile->htsfile;
  __pyx_v_self->iterdata.htsfile = __pyx_t_6;

  /* "pysam/csamfile.pyx":1723
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, end, reopen)
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 */
  __pyx_t_7 = __pyx_v_self->iter->iter;
  __pyx_v_self->iterdata.iter = __pyx_t_7;

  /* "pysam/csamfile.pyx":1724
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/csamfile.pyx":1725
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *         self.iterdata.header = self.samfile.header
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/csamfile.pyx":1726
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile != None:
 */
  __pyx_t_8 = __pyx_v_self->samfile->header;
  __pyx_v_self->iterdata.header = __pyx_t_8;

  /* "pysam/csamfile.pyx":1728
 *         self.iterdata.header = self.samfile.header
 * 
 *         if self.fastafile != None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
  __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_self->fastafile), Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_9) {

    /* "pysam/csamfile.pyx":1729
 * 
 *         if self.fastafile != None:
 *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 *         else:
 *             self.iterdata.fastafile = NULL
 */
    __pyx_t_10 = __pyx_v_self->fastafile->fastafile;
    __pyx_v_self->iterdata.fastafile = __pyx_t_10;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1731
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.stepper == None or self.stepper == "all":
 */
    __pyx_v_self->iterdata.fastafile = NULL;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1733
 *             self.iterdata.fastafile = NULL
 * 
 *         if self.stepper == None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             self.pileup_iter = bam_plp_init(
 *                 <bam_plp_auto_f>&__advance_all,
 */
  __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_9) {
    __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = __pyx_t_11;
  } else {
    __pyx_t_12 = __pyx_t_9;
  }
  if (__pyx_t_12) {

    /* "pysam/csamfile.pyx":1734
 * 
 *         if self.stepper == None or self.stepper == "all":
 *             self.pileup_iter = bam_plp_init(             # <<<<<<<<<<<<<<
 *                 <bam_plp_auto_f>&__advance_all,
 *                 &self.iterdata)
 */
    __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_8csamfile___advance_all)), (&__pyx_v_self->iterdata));
    goto __pyx_L4;
  }

  /* "pysam/csamfile.pyx":1737
 *                 <bam_plp_auto_f>&__advance_all,
 *                 &self.iterdata)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             self.pileup_iter = bam_plp_init(
 *                 <bam_plp_auto_f>&__advance_snpcalls,
 */
  __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_samtools, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_12) {

    /* "pysam/csamfile.pyx":1738
 *                 &self.iterdata)
 *         elif self.stepper == "samtools":
 *             self.pileup_iter = bam_plp_init(             # <<<<<<<<<<<<<<
 *                 <bam_plp_auto_f>&__advance_snpcalls,
 *                 &self.iterdata)
 */
    __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_8csamfile___advance_snpcalls)), (&__pyx_v_self->iterdata));
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1743
 *         else:
 *             raise ValueError(
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
 * 
 *         if self.max_depth:
 */
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/csamfile.pyx":1742
 *                 &self.iterdata)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1742; __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);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L4:;

  /* "pysam/csamfile.pyx":1745
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             bam_plp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
  __pyx_t_12 = (__pyx_v_self->max_depth != 0);
  if (__pyx_t_12) {

    /* "pysam/csamfile.pyx":1746
 * 
 *         if self.max_depth:
 *             bam_plp_set_maxcnt(self.pileup_iter, self.max_depth)             # <<<<<<<<<<<<<<
 * 
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 */
    bam_plp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "pysam/csamfile.pyx":1714
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
 *                             int tid,
 *                             int start,
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorColumn.setupIteratorData", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1750
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

static PyObject *__pyx_f_5pysam_8csamfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_end) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  hts_itr_t *__pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("reset", 0);
  __Pyx_TraceCall("reset", __pyx_f[0], 1750);

  /* "pysam/csamfile.pyx":1756
 *         having to incur the full set-up costs.
 *         '''
 *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 * 
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
  __Pyx_INCREF(__pyx_v_tid);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reopen, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowRegion)), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __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_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->iter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":1757
 *         '''
 *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 * 
 *         # invalidate sequence if different tid
 */
  __pyx_t_4 = __pyx_v_self->iter->iter;
  __pyx_v_self->iterdata.iter = __pyx_t_4;

  /* "pysam/csamfile.pyx":1760
 * 
 *         # invalidate sequence if different tid
 *         if self.tid != tid:             # <<<<<<<<<<<<<<
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
 *             self.iterdata.seq = NULL
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":1761
 *         # invalidate sequence if different tid
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1
 */
    __pyx_t_5 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
    if (__pyx_t_5) {
      free(__pyx_v_self->iterdata.seq);
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "pysam/csamfile.pyx":1762
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *             self.iterdata.tid = -1
 * 
 */
    __pyx_v_self->iterdata.seq = NULL;

    /* "pysam/csamfile.pyx":1763
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 * 
 *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
 */
    __pyx_v_self->iterdata.tid = -1;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1766
 * 
 *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
 *         bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  bam_plp_reset(__pyx_v_self->pileup_iter);

  /* "pysam/csamfile.pyx":1750
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorColumn.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1768
 *         bam_plp_reset(self.pileup_iter)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 */

/* Python wrapper */
static void __pyx_pw_5pysam_8csamfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_8csamfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_8csamfile_14IteratorColumn_8__dealloc__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_8csamfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1768);

  /* "pysam/csamfile.pyx":1771
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 *         if self.pileup_iter != <bam_plp_t>NULL:             # <<<<<<<<<<<<<<
 *             bam_plp_reset(self.pileup_iter)
 *             bam_plp_destroy(self.pileup_iter)
 */
  __pyx_t_1 = ((__pyx_v_self->pileup_iter != ((bam_plp_t)NULL)) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1772
 *         # that have not been fully consumed
 *         if self.pileup_iter != <bam_plp_t>NULL:
 *             bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 *             bam_plp_destroy(self.pileup_iter)
 *             self.pileup_iter = <bam_plp_t>NULL
 */
    bam_plp_reset(__pyx_v_self->pileup_iter);

    /* "pysam/csamfile.pyx":1773
 *         if self.pileup_iter != <bam_plp_t>NULL:
 *             bam_plp_reset(self.pileup_iter)
 *             bam_plp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
 *             self.pileup_iter = <bam_plp_t>NULL
 *             self.plp = <bam_pileup1_t*>NULL
 */
    bam_plp_destroy(__pyx_v_self->pileup_iter);

    /* "pysam/csamfile.pyx":1774
 *             bam_plp_reset(self.pileup_iter)
 *             bam_plp_destroy(self.pileup_iter)
 *             self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
 *             self.plp = <bam_pileup1_t*>NULL
 * 
 */
    __pyx_v_self->pileup_iter = ((bam_plp_t)NULL);

    /* "pysam/csamfile.pyx":1775
 *             bam_plp_destroy(self.pileup_iter)
 *             self.pileup_iter = <bam_plp_t>NULL
 *             self.plp = <bam_pileup1_t*>NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.iterdata.seq != NULL:
 */
    __pyx_v_self->plp = ((bam_pileup1_t *)NULL);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1777
 *             self.plp = <bam_pileup1_t*>NULL
 * 
 *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1778
 * 
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 * 
 */
    free(__pyx_v_self->iterdata.seq);

    /* "pysam/csamfile.pyx":1779
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_self->iterdata.seq = NULL;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysam/csamfile.pyx":1768
 *         bam_plp_reset(self.pileup_iter)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/csamfile.pyx":1785
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self, Samfile samfile,             # <<<<<<<<<<<<<<
 *                   int tid = 0,
 *                   int start = 0,
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_start;
  int __pyx_v_end;
  int __pyx_v_truncate;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_truncate,0};
    PyObject* values[5] = {0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tid);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1785; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    if (values[1]) {
      __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_tid = ((int)0);
    }
    if (values[2]) {
      __pyx_v_start = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_start = ((int)0);
    }
    if (values[3]) {
      __pyx_v_end = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1788; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_end = __pyx_k__57;
    }
    if (values[4]) {
      __pyx_v_truncate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1789; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysam/csamfile.pyx":1789
 *                   int start = 0,
 *                   int end = max_pos,
 *                   int truncate = False,             # <<<<<<<<<<<<<<
 *                   **kwargs ):
 * 
 */
      __pyx_v_truncate = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1785; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end, __pyx_v_truncate, __pyx_v_kwargs);

  /* "pysam/csamfile.pyx":1785
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self, Samfile samfile,             # <<<<<<<<<<<<<<
 *                   int tid = 0,
 *                   int start = 0,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1785);

  /* "pysam/csamfile.pyx":1793
 * 
 *         # initialize iterator
 *         self.setupIteratorData( tid, start, end, 1 )             # <<<<<<<<<<<<<<
 *         self.start = start
 *         self.end = end
 */
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.reopen = 1;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_end, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1794
 *         # initialize iterator
 *         self.setupIteratorData( tid, start, end, 1 )
 *         self.start = start             # <<<<<<<<<<<<<<
 *         self.end = end
 *         self.truncate = truncate
 */
  __pyx_v_self->start = __pyx_v_start;

  /* "pysam/csamfile.pyx":1795
 *         self.setupIteratorData( tid, start, end, 1 )
 *         self.start = start
 *         self.end = end             # <<<<<<<<<<<<<<
 *         self.truncate = truncate
 * 
 */
  __pyx_v_self->end = __pyx_v_end;

  /* "pysam/csamfile.pyx":1796
 *         self.start = start
 *         self.end = end
 *         self.truncate = truncate             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_v_self->truncate = __pyx_v_truncate;

  /* "pysam/csamfile.pyx":1785
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self, Samfile samfile,             # <<<<<<<<<<<<<<
 *                   int tid = 0,
 *                   int start = 0,
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1798
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_20IteratorColumnRegion_2__next__[] = "python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_20IteratorColumnRegion_2__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_20IteratorColumnRegion_2__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1798);

  /* "pysam/csamfile.pyx":1802
 *         """
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.cnext()
 *             if self.n_plp < 0:
 */
  while (1) {

    /* "pysam/csamfile.pyx":1803
 * 
 *         while 1:
 *             self.cnext()             # <<<<<<<<<<<<<<
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )
 */
    ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self));

    /* "pysam/csamfile.pyx":1804
 *         while 1:
 *             self.cnext()
 *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.n_plp < 0) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1805
 *             self.cnext()
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL:
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":1807
 *                 raise ValueError("error during iteration" )
 * 
 *             if self.plp == NULL:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.plp == NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1808
 * 
 *             if self.plp == NULL:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             if self.truncate:
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":1810
 *                 raise StopIteration
 * 
 *             if self.truncate:             # <<<<<<<<<<<<<<
 *                 if self.start > self.pos: continue
 *                 if self.pos >= self.end: raise StopIteration
 */
    __pyx_t_1 = (__pyx_v_self->truncate != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1811
 * 
 *             if self.truncate:
 *                 if self.start > self.pos: continue             # <<<<<<<<<<<<<<
 *                 if self.pos >= self.end: raise StopIteration
 * 
 */
      __pyx_t_1 = ((__pyx_v_self->start > __pyx_v_self->__pyx_base.pos) != 0);
      if (__pyx_t_1) {
        goto __pyx_L3_continue;
      }

      /* "pysam/csamfile.pyx":1812
 *             if self.truncate:
 *                 if self.start > self.pos: continue
 *                 if self.pos >= self.end: raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             return makePileupProxy(&self.plp,
 */
      __pyx_t_1 = ((__pyx_v_self->__pyx_base.pos >= __pyx_v_self->end) != 0);
      if (__pyx_t_1) {
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "pysam/csamfile.pyx":1814
 *                 if self.pos >= self.end: raise StopIteration
 * 
 *             return makePileupProxy(&self.plp,             # <<<<<<<<<<<<<<
 *                                    self.tid,
 *                                    self.pos,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/csamfile.pyx":1817
 *                                    self.tid,
 *                                    self.pos,
 *                                    self.n_plp)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_2 = __pyx_f_5pysam_8csamfile_makePileupProxy((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1814; __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_L3_continue:;
  }

  /* "pysam/csamfile.pyx":1798
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumnRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1824
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   Samfile samfile,
 *                   **kwargs):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,0};
    PyObject* values[1] = {0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1824; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[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 = 1824; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1824);

  /* "pysam/csamfile.pyx":1829
 * 
 *         # no iteration over empty files
 *         if not samfile.nreferences:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1829; __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 = 1829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":1830
 *         # no iteration over empty files
 *         if not samfile.nreferences:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         # initialize iterator
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":1833
 * 
 *         # initialize iterator
 *         self.setupIteratorData(self.tid, 0, max_pos, 1)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.reopen = 1;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_8csamfile_max_pos, &__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1824
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   Samfile samfile,
 *                   **kwargs):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1835
 *         self.setupIteratorData(self.tid, 0, max_pos, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__[] = "python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__(((struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1835);

  /* "pysam/csamfile.pyx":1839
 *         """
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.cnext()
 * 
 */
  while (1) {

    /* "pysam/csamfile.pyx":1840
 * 
 *         while 1:
 *             self.cnext()             # <<<<<<<<<<<<<<
 * 
 *             if self.n_plp < 0:
 */
    ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self));

    /* "pysam/csamfile.pyx":1842
 *             self.cnext()
 * 
 *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.n_plp < 0) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1843
 * 
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             # return result, if within same reference
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/csamfile.pyx":1846
 * 
 *             # return result, if within same reference
 *             if self.plp != NULL:             # <<<<<<<<<<<<<<
 *                 return makePileupProxy(&self.plp,
 *                                        self.tid,
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.plp != NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1847
 *             # return result, if within same reference
 *             if self.plp != NULL:
 *                 return makePileupProxy(&self.plp,             # <<<<<<<<<<<<<<
 *                                        self.tid,
 *                                        self.pos,
 */
      __Pyx_XDECREF(__pyx_r);

      /* "pysam/csamfile.pyx":1850
 *                                        self.tid,
 *                                        self.pos,
 *                                        self.n_plp)             # <<<<<<<<<<<<<<
 * 
 *             # otherwise, proceed to next reference or stop
 */
      __pyx_t_2 = __pyx_f_5pysam_8csamfile_makePileupProxy((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;
    }

    /* "pysam/csamfile.pyx":1853
 * 
 *             # otherwise, proceed to next reference or stop
 *             self.tid += 1             # <<<<<<<<<<<<<<
 *             if self.tid < self.samfile.nreferences:
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)
 */
    __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1);

    /* "pysam/csamfile.pyx":1854
 *             # otherwise, proceed to next reference or stop
 *             self.tid += 1
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)
 *             else:
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1855
 *             self.tid += 1
 *             if self.tid < self.samfile.nreferences:
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)             # <<<<<<<<<<<<<<
 *             else:
 *                 raise StopIteration
 */
      __pyx_t_5.__pyx_n = 1;
      __pyx_t_5.reopen = 0;
      __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_8csamfile_max_pos, &__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":1857
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)
 *             else:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * ##-------------------------------------------------------------------
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L7:;
  }

  /* "pysam/csamfile.pyx":1835
 *         self.setupIteratorData(self.tid, 0, max_pos, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

  /* function exit code */
  __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("pysam.csamfile.IteratorColumnAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1862
 * ##-------------------------------------------------------------------
 * ##-------------------------------------------------------------------
 * cdef inline int32_t query_start(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

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

  /* "pysam/csamfile.pyx":1865
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
 * 
 *     if pysam_get_n_cigar(src):
 */
  __pyx_v_start_offset = 0;

  /* "pysam/csamfile.pyx":1867
 *     cdef uint32_t start_offset = 0
 * 
 *     if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_t_1 = (pysam_get_n_cigar(__pyx_v_src) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1868
 * 
 *     if pysam_get_n_cigar(src):
 *         cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

    /* "pysam/csamfile.pyx":1869
 *     if pysam_get_n_cigar(src):
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 */
    __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src);
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {

      /* "pysam/csamfile.pyx":1870
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             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]) & BAM_CIGAR_MASK);

      /* "pysam/csamfile.pyx":1871
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             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')
 */
      __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
      if (__pyx_t_1) {

        /* "pysam/csamfile.pyx":1872
 *             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_1 = ((__pyx_v_start_offset != 0) != 0);
        if (__pyx_t_1) {
          __pyx_t_3 = ((__pyx_v_start_offset != __pyx_v_src->core.l_qseq) != 0);
          __pyx_t_4 = __pyx_t_3;
        } else {
          __pyx_t_4 = __pyx_t_1;
        }
        if (__pyx_t_4) {

          /* "pysam/csamfile.pyx":1873
 *             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_Invalid_clipping_in_CIGAR_string);

          /* "pysam/csamfile.pyx":1874
 *                 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;
      }

      /* "pysam/csamfile.pyx":1875
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
      __pyx_t_4 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
      if (__pyx_t_4) {

        /* "pysam/csamfile.pyx":1876
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":1878
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     return start_offset
 */
        goto __pyx_L5_break;
      }
      __pyx_L6:;
    }
    __pyx_L5_break:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1880
 *                 break
 * 
 *     return start_offset             # <<<<<<<<<<<<<<
 * 
 * ##-------------------------------------------------------------------
 */
  __pyx_r = __pyx_v_start_offset;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1862
 * ##-------------------------------------------------------------------
 * ##-------------------------------------------------------------------
 * cdef inline int32_t query_start(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1885
 * ##-------------------------------------------------------------------
 * ##-------------------------------------------------------------------
 * cdef inline int32_t query_end(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

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

  /* "pysam/csamfile.pyx":1888
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     if pysam_get_n_cigar(src) > 1:
 */
  __pyx_t_1 = __pyx_v_src->core.l_qseq;
  __pyx_v_end_offset = __pyx_t_1;

  /* "pysam/csamfile.pyx":1890
 *     cdef uint32_t end_offset = src.core.l_qseq
 * 
 *     if pysam_get_n_cigar(src) > 1:             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) > 1) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":1891
 * 
 *     if pysam_get_n_cigar(src) > 1:
 *         cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

    /* "pysam/csamfile.pyx":1892
 *     if pysam_get_n_cigar(src) > 1:
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 */
    for (__pyx_v_k = pysam_get_n_cigar(__pyx_v_src)-1; __pyx_v_k >= 1; __pyx_v_k--) {

      /* "pysam/csamfile.pyx":1893
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > 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]) & BAM_CIGAR_MASK);

      /* "pysam/csamfile.pyx":1894
 *         for k from pysam_get_n_cigar(src) > 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,
 */
      __pyx_t_2 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
      if (__pyx_t_2) {

        /* "pysam/csamfile.pyx":1895
 *             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')
 */
        __pyx_t_2 = ((__pyx_v_end_offset != 0) != 0);
        if (__pyx_t_2) {
          __pyx_t_3 = ((__pyx_v_end_offset != __pyx_v_src->core.l_qseq) != 0);
          __pyx_t_4 = __pyx_t_3;
        } else {
          __pyx_t_4 = __pyx_t_2;
        }
        if (__pyx_t_4) {

          /* "pysam/csamfile.pyx":1896
 *             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
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_Invalid_clipping_in_CIGAR_string);

          /* "pysam/csamfile.pyx":1898
 *                     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;
      }

      /* "pysam/csamfile.pyx":1899
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
      __pyx_t_4 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
      if (__pyx_t_4) {

        /* "pysam/csamfile.pyx":1900
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_end_offset = (__pyx_v_end_offset - ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":1902
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     if end_offset == 0:
 */
        goto __pyx_L5_break;
      }
      __pyx_L6:;
    }
    __pyx_L5_break:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1904
 *                 break
 * 
 *     if end_offset == 0:             # <<<<<<<<<<<<<<
 *         end_offset = src.core.l_qseq
 * 
 */
  __pyx_t_4 = ((__pyx_v_end_offset == 0) != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":1905
 * 
 *     if end_offset == 0:
 *         end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     return end_offset
 */
    __pyx_t_1 = __pyx_v_src->core.l_qseq;
    __pyx_v_end_offset = __pyx_t_1;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "pysam/csamfile.pyx":1907
 *         end_offset = src.core.l_qseq
 * 
 *     return end_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_end_offset;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1885
 * ##-------------------------------------------------------------------
 * ##-------------------------------------------------------------------
 * cdef inline int32_t query_end(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1910
 * 
 * 
 * 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_5pysam_8csamfile_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;
  PyObject *__pyx_v_seq = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  uint32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("get_seq_range", 0);
  __Pyx_TraceCall("get_seq_range", __pyx_f[0], 1910);

  /* "pysam/csamfile.pyx":1915
 *     cdef char * s
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_src->core.l_qseq != 0)) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1916
 * 
 *     if not src.core.l_qseq:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":1918
 *         return None
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)
 */
  __pyx_t_2 = PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_seq = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1919
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 *     s   = <char*>seq             # <<<<<<<<<<<<<<
 *     p   = pysam_bam_get_seq(src)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = ((char *)__pyx_t_3);

  /* "pysam/csamfile.pyx":1920
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 * 
 *     for k from start <= k < end:
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysam/csamfile.pyx":1922
 *     p   = pysam_bam_get_seq(src)
 * 
 *     for k from start <= k < end:             # <<<<<<<<<<<<<<
 *         # equivalent to seq_nt16_str[bam1_seqi(s, i)] (see bam.c)
 *         # note: do not use string literal as it will be a python string
 */
  __pyx_t_4 = __pyx_v_end;
  for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

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

  /* "pysam/csamfile.pyx":1927
 *         s[k-start] = seq_nt16_str[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;

  /* "pysam/csamfile.pyx":1910
 * 
 * 
 * cdef inline object get_seq_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *     cdef uint8_t * p
 *     cdef uint32_t k
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.get_seq_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1930
 * 
 * 
 * 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_5pysam_8csamfile_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 = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  uint32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("get_qual_range", 0);
  __Pyx_TraceCall("get_qual_range", __pyx_f[0], 1930);

  /* "pysam/csamfile.pyx":1935
 *     cdef char * q
 * 
 *     p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *     if p[0] == 0xff:
 *         return None
 */
  __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

  /* "pysam/csamfile.pyx":1936
 * 
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = (((__pyx_v_p[0]) == 0xff) != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":1937
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     qual = PyBytes_FromStringAndSize(NULL, end - start)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":1939
 *         return None
 * 
 *     qual = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
 *     q    = <char*>qual
 * 
 */
  __pyx_t_2 = PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_qual = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":1940
 * 
 *     qual = PyBytes_FromStringAndSize(NULL, end - start)
 *     q    = <char*>qual             # <<<<<<<<<<<<<<
 * 
 *     for k from start <= k < end:
 */
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_q = ((char *)__pyx_t_3);

  /* "pysam/csamfile.pyx":1942
 *     q    = <char*>qual
 * 
 *     for k from start <= k < end:             # <<<<<<<<<<<<<<
 *         ## equivalent to t[i] + 33 (see bam.c)
 *         q[k-start] = p[k] + 33
 */
  __pyx_t_4 = __pyx_v_end;
  for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":1944
 *     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);
  }

  /* "pysam/csamfile.pyx":1946
 *         q[k-start] = p[k] + 33
 * 
 *     return qual             # <<<<<<<<<<<<<<
 * 
 * cdef inline uint8_t get_type_code(value, value_type = None):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_qual);
  __pyx_r = __pyx_v_qual;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1930
 * 
 * 
 * cdef inline object get_qual_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *     cdef uint8_t * p
 *     cdef uint32_t k
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.get_qual_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qual);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1948
 *     return qual
 * 
 * cdef inline uint8_t get_type_code(value, value_type = None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */

static CYTHON_INLINE uint8_t __pyx_f_5pysam_8csamfile_get_type_code(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_8csamfile_get_type_code *__pyx_optional_args) {
  PyObject *__pyx_v_value_type = ((PyObject *)Py_None);
  uint8_t __pyx_v_type_code;
  char *__pyx_v__char_type;
  uint8_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("get_type_code", 0);
  __Pyx_TraceCall("get_type_code", __pyx_f[0], 1948);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_value_type = __pyx_optional_args->value_type;
    }
  }
  __Pyx_INCREF(__pyx_v_value_type);

  /* "pysam/csamfile.pyx":1955
 *     cdef char * _char_type
 * 
 *     if value_type is None:             # <<<<<<<<<<<<<<
 *         if isinstance(value, int):
 *             type_code = 'i'
 */
  __pyx_t_1 = (__pyx_v_value_type == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":1956
 * 
 *     if value_type is None:
 *         if isinstance(value, int):             # <<<<<<<<<<<<<<
 *             type_code = 'i'
 *         elif isinstance(value, float):
 */
    __pyx_t_2 = PyInt_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1957
 *     if value_type is None:
 *         if isinstance(value, int):
 *             type_code = 'i'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, float):
 *             type_code = 'd'
 */
      __pyx_v_type_code = 'i';
      goto __pyx_L4;
    }

    /* "pysam/csamfile.pyx":1958
 *         if isinstance(value, int):
 *             type_code = 'i'
 *         elif isinstance(value, float):             # <<<<<<<<<<<<<<
 *             type_code = 'd'
 *         elif isinstance(value, str):
 */
    __pyx_t_1 = PyFloat_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":1959
 *             type_code = 'i'
 *         elif isinstance(value, float):
 *             type_code = 'd'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, str):
 *             type_code = 'Z'
 */
      __pyx_v_type_code = 'd';
      goto __pyx_L4;
    }

    /* "pysam/csamfile.pyx":1960
 *         elif isinstance(value, float):
 *             type_code = 'd'
 *         elif isinstance(value, str):             # <<<<<<<<<<<<<<
 *             type_code = 'Z'
 *         elif isinstance(value, bytes):
 */
    __pyx_t_2 = PyString_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1961
 *             type_code = 'd'
 *         elif isinstance(value, str):
 *             type_code = 'Z'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, bytes):
 *             type_code = 'Z'
 */
      __pyx_v_type_code = 'Z';
      goto __pyx_L4;
    }

    /* "pysam/csamfile.pyx":1962
 *         elif isinstance(value, str):
 *             type_code = 'Z'
 *         elif isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             type_code = 'Z'
 *         else:
 */
    __pyx_t_1 = PyBytes_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":1963
 *             type_code = 'Z'
 *         elif isinstance(value, bytes):
 *             type_code = 'Z'             # <<<<<<<<<<<<<<
 *         else:
 *             return 0
 */
      __pyx_v_type_code = 'Z';
      goto __pyx_L4;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":1965
 *             type_code = 'Z'
 *         else:
 *             return 0             # <<<<<<<<<<<<<<
 *     else:
 *         if value_type not in 'Zidf':
 */
      __pyx_r = 0;
      goto __pyx_L0;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":1967
 *             return 0
 *     else:
 *         if value_type not in 'Zidf':             # <<<<<<<<<<<<<<
 *             return 0
 *         value_type = _forceBytes( value_type )
 */
    __pyx_t_2 = (__Pyx_PySequence_Contains(__pyx_v_value_type, __pyx_n_s_Zidf, Py_NE)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/csamfile.pyx":1968
 *     else:
 *         if value_type not in 'Zidf':
 *             return 0             # <<<<<<<<<<<<<<
 *         value_type = _forceBytes( value_type )
 *         _char_type = value_type
 */
      __pyx_r = 0;
      goto __pyx_L0;
    }

    /* "pysam/csamfile.pyx":1969
 *         if value_type not in 'Zidf':
 *             return 0
 *         value_type = _forceBytes( value_type )             # <<<<<<<<<<<<<<
 *         _char_type = value_type
 *         type_code = (<uint8_t*>_char_type)[0]
 */
    __pyx_t_3 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_value_type); 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_SET(__pyx_v_value_type, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":1970
 *             return 0
 *         value_type = _forceBytes( value_type )
 *         _char_type = value_type             # <<<<<<<<<<<<<<
 *         type_code = (<uint8_t*>_char_type)[0]
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_value_type); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v__char_type = __pyx_t_4;

    /* "pysam/csamfile.pyx":1971
 *         value_type = _forceBytes( value_type )
 *         _char_type = value_type
 *         type_code = (<uint8_t*>_char_type)[0]             # <<<<<<<<<<<<<<
 * 
 *     return type_code
 */
    __pyx_v_type_code = (((uint8_t *)__pyx_v__char_type)[0]);
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1973
 *         type_code = (<uint8_t*>_char_type)[0]
 * 
 *     return type_code             # <<<<<<<<<<<<<<
 * 
 * cdef inline convert_python_tag(pytag, value, fmts, args):
 */
  __pyx_r = __pyx_v_type_code;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":1948
 *     return qual
 * 
 * cdef inline uint8_t get_type_code(value, value_type = None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysam.csamfile.get_type_code", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_value_type);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":1975
 *     return type_code
 * 
 * cdef inline convert_python_tag(pytag, value, fmts, args):             # <<<<<<<<<<<<<<
 * 
 *     if not type(pytag) is bytes:
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_8csamfile_convert_python_tag(PyObject *__pyx_v_pytag, PyObject *__pyx_v_value, PyObject *__pyx_v_fmts, PyObject *__pyx_v_args) {
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_pytype = NULL;
  PyObject *__pyx_v_datafmt = NULL;
  PyObject *__pyx_v_datatype = NULL;
  PyObject *__pyx_v_mi = NULL;
  PyObject *__pyx_v_ma = NULL;
  PyObject *__pyx_v_absmax = NULL;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("convert_python_tag", 0);
  __Pyx_TraceCall("convert_python_tag", __pyx_f[0], 1975);
  __Pyx_INCREF(__pyx_v_pytag);
  __Pyx_INCREF(__pyx_v_value);

  /* "pysam/csamfile.pyx":1977
 * cdef inline convert_python_tag(pytag, value, fmts, args):
 * 
 *     if not type(pytag) is bytes:             # <<<<<<<<<<<<<<
 *         pytag = pytag.encode('ascii')
 *     t = type(value)
 */
  __pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_pytag)) != ((PyObject *)((PyObject*)(&PyBytes_Type))));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":1978
 * 
 *     if not type(pytag) is bytes:
 *         pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
 *     t = type(value)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytag, __pyx_n_s_encode); 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_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_pytag, __pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":1979
 *     if not type(pytag) is bytes:
 *         pytag = pytag.encode('ascii')
 *     t = type(value)             # <<<<<<<<<<<<<<
 * 
 *     if t is tuple or t is list:
 */
  __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
  __pyx_v_t = ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value)));

  /* "pysam/csamfile.pyx":1981
 *     t = type(value)
 * 
 *     if t is tuple or t is list:             # <<<<<<<<<<<<<<
 *         # binary tags - treat separately
 *         pytype = 'B'
 */
  __pyx_t_2 = (__pyx_v_t == ((PyObject*)(&PyTuple_Type)));
  if (!(__pyx_t_2 != 0)) {
    __pyx_t_1 = (__pyx_v_t == ((PyObject*)(&PyList_Type)));
    __pyx_t_5 = (__pyx_t_1 != 0);
  } else {
    __pyx_t_5 = (__pyx_t_2 != 0);
  }
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":1983
 *     if t is tuple or t is list:
 *         # binary tags - treat separately
 *         pytype = 'B'             # <<<<<<<<<<<<<<
 *         # get data type - first value determines type
 *         if type(value[0]) is float:
 */
    __Pyx_INCREF(__pyx_n_s_B);
    __pyx_v_pytype = __pyx_n_s_B;

    /* "pysam/csamfile.pyx":1985
 *         pytype = 'B'
 *         # get data type - first value determines type
 *         if type(value[0]) is float:             # <<<<<<<<<<<<<<
 *             datafmt, datatype = "f", "f"
 *         else:
 */
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_value, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_t_4)) == ((PyObject *)((PyObject*)(&PyFloat_Type))));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = (__pyx_t_5 != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":1986
 *         # get data type - first value determines type
 *         if type(value[0]) is float:
 *             datafmt, datatype = "f", "f"             # <<<<<<<<<<<<<<
 *         else:
 *             mi, ma = min(value), max(value)
 */
      __pyx_t_4 = __pyx_n_s_f;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_3 = __pyx_n_s_f;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_v_datafmt = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_datatype = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":1988
 *             datafmt, datatype = "f", "f"
 *         else:
 *             mi, ma = min(value), max(value)             # <<<<<<<<<<<<<<
 *             absmax = max( abs(mi), abs(ma) )
 *             # signed ints
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __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 = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_mi = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_ma = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":1989
 *         else:
 *             mi, ma = min(value), max(value)
 *             absmax = max( abs(mi), abs(ma) )             # <<<<<<<<<<<<<<
 *             # signed ints
 *             if mi < 0:
 */
      __pyx_t_6 = PyNumber_Absolute(__pyx_v_ma); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyNumber_Absolute(__pyx_v_mi); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = PyObject_RichCompare(__pyx_t_6, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_2) {
        __Pyx_INCREF(__pyx_t_6);
        __pyx_t_3 = __pyx_t_6;
      } else {
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_3 = __pyx_t_4;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __pyx_t_3;
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_absmax = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":1991
 *             absmax = max( abs(mi), abs(ma) )
 *             # signed ints
 *             if mi < 0:             # <<<<<<<<<<<<<<
 *                 if mi >= -127: datafmt, datatype = "b", 'c'
 *                 elif mi >= -32767: datafmt, datatype = "h", 's'
 */
      __pyx_t_6 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_2) {

        /* "pysam/csamfile.pyx":1992
 *             # signed ints
 *             if mi < 0:
 *                 if mi >= -127: datafmt, datatype = "b", 'c'             # <<<<<<<<<<<<<<
 *                 elif mi >= -32767: datafmt, datatype = "h", 's'
 *                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
        __pyx_t_6 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_2) {
          __pyx_t_6 = __pyx_n_s_b;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = __pyx_n_s_c;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_v_datafmt = __pyx_t_6;
          __pyx_t_6 = 0;
          __pyx_v_datatype = __pyx_t_3;
          __pyx_t_3 = 0;
          goto __pyx_L7;
        }

        /* "pysam/csamfile.pyx":1993
 *             if mi < 0:
 *                 if mi >= -127: datafmt, datatype = "b", 'c'
 *                 elif mi >= -32767: datafmt, datatype = "h", 's'             # <<<<<<<<<<<<<<
 *                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: datafmt, datatype = "i", 'i'
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          __pyx_t_3 = __pyx_n_s_h;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_6 = __pyx_n_s_s_2;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_v_datafmt = __pyx_t_3;
          __pyx_t_3 = 0;
          __pyx_v_datatype = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L7;
        }

        /* "pysam/csamfile.pyx":1994
 *                 if mi >= -127: datafmt, datatype = "b", 'c'
 *                 elif mi >= -32767: datafmt, datatype = "h", 's'
 *                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                 else: datafmt, datatype = "i", 'i'
 * 
 */
        __pyx_t_6 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_2) {
          __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __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, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        /*else*/ {

          /* "pysam/csamfile.pyx":1995
 *                 elif mi >= -32767: datafmt, datatype = "h", 's'
 *                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: datafmt, datatype = "i", 'i'             # <<<<<<<<<<<<<<
 * 
 *             # unsigned ints
 */
          __pyx_t_6 = __pyx_n_s_i;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = __pyx_n_s_i;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_v_datafmt = __pyx_t_6;
          __pyx_t_6 = 0;
          __pyx_v_datatype = __pyx_t_3;
          __pyx_t_3 = 0;
        }
        __pyx_L7:;
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":1999
 *             # unsigned ints
 *             else:
 *                 if absmax <= 255: datafmt, datatype = "B", 'C'             # <<<<<<<<<<<<<<
 *                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
 *                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          __pyx_t_3 = __pyx_n_s_B;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_6 = __pyx_n_s_C;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_v_datafmt = __pyx_t_3;
          __pyx_t_3 = 0;
          __pyx_v_datatype = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L8;
        }

        /* "pysam/csamfile.pyx":2000
 *             else:
 *                 if absmax <= 255: datafmt, datatype = "B", 'C'
 *                 elif absmax <= 65535: datafmt, datatype = "H", 'S'             # <<<<<<<<<<<<<<
 *                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: datafmt, datatype = "I", 'I'
 */
        __pyx_t_6 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_2) {
          __pyx_t_6 = __pyx_n_s_H;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = __pyx_n_s_S;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_v_datafmt = __pyx_t_6;
          __pyx_t_6 = 0;
          __pyx_v_datatype = __pyx_t_3;
          __pyx_t_3 = 0;
          goto __pyx_L8;
        }

        /* "pysam/csamfile.pyx":2001
 *                 if absmax <= 255: datafmt, datatype = "B", 'C'
 *                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
 *                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                 else: datafmt, datatype = "I", 'I'
 * 
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        /*else*/ {

          /* "pysam/csamfile.pyx":2002
 *                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
 *                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: datafmt, datatype = "I", 'I'             # <<<<<<<<<<<<<<
 * 
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 */
          __pyx_t_3 = __pyx_n_s_I;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_6 = __pyx_n_s_I;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_v_datafmt = __pyx_t_3;
          __pyx_t_3 = 0;
          __pyx_v_datatype = __pyx_t_6;
          __pyx_t_6 = 0;
        }
        __pyx_L8:;
      }
      __pyx_L6:;
    }
    __pyx_L5:;

    /* "pysam/csamfile.pyx":2004
 *                 else: datafmt, datatype = "I", 'I'
 * 
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)             # <<<<<<<<<<<<<<
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_datafmt);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_datafmt);
    __Pyx_GIVEREF(__pyx_v_datafmt);
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_i_s, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_datafmt, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysam/csamfile.pyx":2005
 * 
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_args, __pyx_n_s_extend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__61, 0, 1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/csamfile.pyx":2006
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                       datatype.encode('ascii'),
 *                       len(value)] + list(value) )
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytype, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2007
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                       len(value)] + list(value) )
 *         fmts.append( datafmt )
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_datatype, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2008
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),
 *                       len(value)] + list(value) )             # <<<<<<<<<<<<<<
 *         fmts.append( datafmt )
 *         return
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/csamfile.pyx":2005
 * 
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),
 */
    __pyx_t_10 = PyList_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_10, 2, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    PyList_SET_ITEM(__pyx_t_10, 3, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2008
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),
 *                       len(value)] + list(value) )             # <<<<<<<<<<<<<<
 *         fmts.append( datafmt )
 *         return
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pysam/csamfile.pyx":2005
 * 
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),
 */
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2009
 *                       datatype.encode('ascii'),
 *                       len(value)] + list(value) )
 *         fmts.append( datafmt )             # <<<<<<<<<<<<<<
 *         return
 * 
 */
    __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":2010
 *                       len(value)] + list(value) )
 *         fmts.append( datafmt )
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if t is float:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2012
 *         return
 * 
 *     if t is float:             # <<<<<<<<<<<<<<
 *         fmt, pytype = "2scf", 'f'
 *     elif t is int:
 */
  __pyx_t_2 = (__pyx_v_t == ((PyObject*)(&PyFloat_Type)));
  __pyx_t_5 = (__pyx_t_2 != 0);
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":2013
 * 
 *     if t is float:
 *         fmt, pytype = "2scf", 'f'             # <<<<<<<<<<<<<<
 *     elif t is int:
 *         # negative values
 */
    __pyx_t_4 = __pyx_kp_s_2scf;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_9 = __pyx_n_s_f;
    __Pyx_INCREF(__pyx_t_9);
    __pyx_v_fmt = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_v_pytype = __pyx_t_9;
    __pyx_t_9 = 0;
    goto __pyx_L9;
  }

  /* "pysam/csamfile.pyx":2014
 *     if t is float:
 *         fmt, pytype = "2scf", 'f'
 *     elif t is int:             # <<<<<<<<<<<<<<
 *         # negative values
 *         if value < 0:
 */
  __pyx_t_5 = (__pyx_v_t == ((PyObject*)(&PyInt_Type)));
  __pyx_t_2 = (__pyx_t_5 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2016
 *     elif t is int:
 *         # negative values
 *         if value < 0:             # <<<<<<<<<<<<<<
 *             if value >= -127: fmt, pytype = "2scb", 'c'
 *             elif value >= -32767: fmt, pytype = "2sch", 's'
 */
    __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":2017
 *         # negative values
 *         if value < 0:
 *             if value >= -127: fmt, pytype = "2scb", 'c'             # <<<<<<<<<<<<<<
 *             elif value >= -32767: fmt, pytype = "2sch", 's'
 *             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __pyx_kp_s_2scb;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_4 = __pyx_n_s_c;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_fmt = __pyx_t_9;
        __pyx_t_9 = 0;
        __pyx_v_pytype = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L11;
      }

      /* "pysam/csamfile.pyx":2018
 *         if value < 0:
 *             if value >= -127: fmt, pytype = "2scb", 'c'
 *             elif value >= -32767: fmt, pytype = "2sch", 's'             # <<<<<<<<<<<<<<
 *             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *             else: fmt, pytype = "2sci", 'i'
 */
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {
        __pyx_t_4 = __pyx_kp_s_2sch;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_9 = __pyx_n_s_s_2;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_v_fmt = __pyx_t_4;
        __pyx_t_4 = 0;
        __pyx_v_pytype = __pyx_t_9;
        __pyx_t_9 = 0;
        goto __pyx_L11;
      }

      /* "pysam/csamfile.pyx":2019
 *             if value >= -127: fmt, pytype = "2scb", 'c'
 *             elif value >= -32767: fmt, pytype = "2sch", 's'
 *             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *             else: fmt, pytype = "2sci", 'i'
 *         # positive values
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_9, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":2020
 *             elif value >= -32767: fmt, pytype = "2sch", 's'
 *             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *             else: fmt, pytype = "2sci", 'i'             # <<<<<<<<<<<<<<
 *         # positive values
 *         else:
 */
        __pyx_t_9 = __pyx_kp_s_2sci;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_4 = __pyx_n_s_i;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_fmt = __pyx_t_9;
        __pyx_t_9 = 0;
        __pyx_v_pytype = __pyx_t_4;
        __pyx_t_4 = 0;
      }
      __pyx_L11:;
      goto __pyx_L10;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":2023
 *         # positive values
 *         else:
 *             if value <= 255: fmt, pytype = "2scB", 'C'             # <<<<<<<<<<<<<<
 *             elif value <= 65535: fmt, pytype = "2scH", 'S'
 *             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {
        __pyx_t_4 = __pyx_kp_s_2scB;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_9 = __pyx_n_s_C;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_v_fmt = __pyx_t_4;
        __pyx_t_4 = 0;
        __pyx_v_pytype = __pyx_t_9;
        __pyx_t_9 = 0;
        goto __pyx_L12;
      }

      /* "pysam/csamfile.pyx":2024
 *         else:
 *             if value <= 255: fmt, pytype = "2scB", 'C'
 *             elif value <= 65535: fmt, pytype = "2scH", 'S'             # <<<<<<<<<<<<<<
 *             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *             else: fmt, pytype = "2scI", 'I'
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __pyx_kp_s_2scH;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_4 = __pyx_n_s_S;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_fmt = __pyx_t_9;
        __pyx_t_9 = 0;
        __pyx_v_pytype = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L12;
      }

      /* "pysam/csamfile.pyx":2025
 *             if value <= 255: fmt, pytype = "2scB", 'C'
 *             elif value <= 65535: fmt, pytype = "2scH", 'S'
 *             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *             else: fmt, pytype = "2scI", 'I'
 *     else:
 */
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {
        __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":2026
 *             elif value <= 65535: fmt, pytype = "2scH", 'S'
 *             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *             else: fmt, pytype = "2scI", 'I'             # <<<<<<<<<<<<<<
 *     else:
 *         # Note: hex strings (H) are not supported yet
 */
        __pyx_t_4 = __pyx_kp_s_2scI;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_9 = __pyx_n_s_I;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_v_fmt = __pyx_t_4;
        __pyx_t_4 = 0;
        __pyx_v_pytype = __pyx_t_9;
        __pyx_t_9 = 0;
      }
      __pyx_L12:;
    }
    __pyx_L10:;
    goto __pyx_L9;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2029
 *     else:
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:             # <<<<<<<<<<<<<<
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 */
    __pyx_t_2 = (__pyx_v_t != ((PyObject*)(&PyBytes_Type)));
    __pyx_t_5 = (__pyx_t_2 != 0);
    if (__pyx_t_5) {

      /* "pysam/csamfile.pyx":2030
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:
 *             value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *         if len(value) == 1:
 *             fmt, pytype = "2scc", 'A'
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "pysam/csamfile.pyx":2031
 *         if t is not bytes:
 *             value = value.encode('ascii')
 *         if len(value) == 1:             # <<<<<<<<<<<<<<
 *             fmt, pytype = "2scc", 'A'
 *         else:
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = ((__pyx_t_8 == 1) != 0);
    if (__pyx_t_5) {

      /* "pysam/csamfile.pyx":2032
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 *             fmt, pytype = "2scc", 'A'             # <<<<<<<<<<<<<<
 *         else:
 *             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 */
      __pyx_t_4 = __pyx_kp_s_2scc;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_9 = __pyx_n_s_A;
      __Pyx_INCREF(__pyx_t_9);
      __pyx_v_fmt = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_pytype = __pyx_t_9;
      __pyx_t_9 = 0;
      goto __pyx_L14;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":2034
 *             fmt, pytype = "2scc", 'A'
 *         else:
 *             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'             # <<<<<<<<<<<<<<
 * 
 *     args.extend( [pytag[:2],
 */
      __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_9 = PyInt_FromSsize_t((__pyx_t_8 + 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_2sc_is, __pyx_t_9); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __pyx_n_s_Z;
      __Pyx_INCREF(__pyx_t_9);
      __pyx_v_fmt = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_pytype = __pyx_t_9;
      __pyx_t_9 = 0;
    }
    __pyx_L14:;
  }
  __pyx_L9:;

  /* "pysam/csamfile.pyx":2036
 *             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 * 
 *     args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                   pytype.encode('ascii'),
 *                   value ] )
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_args, __pyx_n_s_extend); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__65, 0, 1, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/csamfile.pyx":2037
 * 
 *     args.extend( [pytag[:2],
 *                   pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                   value ] )
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytype, __pyx_n_s_encode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":2036
 *             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 * 
 *     args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                   pytype.encode('ascii'),
 *                   value ] )
 */
  __pyx_t_6 = PyList_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_v_value);
  PyList_SET_ITEM(__pyx_t_6, 2, __pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __pyx_t_4 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":2040
 *                   value ] )
 * 
 *     fmts.append( fmt )             # <<<<<<<<<<<<<<
 * 
 * ###########################################################
 */
  __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_fmts, __pyx_v_fmt); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":1975
 *     return type_code
 * 
 * cdef inline convert_python_tag(pytag, value, fmts, args):             # <<<<<<<<<<<<<<
 * 
 *     if not type(pytag) is bytes:
 */

  /* function exit code */
  __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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.csamfile.convert_python_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_pytype);
  __Pyx_XDECREF(__pyx_v_datafmt);
  __Pyx_XDECREF(__pyx_v_datatype);
  __Pyx_XDECREF(__pyx_v_mi);
  __Pyx_XDECREF(__pyx_v_ma);
  __Pyx_XDECREF(__pyx_v_absmax);
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XDECREF(__pyx_v_pytag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2074
 * 
 *     # Now only called when instances are created from Python
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 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, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead___init__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead___init__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2074);

  /* "pysam/csamfile.pyx":2076
 *     def __init__(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()
 */
  __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/csamfile.pyx":2080
 *         # 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)
 */
  __pyx_v_self->_delegate->m_data = 40;

  /* "pysam/csamfile.pyx":2081
 *         # 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.l_data = 0
 */
  __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1));

  /* "pysam/csamfile.pyx":2083
 *         self._delegate.data = <uint8_t *>calloc(
 *             self._delegate.m_data, 1)
 *         self._delegate.l_data = 0             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->_delegate->l_data = 0;

  /* "pysam/csamfile.pyx":2074
 * 
 *     # Now only called when instances are created from Python
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )
 */

  /* function exit code */
  __pyx_r = 0;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2085
 *         self._delegate.l_data = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_8csamfile_11AlignedRead_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_8csamfile_11AlignedRead_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_8csamfile_11AlignedRead_2__dealloc__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_8csamfile_11AlignedRead_2__dealloc__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2085);

  /* "pysam/csamfile.pyx":2086
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  bam_destroy1(__pyx_v_self->_delegate);

  /* "pysam/csamfile.pyx":2085
 *         self._delegate.l_data = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/csamfile.pyx":2088
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """return string representation of alignment.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5__str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_4__str__[] = "return string representation of alignment.\n\n        The representation is an approximate :term:`sam` format.\n\n        An aligned read might not be associated with a :term:`Samfile`.\n        As a result :term:`tid` is shown instead of the reference name.\n\n        Similarly, the tags field is returned in its parsed state.\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_8csamfile_11AlignedRead_4__str__;
#endif
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4__str__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4__str__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_v_seq = NULL;
  PyObject *__pyx_v_qual = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  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;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 2088);

  /* "pysam/csamfile.pyx":2100
 *         # sam-parsing is done in sam.c/bam_format1_core which
 *         # requires a valid header.
 *         if sys.version_info[0] < 3:             # <<<<<<<<<<<<<<
 *             seq = self.seq
 *             qual = self.qual
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_version_info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __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_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __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_RichCompare(__pyx_t_1, __pyx_int_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __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 = 2100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":2101
 *         # requires a valid header.
 *         if sys.version_info[0] < 3:
 *             seq = self.seq             # <<<<<<<<<<<<<<
 *             qual = self.qual
 *         else:
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_seq = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysam/csamfile.pyx":2102
 *         if sys.version_info[0] < 3:
 *             seq = self.seq
 *             qual = self.qual             # <<<<<<<<<<<<<<
 *         else:
 *             seq = self.seq.decode('ascii')
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_qual = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2104
 *             qual = self.qual
 *         else:
 *             seq = self.seq.decode('ascii')             # <<<<<<<<<<<<<<
 *             qual = self.qual.decode('ascii')
 *         return "\t".join(map(str, (self.qname,
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_seq = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysam/csamfile.pyx":2105
 *         else:
 *             seq = self.seq.decode('ascii')
 *             qual = self.qual.decode('ascii')             # <<<<<<<<<<<<<<
 *         return "\t".join(map(str, (self.qname,
 *                                    self.flag,
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_qual = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2106
 *             seq = self.seq.decode('ascii')
 *             qual = self.qual.decode('ascii')
 *         return "\t".join(map(str, (self.qname,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.rname,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_qname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/csamfile.pyx":2107
 *             qual = self.qual.decode('ascii')
 *         return "\t".join(map(str, (self.qname,
 *                                    self.flag,             # <<<<<<<<<<<<<<
 *                                    self.rname,
 *                                    self.pos,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/csamfile.pyx":2108
 *         return "\t".join(map(str, (self.qname,
 *                                    self.flag,
 *                                    self.rname,             # <<<<<<<<<<<<<<
 *                                    self.pos,
 *                                    self.mapq,
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_rname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/csamfile.pyx":2109
 *                                    self.flag,
 *                                    self.rname,
 *                                    self.pos,             # <<<<<<<<<<<<<<
 *                                    self.mapq,
 *                                    self.cigar,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/csamfile.pyx":2110
 *                                    self.rname,
 *                                    self.pos,
 *                                    self.mapq,             # <<<<<<<<<<<<<<
 *                                    self.cigar,
 *                                    self.mrnm,
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapq); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/csamfile.pyx":2111
 *                                    self.pos,
 *                                    self.mapq,
 *                                    self.cigar,             # <<<<<<<<<<<<<<
 *                                    self.mrnm,
 *                                    self.mpos,
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigar); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/csamfile.pyx":2112
 *                                    self.mapq,
 *                                    self.cigar,
 *                                    self.mrnm,             # <<<<<<<<<<<<<<
 *                                    self.mpos,
 *                                    self.rlen,
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mrnm); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/csamfile.pyx":2113
 *                                    self.cigar,
 *                                    self.mrnm,
 *                                    self.mpos,             # <<<<<<<<<<<<<<
 *                                    self.rlen,
 *                                    seq,
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mpos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);

  /* "pysam/csamfile.pyx":2114
 *                                    self.mrnm,
 *                                    self.mpos,
 *                                    self.rlen,             # <<<<<<<<<<<<<<
 *                                    seq,
 *                                    qual,
 */
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_rlen); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);

  /* "pysam/csamfile.pyx":2117
 *                                    seq,
 *                                    qual,
 *                                    self.tags )))             # <<<<<<<<<<<<<<
 * 
 *     def compare(self, AlignedRead other):
 */
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tags); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);

  /* "pysam/csamfile.pyx":2106
 *             seq = self.seq.decode('ascii')
 *             qual = self.qual.decode('ascii')
 *         return "\t".join(map(str, (self.qname,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.rname,
 */
  __pyx_t_12 = PyTuple_New(12); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_12, 3, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_12, 4, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_12, 5, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_12, 6, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_12, 7, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_12, 8, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_v_seq);
  PyTuple_SET_ITEM(__pyx_t_12, 9, __pyx_v_seq);
  __Pyx_GIVEREF(__pyx_v_seq);
  __Pyx_INCREF(__pyx_v_qual);
  PyTuple_SET_ITEM(__pyx_t_12, 10, __pyx_v_qual);
  __Pyx_GIVEREF(__pyx_v_qual);
  PyTuple_SET_ITEM(__pyx_t_12, 11, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_2 = 0;
  __pyx_t_1 = 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_11 = 0;
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_12);
  __Pyx_GIVEREF(__pyx_t_12);
  __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_11, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_r = __pyx_t_11;
  __pyx_t_11 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2088
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """return string representation of alignment.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __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_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_XDECREF(__pyx_v_qual);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2119
 *                                    self.tags )))
 * 
 *     def compare(self, AlignedRead other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary <,=,> to *other*'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_7compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_6compare[] = "AlignedRead.compare(self, AlignedRead other)\nreturn -1,0,1, if contents in this are binary <,=,> to *other*";
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_7compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("compare (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_8csamfile_AlignedRead, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_6compare(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_other));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_6compare(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_other) {
  int __pyx_v_retval;
  bam1_t *__pyx_v_t;
  bam1_t *__pyx_v_o;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("compare", 0);
  __Pyx_TraceCall("compare", __pyx_f[0], 2119);

  /* "pysam/csamfile.pyx":2126
 *         cdef bam1_t *o
 * 
 *         t = self._delegate             # <<<<<<<<<<<<<<
 *         o = other._delegate
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_t = __pyx_t_1;

  /* "pysam/csamfile.pyx":2127
 * 
 *         t = self._delegate
 *         o = other._delegate             # <<<<<<<<<<<<<<
 * 
 *         # uncomment for debugging purposes
 */
  __pyx_t_1 = __pyx_v_other->_delegate;
  __pyx_v_o = __pyx_t_1;

  /* "pysam/csamfile.pyx":2139
 * 
 *         # Fast-path test for object identity
 *         if t == o:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_2 = ((__pyx_v_t == __pyx_v_o) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2140
 *         # 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;
  }

  /* "pysam/csamfile.pyx":2142
 *             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)));

  /* "pysam/csamfile.pyx":2144
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 * 
 *         if retval: return retval             # <<<<<<<<<<<<<<
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) # cmp(t.l_data, o.l_data)
 *         if retval: return retval
 */
  __pyx_t_2 = (__pyx_v_retval != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2145
 * 
 *         if retval: return retval
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) # cmp(t.l_data, o.l_data)             # <<<<<<<<<<<<<<
 *         if retval: return retval
 *         return memcmp(t.data, o.data, t.l_data)
 */
  __pyx_v_retval = ((__pyx_v_t->l_data > __pyx_v_o->l_data) - (__pyx_v_t->l_data < __pyx_v_o->l_data));

  /* "pysam/csamfile.pyx":2146
 *         if retval: return retval
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) # cmp(t.l_data, o.l_data)
 *         if retval: return retval             # <<<<<<<<<<<<<<
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 */
  __pyx_t_2 = (__pyx_v_retval != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2147
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) # cmp(t.l_data, o.l_data)
 *         if retval: return retval
 *         return memcmp(t.data, o.data, t.l_data)             # <<<<<<<<<<<<<<
 * 
 *     # Disabled so long as __cmp__ is a special method
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->l_data)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2119
 *                                    self.tags )))
 * 
 *     def compare(self, AlignedRead other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary <,=,> to *other*'''
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.compare", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2150
 * 
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return _Py_HashPointer(<void *>self)
 * 
 */

/* Python wrapper */
static Py_hash_t __pyx_pw_5pysam_8csamfile_11AlignedRead_9__hash__(PyObject *__pyx_v_self); /*proto*/
static Py_hash_t __pyx_pw_5pysam_8csamfile_11AlignedRead_9__hash__(PyObject *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_8__hash__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static Py_hash_t __pyx_pf_5pysam_8csamfile_11AlignedRead_8__hash__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__hash__", 0);
  __Pyx_TraceCall("__hash__", __pyx_f[0], 2150);

  /* "pysam/csamfile.pyx":2151
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):
 *         return _Py_HashPointer(<void *>self)             # <<<<<<<<<<<<<<
 * 
 *     def _convert_python_tag(self, pytag, value, fmts, args):
 */
  __pyx_r = _Py_HashPointer(((void *)__pyx_v_self));
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2150
 * 
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return _Py_HashPointer(<void *>self)
 * 
 */

  /* function exit code */
  __pyx_L0:;
  if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2153
 *         return _Py_HashPointer(<void *>self)
 * 
 *     def _convert_python_tag(self, pytag, value, fmts, args):             # <<<<<<<<<<<<<<
 * 
 *         if not type(pytag) is bytes:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_11_convert_python_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_10_convert_python_tag[] = "AlignedRead._convert_python_tag(self, pytag, value, fmts, args)";
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_11_convert_python_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pytag = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_fmts = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_convert_python_tag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pytag,&__pyx_n_s_value,&__pyx_n_s_fmts,&__pyx_n_s_args,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pytag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_convert_python_tag", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fmts)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_convert_python_tag", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_convert_python_tag", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_convert_python_tag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_pytag = values[0];
    __pyx_v_value = values[1];
    __pyx_v_fmts = values[2];
    __pyx_v_args = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_convert_python_tag", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead._convert_python_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_10_convert_python_tag(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), __pyx_v_pytag, __pyx_v_value, __pyx_v_fmts, __pyx_v_args);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_10_convert_python_tag(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_pytag, PyObject *__pyx_v_value, PyObject *__pyx_v_fmts, PyObject *__pyx_v_args) {
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_pytype = NULL;
  PyObject *__pyx_v_datafmt = NULL;
  PyObject *__pyx_v_datatype = NULL;
  PyObject *__pyx_v_mi = NULL;
  PyObject *__pyx_v_ma = NULL;
  PyObject *__pyx_v_absmax = NULL;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("_convert_python_tag", 0);
  __Pyx_TraceCall("_convert_python_tag", __pyx_f[0], 2153);
  __Pyx_INCREF(__pyx_v_pytag);
  __Pyx_INCREF(__pyx_v_value);

  /* "pysam/csamfile.pyx":2155
 *     def _convert_python_tag(self, pytag, value, fmts, args):
 * 
 *         if not type(pytag) is bytes:             # <<<<<<<<<<<<<<
 *             pytag = pytag.encode('ascii')
 *         t = type(value)
 */
  __pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_pytag)) != ((PyObject *)((PyObject*)(&PyBytes_Type))));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2156
 * 
 *         if not type(pytag) is bytes:
 *             pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
 *         t = type(value)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytag, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_pytag, __pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2157
 *         if not type(pytag) is bytes:
 *             pytag = pytag.encode('ascii')
 *         t = type(value)             # <<<<<<<<<<<<<<
 * 
 *         if t is tuple or t is list:
 */
  __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
  __pyx_v_t = ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value)));

  /* "pysam/csamfile.pyx":2159
 *         t = type(value)
 * 
 *         if t is tuple or t is list:             # <<<<<<<<<<<<<<
 *             # binary tags - treat separately
 *             pytype = 'B'
 */
  __pyx_t_2 = (__pyx_v_t == ((PyObject*)(&PyTuple_Type)));
  if (!(__pyx_t_2 != 0)) {
    __pyx_t_1 = (__pyx_v_t == ((PyObject*)(&PyList_Type)));
    __pyx_t_5 = (__pyx_t_1 != 0);
  } else {
    __pyx_t_5 = (__pyx_t_2 != 0);
  }
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":2161
 *         if t is tuple or t is list:
 *             # binary tags - treat separately
 *             pytype = 'B'             # <<<<<<<<<<<<<<
 *             # get data type - first value determines type
 *             if type(value[0]) is float:
 */
    __Pyx_INCREF(__pyx_n_s_B);
    __pyx_v_pytype = __pyx_n_s_B;

    /* "pysam/csamfile.pyx":2163
 *             pytype = 'B'
 *             # get data type - first value determines type
 *             if type(value[0]) is float:             # <<<<<<<<<<<<<<
 *                 datafmt, datatype = "f", "f"
 *             else:
 */
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_value, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2163; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_t_4)) == ((PyObject *)((PyObject*)(&PyFloat_Type))));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = (__pyx_t_5 != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":2164
 *             # get data type - first value determines type
 *             if type(value[0]) is float:
 *                 datafmt, datatype = "f", "f"             # <<<<<<<<<<<<<<
 *             else:
 *                 mi, ma = min(value), max(value)
 */
      __pyx_t_4 = __pyx_n_s_f;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_3 = __pyx_n_s_f;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_v_datafmt = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_datatype = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":2166
 *                 datafmt, datatype = "f", "f"
 *             else:
 *                 mi, ma = min(value), max(value)             # <<<<<<<<<<<<<<
 *                 absmax = max( abs(mi), abs(ma) )
 *                 # signed ints
 */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __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 = 2166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_mi = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_ma = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":2167
 *             else:
 *                 mi, ma = min(value), max(value)
 *                 absmax = max( abs(mi), abs(ma) )             # <<<<<<<<<<<<<<
 *                 # signed ints
 *                 if mi < 0:
 */
      __pyx_t_6 = PyNumber_Absolute(__pyx_v_ma); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyNumber_Absolute(__pyx_v_mi); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = PyObject_RichCompare(__pyx_t_6, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_2) {
        __Pyx_INCREF(__pyx_t_6);
        __pyx_t_3 = __pyx_t_6;
      } else {
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_3 = __pyx_t_4;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __pyx_t_3;
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_absmax = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pysam/csamfile.pyx":2169
 *                 absmax = max( abs(mi), abs(ma) )
 *                 # signed ints
 *                 if mi < 0:             # <<<<<<<<<<<<<<
 *                     if mi >= -127: datafmt, datatype = "b", 'c'
 *                     elif mi >= -32767: datafmt, datatype = "h", 's'
 */
      __pyx_t_6 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_2) {

        /* "pysam/csamfile.pyx":2170
 *                 # signed ints
 *                 if mi < 0:
 *                     if mi >= -127: datafmt, datatype = "b", 'c'             # <<<<<<<<<<<<<<
 *                     elif mi >= -32767: datafmt, datatype = "h", 's'
 *                     elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
        __pyx_t_6 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_2) {
          __pyx_t_6 = __pyx_n_s_b;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = __pyx_n_s_c;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_v_datafmt = __pyx_t_6;
          __pyx_t_6 = 0;
          __pyx_v_datatype = __pyx_t_3;
          __pyx_t_3 = 0;
          goto __pyx_L7;
        }

        /* "pysam/csamfile.pyx":2171
 *                 if mi < 0:
 *                     if mi >= -127: datafmt, datatype = "b", 'c'
 *                     elif mi >= -32767: datafmt, datatype = "h", 's'             # <<<<<<<<<<<<<<
 *                     elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                     else: datafmt, datatype = "i", 'i'
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          __pyx_t_3 = __pyx_n_s_h;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_6 = __pyx_n_s_s_2;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_v_datafmt = __pyx_t_3;
          __pyx_t_3 = 0;
          __pyx_v_datatype = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L7;
        }

        /* "pysam/csamfile.pyx":2172
 *                     if mi >= -127: datafmt, datatype = "b", 'c'
 *                     elif mi >= -32767: datafmt, datatype = "h", 's'
 *                     elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                     else: datafmt, datatype = "i", 'i'
 * 
 */
        __pyx_t_6 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_2) {
          __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __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, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        /*else*/ {

          /* "pysam/csamfile.pyx":2173
 *                     elif mi >= -32767: datafmt, datatype = "h", 's'
 *                     elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                     else: datafmt, datatype = "i", 'i'             # <<<<<<<<<<<<<<
 * 
 *                 # unsigned ints
 */
          __pyx_t_6 = __pyx_n_s_i;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = __pyx_n_s_i;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_v_datafmt = __pyx_t_6;
          __pyx_t_6 = 0;
          __pyx_v_datatype = __pyx_t_3;
          __pyx_t_3 = 0;
        }
        __pyx_L7:;
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":2177
 *                 # unsigned ints
 *                 else:
 *                     if absmax <= 255: datafmt, datatype = "B", 'C'             # <<<<<<<<<<<<<<
 *                     elif absmax <= 65535: datafmt, datatype = "H", 'S'
 *                     elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          __pyx_t_3 = __pyx_n_s_B;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_6 = __pyx_n_s_C;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_v_datafmt = __pyx_t_3;
          __pyx_t_3 = 0;
          __pyx_v_datatype = __pyx_t_6;
          __pyx_t_6 = 0;
          goto __pyx_L8;
        }

        /* "pysam/csamfile.pyx":2178
 *                 else:
 *                     if absmax <= 255: datafmt, datatype = "B", 'C'
 *                     elif absmax <= 65535: datafmt, datatype = "H", 'S'             # <<<<<<<<<<<<<<
 *                     elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                     else: datafmt, datatype = "I", 'I'
 */
        __pyx_t_6 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_2) {
          __pyx_t_6 = __pyx_n_s_H;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = __pyx_n_s_S;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_v_datafmt = __pyx_t_6;
          __pyx_t_6 = 0;
          __pyx_v_datatype = __pyx_t_3;
          __pyx_t_3 = 0;
          goto __pyx_L8;
        }

        /* "pysam/csamfile.pyx":2179
 *                     if absmax <= 255: datafmt, datatype = "B", 'C'
 *                     elif absmax <= 65535: datafmt, datatype = "H", 'S'
 *                     elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                     else: datafmt, datatype = "I", 'I'
 * 
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        /*else*/ {

          /* "pysam/csamfile.pyx":2180
 *                     elif absmax <= 65535: datafmt, datatype = "H", 'S'
 *                     elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                     else: datafmt, datatype = "I", 'I'             # <<<<<<<<<<<<<<
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 */
          __pyx_t_3 = __pyx_n_s_I;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_6 = __pyx_n_s_I;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_v_datafmt = __pyx_t_3;
          __pyx_t_3 = 0;
          __pyx_v_datatype = __pyx_t_6;
          __pyx_t_6 = 0;
        }
        __pyx_L8:;
      }
      __pyx_L6:;
    }
    __pyx_L5:;

    /* "pysam/csamfile.pyx":2182
 *                     else: datafmt, datatype = "I", 'I'
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)             # <<<<<<<<<<<<<<
 *             args.extend( [pytag[:2],
 *                           pytype.encode('ascii'),
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_datafmt);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_datafmt);
    __Pyx_GIVEREF(__pyx_v_datafmt);
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_i_s, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_datafmt, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysam/csamfile.pyx":2183
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 *             args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_args, __pyx_n_s_extend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__70, 0, 1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/csamfile.pyx":2184
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 *             args.extend( [pytag[:2],
 *                           pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                           datatype.encode('ascii'),
 *                           len(value)] + list(value) )
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytype, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__71, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2185
 *             args.extend( [pytag[:2],
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                           len(value)] + list(value) )
 *             fmts.append( datafmt )
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_datatype, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2186
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),
 *                           len(value)] + list(value) )             # <<<<<<<<<<<<<<
 *             fmts.append( datafmt )
 *             return
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/csamfile.pyx":2183
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 *             args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),
 */
    __pyx_t_10 = PyList_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_10, 2, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    PyList_SET_ITEM(__pyx_t_10, 3, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_3 = 0;
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2186
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),
 *                           len(value)] + list(value) )             # <<<<<<<<<<<<<<
 *             fmts.append( datafmt )
 *             return
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_9 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pysam/csamfile.pyx":2183
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 *             args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),
 */
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/csamfile.pyx":2187
 *                           datatype.encode('ascii'),
 *                           len(value)] + list(value) )
 *             fmts.append( datafmt )             # <<<<<<<<<<<<<<
 *             return
 * 
 */
    __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":2188
 *                           len(value)] + list(value) )
 *             fmts.append( datafmt )
 *             return             # <<<<<<<<<<<<<<
 * 
 *         if t is float:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2190
 *             return
 * 
 *         if t is float:             # <<<<<<<<<<<<<<
 *             fmt, pytype = "2scf", 'f'
 *         elif t is int:
 */
  __pyx_t_2 = (__pyx_v_t == ((PyObject*)(&PyFloat_Type)));
  __pyx_t_5 = (__pyx_t_2 != 0);
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":2191
 * 
 *         if t is float:
 *             fmt, pytype = "2scf", 'f'             # <<<<<<<<<<<<<<
 *         elif t is int:
 *             # negative values
 */
    __pyx_t_4 = __pyx_kp_s_2scf;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_9 = __pyx_n_s_f;
    __Pyx_INCREF(__pyx_t_9);
    __pyx_v_fmt = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_v_pytype = __pyx_t_9;
    __pyx_t_9 = 0;
    goto __pyx_L9;
  }

  /* "pysam/csamfile.pyx":2192
 *         if t is float:
 *             fmt, pytype = "2scf", 'f'
 *         elif t is int:             # <<<<<<<<<<<<<<
 *             # negative values
 *             if value < 0:
 */
  __pyx_t_5 = (__pyx_v_t == ((PyObject*)(&PyInt_Type)));
  __pyx_t_2 = (__pyx_t_5 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2194
 *         elif t is int:
 *             # negative values
 *             if value < 0:             # <<<<<<<<<<<<<<
 *                 if value >= -127: fmt, pytype = "2scb", 'c'
 *                 elif value >= -32767: fmt, pytype = "2sch", 's'
 */
    __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":2195
 *             # negative values
 *             if value < 0:
 *                 if value >= -127: fmt, pytype = "2scb", 'c'             # <<<<<<<<<<<<<<
 *                 elif value >= -32767: fmt, pytype = "2sch", 's'
 *                 elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __pyx_kp_s_2scb;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_4 = __pyx_n_s_c;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_fmt = __pyx_t_9;
        __pyx_t_9 = 0;
        __pyx_v_pytype = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L11;
      }

      /* "pysam/csamfile.pyx":2196
 *             if value < 0:
 *                 if value >= -127: fmt, pytype = "2scb", 'c'
 *                 elif value >= -32767: fmt, pytype = "2sch", 's'             # <<<<<<<<<<<<<<
 *                 elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: fmt, pytype = "2sci", 'i'
 */
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {
        __pyx_t_4 = __pyx_kp_s_2sch;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_9 = __pyx_n_s_s_2;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_v_fmt = __pyx_t_4;
        __pyx_t_4 = 0;
        __pyx_v_pytype = __pyx_t_9;
        __pyx_t_9 = 0;
        goto __pyx_L11;
      }

      /* "pysam/csamfile.pyx":2197
 *                 if value >= -127: fmt, pytype = "2scb", 'c'
 *                 elif value >= -32767: fmt, pytype = "2sch", 's'
 *                 elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                 else: fmt, pytype = "2sci", 'i'
 *             # positive values
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_9, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":2198
 *                 elif value >= -32767: fmt, pytype = "2sch", 's'
 *                 elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: fmt, pytype = "2sci", 'i'             # <<<<<<<<<<<<<<
 *             # positive values
 *             else:
 */
        __pyx_t_9 = __pyx_kp_s_2sci;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_4 = __pyx_n_s_i;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_fmt = __pyx_t_9;
        __pyx_t_9 = 0;
        __pyx_v_pytype = __pyx_t_4;
        __pyx_t_4 = 0;
      }
      __pyx_L11:;
      goto __pyx_L10;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":2201
 *             # positive values
 *             else:
 *                 if value <= 255: fmt, pytype = "2scB", 'C'             # <<<<<<<<<<<<<<
 *                 elif value <= 65535: fmt, pytype = "2scH", 'S'
 *                 elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 */
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {
        __pyx_t_4 = __pyx_kp_s_2scB;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_9 = __pyx_n_s_C;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_v_fmt = __pyx_t_4;
        __pyx_t_4 = 0;
        __pyx_v_pytype = __pyx_t_9;
        __pyx_t_9 = 0;
        goto __pyx_L12;
      }

      /* "pysam/csamfile.pyx":2202
 *             else:
 *                 if value <= 255: fmt, pytype = "2scB", 'C'
 *                 elif value <= 65535: fmt, pytype = "2scH", 'S'             # <<<<<<<<<<<<<<
 *                 elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: fmt, pytype = "2scI", 'I'
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __pyx_kp_s_2scH;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_t_4 = __pyx_n_s_S;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_fmt = __pyx_t_9;
        __pyx_t_9 = 0;
        __pyx_v_pytype = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L12;
      }

      /* "pysam/csamfile.pyx":2203
 *                 if value <= 255: fmt, pytype = "2scB", 'C'
 *                 elif value <= 65535: fmt, pytype = "2scH", 'S'
 *                 elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
 *                 else: fmt, pytype = "2scI", 'I'
 *         else:
 */
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {
        __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_v_value); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      /*else*/ {

        /* "pysam/csamfile.pyx":2204
 *                 elif value <= 65535: fmt, pytype = "2scH", 'S'
 *                 elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
 *                 else: fmt, pytype = "2scI", 'I'             # <<<<<<<<<<<<<<
 *         else:
 *             # Note: hex strings (H) are not supported yet
 */
        __pyx_t_4 = __pyx_kp_s_2scI;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_9 = __pyx_n_s_I;
        __Pyx_INCREF(__pyx_t_9);
        __pyx_v_fmt = __pyx_t_4;
        __pyx_t_4 = 0;
        __pyx_v_pytype = __pyx_t_9;
        __pyx_t_9 = 0;
      }
      __pyx_L12:;
    }
    __pyx_L10:;
    goto __pyx_L9;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2207
 *         else:
 *             # Note: hex strings (H) are not supported yet
 *             if t is not bytes:             # <<<<<<<<<<<<<<
 *                 value = value.encode('ascii')
 *             if len(value) == 1:
 */
    __pyx_t_2 = (__pyx_v_t != ((PyObject*)(&PyBytes_Type)));
    __pyx_t_5 = (__pyx_t_2 != 0);
    if (__pyx_t_5) {

      /* "pysam/csamfile.pyx":2208
 *             # Note: hex strings (H) are not supported yet
 *             if t is not bytes:
 *                 value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *             if len(value) == 1:
 *                 fmt, pytype = "2scc", 'A'
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L13;
    }
    __pyx_L13:;

    /* "pysam/csamfile.pyx":2209
 *             if t is not bytes:
 *                 value = value.encode('ascii')
 *             if len(value) == 1:             # <<<<<<<<<<<<<<
 *                 fmt, pytype = "2scc", 'A'
 *             else:
 */
    __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = ((__pyx_t_8 == 1) != 0);
    if (__pyx_t_5) {

      /* "pysam/csamfile.pyx":2210
 *                 value = value.encode('ascii')
 *             if len(value) == 1:
 *                 fmt, pytype = "2scc", 'A'             # <<<<<<<<<<<<<<
 *             else:
 *                 fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 */
      __pyx_t_4 = __pyx_kp_s_2scc;
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_9 = __pyx_n_s_A;
      __Pyx_INCREF(__pyx_t_9);
      __pyx_v_fmt = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_pytype = __pyx_t_9;
      __pyx_t_9 = 0;
      goto __pyx_L14;
    }
    /*else*/ {

      /* "pysam/csamfile.pyx":2212
 *                 fmt, pytype = "2scc", 'A'
 *             else:
 *                 fmt, pytype = "2sc%is" % (len(value)+1), 'Z'             # <<<<<<<<<<<<<<
 * 
 *         args.extend( [pytag[:2],
 */
      __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_9 = PyInt_FromSsize_t((__pyx_t_8 + 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_2sc_is, __pyx_t_9); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __pyx_n_s_Z;
      __Pyx_INCREF(__pyx_t_9);
      __pyx_v_fmt = __pyx_t_4;
      __pyx_t_4 = 0;
      __pyx_v_pytype = __pyx_t_9;
      __pyx_t_9 = 0;
    }
    __pyx_L14:;
  }
  __pyx_L9:;

  /* "pysam/csamfile.pyx":2214
 *                 fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 * 
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       value ] )
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_args, __pyx_n_s_extend); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__74, 0, 1, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/csamfile.pyx":2215
 * 
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                       value ] )
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytype, __pyx_n_s_encode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":2214
 *                 fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 * 
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       value ] )
 */
  __pyx_t_6 = PyList_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_v_value);
  PyList_SET_ITEM(__pyx_t_6, 2, __pyx_v_value);
  __Pyx_GIVEREF(__pyx_v_value);
  __pyx_t_4 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":2218
 *                       value ] )
 * 
 *         fmts.append( fmt )             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_fmts, __pyx_v_fmt); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":2153
 *         return _Py_HashPointer(<void *>self)
 * 
 *     def _convert_python_tag(self, pytag, value, fmts, args):             # <<<<<<<<<<<<<<
 * 
 *         if not type(pytag) is bytes:
 */

  /* function exit code */
  __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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead._convert_python_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_pytype);
  __Pyx_XDECREF(__pyx_v_datafmt);
  __Pyx_XDECREF(__pyx_v_datatype);
  __Pyx_XDECREF(__pyx_v_mi);
  __Pyx_XDECREF(__pyx_v_ma);
  __Pyx_XDECREF(__pyx_v_absmax);
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XDECREF(__pyx_v_pytag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2227
 *     property qname:
 *         """the query name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5qname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5qname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5qname___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5qname___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2227);

  /* "pysam/csamfile.pyx":2229
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_l_qname(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2230
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 */
  __pyx_t_2 = ((pysam_get_l_qname(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2231
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2232
 *             if pysam_get_l_qname(src) == 0:
 *                 return None
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, qname ):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_5pysam_8csamfile__charptr_to_str(((char *)pysam_bam_get_qname(__pyx_v_src))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2227
 *     property qname:
 *         """the query name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2234
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 *         def __set__(self, qname ):             # <<<<<<<<<<<<<<
 *             if qname == None or len(qname) == 0: return
 *             qname = _forceBytes(qname)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5qname_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_qname));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5qname_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qname) {
  bam1_t *__pyx_v_src;
  int __pyx_v_l;
  char *__pyx_v_p;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  bam1_t *__pyx_t_6;
  char const *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2234);
  __Pyx_INCREF(__pyx_v_qname);

  /* "pysam/csamfile.pyx":2235
 * 
 *         def __set__(self, qname ):
 *             if qname == None or len(qname) == 0: return             # <<<<<<<<<<<<<<
 *             qname = _forceBytes(qname)
 *             cdef bam1_t * src
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_qname, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2235; __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 = 2235; __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;
  }

  /* "pysam/csamfile.pyx":2236
 *         def __set__(self, qname ):
 *             if qname == None or len(qname) == 0: return
 *             qname = _forceBytes(qname)             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef int l
 */
  __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_qname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_qname, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":2241
 *             cdef char * p
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = pysam_bam_get_qname( src )
 * 
 */
  __pyx_t_6 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_6;

  /* "pysam/csamfile.pyx":2242
 * 
 *             src = self._delegate
 *             p = pysam_bam_get_qname( src )             # <<<<<<<<<<<<<<
 * 
 *             # the qname is \0 terminated
 */
  __pyx_v_p = pysam_bam_get_qname(__pyx_v_src);

  /* "pysam/csamfile.pyx":2245
 * 
 *             # the qname is \0 terminated
 *             l = len(qname) + 1             # <<<<<<<<<<<<<<
 *             pysam_bam_update(src,
 *                              pysam_get_l_qname(src),
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = (__pyx_t_3 + 1);

  /* "pysam/csamfile.pyx":2246
 *             # the qname is \0 terminated
 *             l = len(qname) + 1
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              pysam_get_l_qname(src),
 *                              l,
 */
  pysam_bam_update(__pyx_v_src, pysam_get_l_qname(__pyx_v_src), __pyx_v_l, ((uint8_t *)__pyx_v_p));

  /* "pysam/csamfile.pyx":2252
 * 
 * 
 *             pysam_set_l_qname(src, l)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  pysam_set_l_qname(__pyx_v_src, __pyx_v_l);

  /* "pysam/csamfile.pyx":2256
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = pysam_bam_get_qname(src)             # <<<<<<<<<<<<<<
 * 
 *             strncpy(p, qname, l)
 */
  __pyx_v_p = pysam_bam_get_qname(__pyx_v_src);

  /* "pysam/csamfile.pyx":2258
 *             p = pysam_bam_get_qname(src)
 * 
 *             strncpy(p, qname, l)             # <<<<<<<<<<<<<<
 * 
 *     property cigar:
 */
  __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_p, __pyx_t_7, __pyx_v_l);

  /* "pysam/csamfile.pyx":2234
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 *         def __set__(self, qname ):             # <<<<<<<<<<<<<<
 *             if qname == None or len(qname) == 0: return
 *             qname = _forceBytes(qname)
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qname);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2299
 *         or None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5cigar_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5cigar_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5cigar___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5cigar___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_op = 0;
  PyObject *__pyx_v_l = 0;
  PyObject *__pyx_v_cigar = 0;
  int __pyx_v_k;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  bam1_t *__pyx_t_2;
  int __pyx_t_3;
  uint16_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2299);

  /* "pysam/csamfile.pyx":2304
 *             cdef op, l, cigar
 *             cdef int k
 *             cigar = []             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_cigar = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":2306
 *             cigar = []
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src) == 0:
 *                 return cigar
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/csamfile.pyx":2307
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return cigar
 * 
 */
  __pyx_t_3 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":2308
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:
 *                 return cigar             # <<<<<<<<<<<<<<
 * 
 *             cigar_p = pysam_bam_get_cigar(src);
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_cigar);
    __pyx_r = __pyx_v_cigar;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2310
 *                 return cigar
 * 
 *             cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":2311
 * 
 *             cigar_p = pysam_bam_get_cigar(src);
 *             for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":2312
 *             cigar_p = pysam_bam_get_cigar(src);
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 */
    __pyx_t_1 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_op, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":2313
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 cigar.append((op, l))
 *             return cigar
 */
    __pyx_t_1 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":2314
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
 *             return cigar
 * 
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_op);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_op);
    __Pyx_GIVEREF(__pyx_v_op);
    __Pyx_INCREF(__pyx_v_l);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_l);
    __Pyx_GIVEREF(__pyx_v_l);
    __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_cigar, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/csamfile.pyx":2315
 *                 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;

  /* "pysam/csamfile.pyx":2299
 *         or None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.cigar.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_op);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XDECREF(__pyx_v_cigar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2317
 *             return cigar
 * 
 *         def __set__(self, values):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5cigar_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_values));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5cigar_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_values) {
  uint32_t *__pyx_v_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_op = 0;
  PyObject *__pyx_v_l = 0;
  int __pyx_v_k;
  int __pyx_v_ncigar;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  uint32_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2317);
  __Pyx_INCREF(__pyx_v_values);

  /* "pysam/csamfile.pyx":2323
 *             cdef int k, ncigar
 * 
 *             k = 0             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
  __pyx_v_k = 0;

  /* "pysam/csamfile.pyx":2325
 *             k = 0
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # get location of cigar string
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2328
 * 
 *             # get location of cigar string
 *             p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # empty values for cigar string
 */
  __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":2331
 * 
 *             # empty values for cigar string
 *             if values is None:             # <<<<<<<<<<<<<<
 *                 values = []
 * 
 */
  __pyx_t_2 = (__pyx_v_values == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":2332
 *             # empty values for cigar string
 *             if values is None:
 *                 values = []             # <<<<<<<<<<<<<<
 * 
 *             ncigar = len(values)
 */
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2334
 *                 values = []
 * 
 *             ncigar = len(values)             # <<<<<<<<<<<<<<
 *             # create space for cigar data within src.data
 *             pysam_bam_update(src,
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_ncigar = __pyx_t_5;

  /* "pysam/csamfile.pyx":2336
 *             ncigar = len(values)
 *             # create space for cigar data within src.data
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              pysam_get_n_cigar(src) * 4,
 *                              ncigar * 4,
 */
  pysam_bam_update(__pyx_v_src, (pysam_get_n_cigar(__pyx_v_src) * 4), (__pyx_v_ncigar * 4), ((uint8_t *)__pyx_v_p));

  /* "pysam/csamfile.pyx":2342
 * 
 *             # length is number of cigar operations, not bytes
 *             pysam_set_n_cigar(src, ncigar)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  pysam_set_n_cigar(__pyx_v_src, __pyx_v_ncigar);

  /* "pysam/csamfile.pyx":2346
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # insert cigar operations
 */
  __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":2349
 * 
 *             # 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_4 = __pyx_v_values; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext;
  }
  for (;;) {
    if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_4)) {
      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_4)) {
      if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
      PyObject* sequence = __pyx_t_7;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L7_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_op, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pysam/csamfile.pyx":2350
 *             # insert cigar operations
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
 *                 k += 1
 * 
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(BAM_CIGAR_SHIFT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyNumber_Lshift(__pyx_v_l, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Or(__pyx_t_9, __pyx_v_op); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_12 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_12 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    (__pyx_v_p[__pyx_v_k]) = __pyx_t_12;

    /* "pysam/csamfile.pyx":2351
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1             # <<<<<<<<<<<<<<
 * 
 *             ## setting the cigar string requires updating the bin
 */
    __pyx_v_k = (__pyx_v_k + 1);
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/csamfile.pyx":2354
 * 
 *             ## setting the cigar string requires updating the bin
 *             pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                           hts_reg2bin(
 *                               src.core.pos,
 */
  pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5));

  /* "pysam/csamfile.pyx":2317
 *             return cigar
 * 
 *         def __set__(self, values):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.cigar.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_op);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2378
 *         empty string.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             c = self.cigar
 *             if c == None: return ""
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_11cigarstring_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_11cigarstring_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_11cigarstring___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_11cigarstring___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_v_c = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  Py_ssize_t __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2378);

  /* "pysam/csamfile.pyx":2379
 *         '''
 *         def __get__(self):
 *             c = self.cigar             # <<<<<<<<<<<<<<
 *             if c == None: return ""
 *             # reverse order
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigar); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_c = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":2380
 *         def __get__(self):
 *             c = self.cigar
 *             if c == None: return ""             # <<<<<<<<<<<<<<
 *             # reverse order
 *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_c, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_s__9);
    __pyx_r = __pyx_kp_s__9;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2382
 *             if c == None: return ""
 *             # reverse order
 *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, cigar):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (PyList_CheckExact(__pyx_v_c) || PyTuple_CheckExact(__pyx_v_c)) {
      __pyx_t_3 = __pyx_v_c; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_6 = __pyx_t_5(__pyx_t_3);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
        PyObject* sequence = __pyx_t_6;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        #else
        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        #endif
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
        index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_10 = NULL;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_10 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_11 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_11 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = __Pyx_PyInt_From_char((__pyx_v_5pysam_8csamfile_CODE2CIGAR[__pyx_t_11])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_y);
      __Pyx_GIVEREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_i_c, __pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2378
 *         empty string.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             c = self.cigar
 *             if c == None: return ""
 */

  /* function exit code */
  __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("pysam.csamfile.AlignedRead.cigarstring.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_c);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2384
 *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 * 
 *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigar = []
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_11cigarstring_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_cigar));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_11cigarstring_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_cigar) {
  PyObject *__pyx_v_parts = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2384);

  /* "pysam/csamfile.pyx":2385
 * 
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:             # <<<<<<<<<<<<<<
 *                 self.cigar = []
 *             else:
 */
  __pyx_t_1 = (__pyx_v_cigar == Py_None);
  if (!(__pyx_t_1 != 0)) {
    __pyx_t_2 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = ((__pyx_t_2 == 0) != 0);
    __pyx_t_4 = __pyx_t_3;
  } else {
    __pyx_t_4 = (__pyx_t_1 != 0);
  }
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":2386
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigar = []             # <<<<<<<<<<<<<<
 *             else:
 *                 parts = CIGAR_REGEX.findall(cigar)
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigar, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2388
 *                 self.cigar = []
 *             else:
 *                 parts = CIGAR_REGEX.findall(cigar)             # <<<<<<<<<<<<<<
 *                 # reverse order
 *                 self.cigar = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts]
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_REGEX); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_findall); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __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 = 2388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_cigar);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_cigar);
    __Pyx_GIVEREF(__pyx_v_cigar);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2388; __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_5); __pyx_t_5 = 0;
    __pyx_v_parts = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysam/csamfile.pyx":2390
 *                 parts = CIGAR_REGEX.findall(cigar)
 *                 # reverse order
 *                 self.cigar = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts]             # <<<<<<<<<<<<<<
 * 
 *     property seq:
 */
    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    if (PyList_CheckExact(__pyx_v_parts) || PyTuple_CheckExact(__pyx_v_parts)) {
      __pyx_t_5 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_5); __pyx_t_2 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_2 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_5)) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_5)) {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_6 = __pyx_t_8(__pyx_t_5);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
        PyObject* sequence = __pyx_t_6;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_10);
        #else
        __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
        index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_12 = NULL;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
      __pyx_t_9 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR2CODE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_y);
      __Pyx_GIVEREF(__pyx_v_y);
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = PyObject_GetItem(__pyx_t_6, __pyx_t_9); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyNumber_Int(__pyx_v_x); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      __pyx_t_10 = 0;
      __pyx_t_9 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigar, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2384
 *             else: return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 * 
 *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigar = []
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.cigarstring.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_parts);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2412
 *         sequence.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef char * s
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3seq_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3seq_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3seq___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3seq___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2412);

  /* "pysam/csamfile.pyx":2415
 *             cdef bam1_t * src
 *             cdef char * s
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2417
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             return get_seq_range(src, 0, src.core.l_qseq)
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2419
 *             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_3 = __pyx_f_5pysam_8csamfile_get_seq_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2412
 *         sequence.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef char * s
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.seq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2421
 *             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.
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3seq_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_seq));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3seq_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__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;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  bam1_t *__pyx_t_4;
  int __pyx_t_5;
  char *__pyx_t_6;
  long __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2421);
  __Pyx_INCREF(__pyx_v_seq);

  /* "pysam/csamfile.pyx":2429
 *             cdef int l, k, nbytes_new, nbytes_old
 * 
 *             if seq == None:             # <<<<<<<<<<<<<<
 *                 l = 0
 *             else:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2430
 * 
 *             if seq == None:
 *                 l = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 l = len(seq)
 */
    __pyx_v_l = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2432
 *                 l = 0
 *             else:
 *                 l = len(seq)             # <<<<<<<<<<<<<<
 *                 seq = _forceBytes(seq)
 * 
 */
    __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_l = __pyx_t_3;

    /* "pysam/csamfile.pyx":2433
 *             else:
 *                 l = len(seq)
 *                 seq = _forceBytes(seq)             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
    __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_seq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_seq, __pyx_t_1);
    __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2435
 *                 seq = _forceBytes(seq)
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # as the sequence is stored in half-bytes, the total length (sequence
 */
  __pyx_t_4 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_4;

  /* "pysam/csamfile.pyx":2439
 *             # 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
 * 
 */
  __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);

  /* "pysam/csamfile.pyx":2440
 *             # 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_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);

  /* "pysam/csamfile.pyx":2443
 * 
 *             # acquire pointer to location in memory
 *             p = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 *             src.core.l_qseq = l
 * 
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysam/csamfile.pyx":2444
 *             # acquire pointer to location in memory
 *             p = pysam_bam_get_seq(src)
 *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
 * 
 *             # change length of data field
 */
  __pyx_v_src->core.l_qseq = __pyx_v_l;

  /* "pysam/csamfile.pyx":2447
 * 
 *             # change length of data field
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              nbytes_old,
 *                              nbytes_new,
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);

  /* "pysam/csamfile.pyx":2452
 *                              p)
 * 
 *             if l > 0:             # <<<<<<<<<<<<<<
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 */
  __pyx_t_2 = ((__pyx_v_l > 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2455
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 *                 p = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 *                 for k from 0 <= k < nbytes_new:
 *                     p[k] = 0
 */
    __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

    /* "pysam/csamfile.pyx":2456
 *                 # as it might have moved
 *                 p = pysam_bam_get_seq(src)
 *                 for k from 0 <= k < nbytes_new:             # <<<<<<<<<<<<<<
 *                     p[k] = 0
 *                 # convert to C string
 */
    __pyx_t_5 = __pyx_v_nbytes_new;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

      /* "pysam/csamfile.pyx":2457
 *                 p = pysam_bam_get_seq(src)
 *                 for k from 0 <= k < nbytes_new:
 *                     p[k] = 0             # <<<<<<<<<<<<<<
 *                 # convert to C string
 *                 s = seq
 */
      (__pyx_v_p[__pyx_v_k]) = 0;
    }

    /* "pysam/csamfile.pyx":2459
 *                     p[k] = 0
 *                 # convert to C string
 *                 s = seq             # <<<<<<<<<<<<<<
 *                 for k from 0 <= k < l:
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_s = __pyx_t_6;

    /* "pysam/csamfile.pyx":2460
 *                 # convert to C string
 *                 s = seq
 *                 for k from 0 <= k < l:             # <<<<<<<<<<<<<<
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)
 * 
 */
    __pyx_t_5 = __pyx_v_l;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

      /* "pysam/csamfile.pyx":2461
 *                 s = seq
 *                 for k from 0 <= k < l:
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
 * 
 *                 # erase qualities
 */
      __pyx_t_7 = __Pyx_div_long(__pyx_v_k, 2);
      (__pyx_v_p[__pyx_t_7]) = ((__pyx_v_p[__pyx_t_7]) | ((seq_nt16_table[((unsigned char)(__pyx_v_s[__pyx_v_k]))]) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))));
    }

    /* "pysam/csamfile.pyx":2464
 * 
 *                 # erase qualities
 *                 p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *                 p[0] = 0xff
 * 
 */
    __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

    /* "pysam/csamfile.pyx":2465
 *                 # erase qualities
 *                 p = pysam_bam_get_qual(src)
 *                 p[0] = 0xff             # <<<<<<<<<<<<<<
 * 
 *     property qual:
 */
    (__pyx_v_p[0]) = 0xff;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysam/csamfile.pyx":2421
 *             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.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.seq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2482
 *         quality scores and the sequence are not the same.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4qual_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4qual_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4qual___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4qual___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2482);

  /* "pysam/csamfile.pyx":2487
 *             cdef char * q
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2489
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             return get_qual_range(src, 0, src.core.l_qseq)
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2491
 *             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_3 = __pyx_f_5pysam_8csamfile_get_qual_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2482
 *         quality scores and the sequence are not the same.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2493
 *             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
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4qual_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_qual));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4qual_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__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;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  char *__pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2493);
  __Pyx_INCREF(__pyx_v_qual);

  /* "pysam/csamfile.pyx":2500
 *             cdef int k
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = pysam_bam_get_qual(src)
 *             if qual == None or len(qual) == 0:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2501
 * 
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *             if qual == None or len(qual) == 0:
 *                 # if absent - set to 0xff
 */
  __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

  /* "pysam/csamfile.pyx":2502
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)
 *             if qual == None or len(qual) == 0:             # <<<<<<<<<<<<<<
 *                 # if absent - set to 0xff
 *                 p[0] = 0xff
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_qual, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_3) {
    __pyx_t_4 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = (__pyx_t_4 == 0);
    __pyx_t_6 = __pyx_t_5;
  } else {
    __pyx_t_6 = __pyx_t_3;
  }
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":2504
 *             if qual == None or len(qual) == 0:
 *                 # if absent - set to 0xff
 *                 p[0] = 0xff             # <<<<<<<<<<<<<<
 *                 return
 *             qual = _forceBytes(qual)
 */
    (__pyx_v_p[0]) = 0xff;

    /* "pysam/csamfile.pyx":2505
 *                 # if absent - set to 0xff
 *                 p[0] = 0xff
 *                 return             # <<<<<<<<<<<<<<
 *             qual = _forceBytes(qual)
 *             cdef int l
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2506
 *                 p[0] = 0xff
 *                 return
 *             qual = _forceBytes(qual)             # <<<<<<<<<<<<<<
 *             cdef int l
 *             # convert to C string
 */
  __pyx_t_2 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_qual); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF_SET(__pyx_v_qual, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":2509
 *             cdef int l
 *             # convert to C string
 *             q = qual             # <<<<<<<<<<<<<<
 *             l = len(qual)
 *             if src.core.l_qseq != l:
 */
  __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_q = __pyx_t_7;

  /* "pysam/csamfile.pyx":2510
 *             # 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_4 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = __pyx_t_4;

  /* "pysam/csamfile.pyx":2511
 *             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_6 = ((__pyx_v_src->core.l_qseq != __pyx_v_l) != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":2512
 *             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_2 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __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_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_2 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":2513
 *             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 CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!((__pyx_v_src->core.l_qseq == __pyx_v_l) != 0))) {
      PyErr_SetNone(PyExc_AssertionError);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

  /* "pysam/csamfile.pyx":2514
 *                 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_10 = __pyx_v_l;
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_10; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":2515
 *             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);
  }

  /* "pysam/csamfile.pyx":2493
 *             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
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qual);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2534
 *         were not considered for alignment may have been retained."""
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5query_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5query_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5query___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5query___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2534);

  /* "pysam/csamfile.pyx":2539
 *             cdef char * s
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2541
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             start = query_start(src)
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2543
 *             if src.core.l_qseq == 0: return None
 * 
 *             start = query_start(src)             # <<<<<<<<<<<<<<
 *             end   = query_end(src)
 * 
 */
  __pyx_t_3 = __pyx_f_5pysam_8csamfile_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_3;

  /* "pysam/csamfile.pyx":2544
 * 
 *             start = query_start(src)
 *             end   = query_end(src)             # <<<<<<<<<<<<<<
 * 
 *             return get_seq_range(src, start, end)
 */
  __pyx_t_3 = __pyx_f_5pysam_8csamfile_query_end(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_3;

  /* "pysam/csamfile.pyx":2546
 *             end   = query_end(src)
 * 
 *             return get_seq_range(src, start, end)             # <<<<<<<<<<<<<<
 * 
 *     property qqual:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __pyx_f_5pysam_8csamfile_get_seq_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2534
 *         were not considered for alignment may have been retained."""
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.query.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2557
 * 
 *         In Python 3, this property is of type bytes."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5qqual_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5qqual_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5qqual___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5qqual___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2557);

  /* "pysam/csamfile.pyx":2561
 *             cdef uint32_t start, end
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2563
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             start = query_start(src)
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2565
 *             if src.core.l_qseq == 0: return None
 * 
 *             start = query_start(src)             # <<<<<<<<<<<<<<
 *             end   = query_end(src)
 * 
 */
  __pyx_t_3 = __pyx_f_5pysam_8csamfile_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_3;

  /* "pysam/csamfile.pyx":2566
 * 
 *             start = query_start(src)
 *             end   = query_end(src)             # <<<<<<<<<<<<<<
 * 
 *             return get_qual_range(src, start, end)
 */
  __pyx_t_3 = __pyx_f_5pysam_8csamfile_query_end(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_3;

  /* "pysam/csamfile.pyx":2568
 *             end   = query_end(src)
 * 
 *             return get_qual_range(src, start, end)             # <<<<<<<<<<<<<<
 * 
 *     property qstart:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __pyx_f_5pysam_8csamfile_get_qual_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2557
 * 
 *         In Python 3, this property is of type bytes."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qqual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2575
 *         This the index of the first base in :attr:`seq` that is not soft-clipped.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return query_start(self._delegate)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_6qstart_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_6qstart_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_6qstart___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_6qstart___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2575);

  /* "pysam/csamfile.pyx":2576
 *         """
 *         def __get__(self):
 *             return query_start(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property qend:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_8csamfile_query_start(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2575
 *         This the index of the first base in :attr:`seq` that is not soft-clipped.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return query_start(self._delegate)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qstart.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2580
 *     property qend:
 *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return query_end(self._delegate)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4qend_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4qend_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4qend___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4qend___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2580);

  /* "pysam/csamfile.pyx":2581
 *         """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_5pysam_8csamfile_query_end(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2580
 *     property qend:
 *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return query_end(self._delegate)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2587
 * 
 *         This is equal to :attr:`qend` - :attr:`qstart`"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4qlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4qlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4qlen___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4qlen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int32_t __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2587);

  /* "pysam/csamfile.pyx":2589
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             return query_end(src)-query_start(src)
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2590
 *             cdef bam1_t * src
 *             src = self._delegate
 *             return query_end(src)-query_start(src)             # <<<<<<<<<<<<<<
 * 
 *     property tags:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_5pysam_8csamfile_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __pyx_f_5pysam_8csamfile_query_start(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2587
 * 
 *         This is equal to :attr:`qend` - :attr:`qstart`"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.qlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2606
 *         multiple times.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef char * ctag
 *             cdef bam1_t * src
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4tags_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4tags_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4tags___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4tags___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char __pyx_v_auxtag[3];
  char __pyx_v_auxtype;
  uint8_t __pyx_v_byte_size;
  int32_t __pyx_v_nvalues;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  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;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  uint8_t __pyx_t_10;
  int32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2606);

  /* "pysam/csamfile.pyx":2615
 *             cdef int32_t nvalues
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if src.l_data == 0:
 *                 return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2616
 * 
 *             src = self._delegate
 *             if src.l_data == 0:             # <<<<<<<<<<<<<<
 *                 return []
 *             s = pysam_bam_get_aux(src)
 */
  __pyx_t_2 = ((__pyx_v_src->l_data == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":2617
 *             src = self._delegate
 *             if src.l_data == 0:
 *                 return []             # <<<<<<<<<<<<<<
 *             s = pysam_bam_get_aux(src)
 *             result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2617; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2618
 *             if src.l_data == 0:
 *                 return []
 *             s = pysam_bam_get_aux(src)             # <<<<<<<<<<<<<<
 *             result = []
 *             auxtag[2] = 0
 */
  __pyx_v_s = pysam_bam_get_aux(__pyx_v_src);

  /* "pysam/csamfile.pyx":2619
 *                 return []
 *             s = pysam_bam_get_aux(src)
 *             result = []             # <<<<<<<<<<<<<<
 *             auxtag[2] = 0
 *             while s < (src.data + src.l_data):
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":2620
 *             s = pysam_bam_get_aux(src)
 *             result = []
 *             auxtag[2] = 0             # <<<<<<<<<<<<<<
 *             while s < (src.data + src.l_data):
 *                 # get tag
 */
  (__pyx_v_auxtag[2]) = 0;

  /* "pysam/csamfile.pyx":2621
 *             result = []
 *             auxtag[2] = 0
 *             while s < (src.data + src.l_data):             # <<<<<<<<<<<<<<
 *                 # get tag
 *                 auxtag[0] = s[0]
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->l_data)) != 0);
    if (!__pyx_t_2) break;

    /* "pysam/csamfile.pyx":2623
 *             while s < (src.data + src.l_data):
 *                 # get tag
 *                 auxtag[0] = s[0]             # <<<<<<<<<<<<<<
 *                 auxtag[1] = s[1]
 *                 s += 2
 */
    (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);

    /* "pysam/csamfile.pyx":2624
 *                 # get tag
 *                 auxtag[0] = s[0]
 *                 auxtag[1] = s[1]             # <<<<<<<<<<<<<<
 *                 s += 2
 *                 auxtype = s[0]
 */
    (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);

    /* "pysam/csamfile.pyx":2625
 *                 auxtag[0] = s[0]
 *                 auxtag[1] = s[1]
 *                 s += 2             # <<<<<<<<<<<<<<
 *                 auxtype = s[0]
 *                 if auxtype in ('c', 'C'):
 */
    __pyx_v_s = (__pyx_v_s + 2);

    /* "pysam/csamfile.pyx":2626
 *                 auxtag[1] = s[1]
 *                 s += 2
 *                 auxtype = s[0]             # <<<<<<<<<<<<<<
 *                 if auxtype in ('c', 'C'):
 *                     value = <int>bam_aux2i(s)
 */
    __pyx_v_auxtype = (__pyx_v_s[0]);

    /* "pysam/csamfile.pyx":2649
 *                     # +1 for NULL terminated string
 *                     s += len(value) + 1
 *                 elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *                     s += 1
 *                     byte_size, nvalues, value = convertBinaryTagToList( s )
 */
    switch (__pyx_v_auxtype) {

      /* "pysam/csamfile.pyx":2627
 *                 s += 2
 *                 auxtype = s[0]
 *                 if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
 *                     value = <int>bam_aux2i(s)
 *                     s += 1
 */
      case 'c':
      case 'C':

      /* "pysam/csamfile.pyx":2628
 *                 auxtype = s[0]
 *                 if auxtype in ('c', 'C'):
 *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                     s += 1
 *                 elif auxtype in ('s', 'S'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/csamfile.pyx":2629
 *                 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 = (__pyx_v_s + 1);
      break;

      /* "pysam/csamfile.pyx":2630
 *                     value = <int>bam_aux2i(s)
 *                     s += 1
 *                 elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
 *                     value = <int>bam_aux2i(s)
 *                     s += 2
 */
      case 's':
      case 'S':

      /* "pysam/csamfile.pyx":2631
 *                     s += 1
 *                 elif auxtype in ('s', 'S'):
 *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                     s += 2
 *                 elif auxtype in ('i', 'I'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/csamfile.pyx":2632
 *                 elif auxtype in ('s', 'S'):
 *                     value = <int>bam_aux2i(s)
 *                     s += 2             # <<<<<<<<<<<<<<
 *                 elif auxtype in ('i', 'I'):
 *                     value = <int32_t>bam_aux2i(s)
 */
      __pyx_v_s = (__pyx_v_s + 2);
      break;

      /* "pysam/csamfile.pyx":2633
 *                     value = <int>bam_aux2i(s)
 *                     s += 2
 *                 elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
 *                     value = <int32_t>bam_aux2i(s)
 *                     s += 4
 */
      case 'i':
      case 'I':

      /* "pysam/csamfile.pyx":2634
 *                     s += 2
 *                 elif auxtype in ('i', 'I'):
 *                     value = <int32_t>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                     s += 4
 *                 elif auxtype == 'f':
 */
      __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/csamfile.pyx":2635
 *                 elif auxtype in ('i', 'I'):
 *                     value = <int32_t>bam_aux2i(s)
 *                     s += 4             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'f':
 *                     value = <float>bam_aux2f(s)
 */
      __pyx_v_s = (__pyx_v_s + 4);
      break;

      /* "pysam/csamfile.pyx":2636
 *                     value = <int32_t>bam_aux2i(s)
 *                     s += 4
 *                 elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *                     value = <float>bam_aux2f(s)
 *                     s += 4
 */
      case 'f':

      /* "pysam/csamfile.pyx":2637
 *                     s += 4
 *                 elif auxtype == 'f':
 *                     value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                     s += 4
 *                 elif auxtype == 'd':
 */
      __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/csamfile.pyx":2638
 *                 elif auxtype == 'f':
 *                     value = <float>bam_aux2f(s)
 *                     s += 4             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'd':
 *                     value = <double>bam_aux2f(s)
 */
      __pyx_v_s = (__pyx_v_s + 4);
      break;

      /* "pysam/csamfile.pyx":2639
 *                     value = <float>bam_aux2f(s)
 *                     s += 4
 *                 elif auxtype == 'd':             # <<<<<<<<<<<<<<
 *                     value = <double>bam_aux2f(s)
 *                     s += 8
 */
      case 'd':

      /* "pysam/csamfile.pyx":2640
 *                     s += 4
 *                 elif auxtype == 'd':
 *                     value = <double>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                     s += 8
 *                 elif auxtype == 'A':
 */
      __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/csamfile.pyx":2641
 *                 elif auxtype == 'd':
 *                     value = <double>bam_aux2f(s)
 *                     s += 8             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'A':
 *                     value = "%c" % <char>bam_aux2A(s)
 */
      __pyx_v_s = (__pyx_v_s + 8);
      break;

      /* "pysam/csamfile.pyx":2642
 *                     value = <double>bam_aux2f(s)
 *                     s += 8
 *                 elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *                     value = "%c" % <char>bam_aux2A(s)
 *                     s += 1
 */
      case 'A':

      /* "pysam/csamfile.pyx":2643
 *                     s += 8
 *                 elif auxtype == 'A':
 *                     value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
 *                     s += 1
 *                 elif auxtype in ('Z', 'H'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/csamfile.pyx":2644
 *                 elif auxtype == 'A':
 *                     value = "%c" % <char>bam_aux2A(s)
 *                     s += 1             # <<<<<<<<<<<<<<
 *                 elif auxtype in ('Z', 'H'):
 *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
 */
      __pyx_v_s = (__pyx_v_s + 1);
      break;

      /* "pysam/csamfile.pyx":2645
 *                     value = "%c" % <char>bam_aux2A(s)
 *                     s += 1
 *                 elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
 *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
 *                     # +1 for NULL terminated string
 */
      case 'Z':
      case 'H':

      /* "pysam/csamfile.pyx":2646
 *                     s += 1
 *                 elif auxtype in ('Z', 'H'):
 *                     value = _charptr_to_str(<char*>bam_aux2Z(s))             # <<<<<<<<<<<<<<
 *                     # +1 for NULL terminated string
 *                     s += len(value) + 1
 */
      __pyx_t_4 = __pyx_f_5pysam_8csamfile__charptr_to_str(((char *)bam_aux2Z(__pyx_v_s))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/csamfile.pyx":2648
 *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
 *                     # +1 for NULL terminated string
 *                     s += len(value) + 1             # <<<<<<<<<<<<<<
 *                 elif auxtype == 'B':
 *                     s += 1
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_s = (__pyx_v_s + (__pyx_t_5 + 1));
      break;

      /* "pysam/csamfile.pyx":2649
 *                     # +1 for NULL terminated string
 *                     s += len(value) + 1
 *                 elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *                     s += 1
 *                     byte_size, nvalues, value = convertBinaryTagToList( s )
 */
      case 'B':

      /* "pysam/csamfile.pyx":2650
 *                     s += len(value) + 1
 *                 elif auxtype == 'B':
 *                     s += 1             # <<<<<<<<<<<<<<
 *                     byte_size, nvalues, value = convertBinaryTagToList( s )
 *                     # 5 for 1 char and 1 int
 */
      __pyx_v_s = (__pyx_v_s + 1);

      /* "pysam/csamfile.pyx":2651
 *                 elif auxtype == 'B':
 *                     s += 1
 *                     byte_size, nvalues, value = convertBinaryTagToList( s )             # <<<<<<<<<<<<<<
 *                     # 5 for 1 char and 1 int
 *                     s += 5 + ( nvalues * byte_size) - 1
 */
      __pyx_t_4 = __pyx_f_5pysam_8csamfile_convertBinaryTagToList(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
        PyObject* sequence = __pyx_t_4;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 2; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __pyx_t_10 = __Pyx_PyInt_As_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_10 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_6); if (unlikely((__pyx_t_11 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_byte_size = __pyx_t_10;
      __pyx_v_nvalues = __pyx_t_11;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/csamfile.pyx":2653
 *                     byte_size, nvalues, value = convertBinaryTagToList( s )
 *                     # 5 for 1 char and 1 int
 *                     s += 5 + ( nvalues * byte_size) - 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise KeyError("unknown type '%s'" % auxtype)
 */
      __pyx_v_s = (__pyx_v_s + ((5 + (__pyx_v_nvalues * __pyx_v_byte_size)) - 1));
      break;
      default:

      /* "pysam/csamfile.pyx":2655
 *                     s += 5 + ( nvalues * byte_size) - 1
 *                 else:
 *                     raise KeyError("unknown type '%s'" % auxtype)             # <<<<<<<<<<<<<<
 * 
 *                 s += 1
 */
      __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_unknown_type_s, __pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __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 = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;
    }

    /* "pysam/csamfile.pyx":2657
 *                     raise KeyError("unknown type '%s'" % auxtype)
 * 
 *                 s += 1             # <<<<<<<<<<<<<<
 * 
 *                 result.append((_charptr_to_str(auxtag), value))
 */
    __pyx_v_s = (__pyx_v_s + 1);

    /* "pysam/csamfile.pyx":2659
 *                 s += 1
 * 
 *                 result.append((_charptr_to_str(auxtag), value))             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
    __pyx_t_7 = __pyx_f_5pysam_8csamfile__charptr_to_str(__pyx_v_auxtag); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_7 = 0;
    __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }

  /* "pysam/csamfile.pyx":2661
 *                 result.append((_charptr_to_str(auxtag), value))
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, tags):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2606
 *         multiple times.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef char * ctag
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.tags.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2663
 *             return result
 * 
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint8_t * s
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4tags_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tags));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4tags_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tags) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char *__pyx_v_temp;
  int __pyx_v_new_size;
  int __pyx_v_old_size;
  PyObject *__pyx_v_fmts = NULL;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_pytag = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_v_buffer = NULL;
  PyObject *__pyx_v_p = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  char *__pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2663);

  /* "pysam/csamfile.pyx":2667
 *             cdef uint8_t * s
 *             cdef char * temp
 *             cdef int new_size = 0             # <<<<<<<<<<<<<<
 *             cdef int old_size
 *             src = self._delegate
 */
  __pyx_v_new_size = 0;

  /* "pysam/csamfile.pyx":2669
 *             cdef int new_size = 0
 *             cdef int old_size
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             fmts, args = ["<"], []
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2670
 *             cdef int old_size
 *             src = self._delegate
 *             fmts, args = ["<"], []             # <<<<<<<<<<<<<<
 * 
 *             if tags is not None and len(tags) > 0:
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_kp_s__76);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_kp_s__76);
  __Pyx_GIVEREF(__pyx_kp_s__76);
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_fmts = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_v_args = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":2672
 *             fmts, args = ["<"], []
 * 
 *             if tags is not None and len(tags) > 0:             # <<<<<<<<<<<<<<
 *                 for pytag, value in tags:
 *                     convert_python_tag(pytag, value, fmts, args)
 */
  __pyx_t_4 = (__pyx_v_tags != Py_None);
  if ((__pyx_t_4 != 0)) {
    __pyx_t_5 = PyObject_Length(__pyx_v_tags); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = ((__pyx_t_5 > 0) != 0);
    __pyx_t_7 = __pyx_t_6;
  } else {
    __pyx_t_7 = (__pyx_t_4 != 0);
  }
  if (__pyx_t_7) {

    /* "pysam/csamfile.pyx":2673
 * 
 *             if tags is not None and len(tags) > 0:
 *                 for pytag, value in tags:             # <<<<<<<<<<<<<<
 *                     convert_python_tag(pytag, value, fmts, args)
 *                 fmt = "".join(fmts)
 */
    if (PyList_CheckExact(__pyx_v_tags) || PyTuple_CheckExact(__pyx_v_tags)) {
      __pyx_t_3 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_3)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_3)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_2 = __pyx_t_8(__pyx_t_3);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_10);
        #else
        __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_11 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
        index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_12 = NULL;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_9);
      __pyx_t_9 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_10);
      __pyx_t_10 = 0;

      /* "pysam/csamfile.pyx":2674
 *             if tags is not None and len(tags) > 0:
 *                 for pytag, value in tags:
 *                     convert_python_tag(pytag, value, fmts, args)             # <<<<<<<<<<<<<<
 *                 fmt = "".join(fmts)
 *                 new_size = struct.calcsize(fmt)
 */
      __pyx_t_2 = __pyx_f_5pysam_8csamfile_convert_python_tag(__pyx_v_pytag, __pyx_v_value, __pyx_v_fmts, __pyx_v_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":2675
 *                 for pytag, value in tags:
 *                     convert_python_tag(pytag, value, fmts, args)
 *                 fmt = "".join(fmts)             # <<<<<<<<<<<<<<
 *                 new_size = struct.calcsize(fmt)
 *                 buffer = ctypes.create_string_buffer(new_size)
 */
    __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_v_fmts); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_fmt = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":2676
 *                     convert_python_tag(pytag, value, fmts, args)
 *                 fmt = "".join(fmts)
 *                 new_size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
 *                 buffer = ctypes.create_string_buffer(new_size)
 *                 struct.pack_into(fmt,
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2676; __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 = 2676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_fmt);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fmt);
    __Pyx_GIVEREF(__pyx_v_fmt);
    __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_v_new_size = __pyx_t_13;

    /* "pysam/csamfile.pyx":2677
 *                 fmt = "".join(fmts)
 *                 new_size = struct.calcsize(fmt)
 *                 buffer = ctypes.create_string_buffer(new_size)             # <<<<<<<<<<<<<<
 *                 struct.pack_into(fmt,
 *                                  buffer,
 */
    __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_new_size); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_buffer = __pyx_t_10;
    __pyx_t_10 = 0;

    /* "pysam/csamfile.pyx":2678
 *                 new_size = struct.calcsize(fmt)
 *                 buffer = ctypes.create_string_buffer(new_size)
 *                 struct.pack_into(fmt,             # <<<<<<<<<<<<<<
 *                                  buffer,
 *                                  0,
 */
    __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "pysam/csamfile.pyx":2679
 *                 buffer = ctypes.create_string_buffer(new_size)
 *                 struct.pack_into(fmt,
 *                                  buffer,             # <<<<<<<<<<<<<<
 *                                  0,
 *                                  *args)
 */
    __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __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);
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);

    /* "pysam/csamfile.pyx":2678
 *                 new_size = struct.calcsize(fmt)
 *                 buffer = ctypes.create_string_buffer(new_size)
 *                 struct.pack_into(fmt,             # <<<<<<<<<<<<<<
 *                                  buffer,
 *                                  0,
 */
    __pyx_t_3 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = PyNumber_Add(__pyx_t_10, __pyx_t_3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __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_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2686
 *             # If total_size == 0, the aux field will be
 *             # empty
 *             old_size = pysam_bam_get_l_aux(src)             # <<<<<<<<<<<<<<
 *             pysam_bam_update(src,
 *                              old_size,
 */
  __pyx_v_old_size = pysam_bam_get_l_aux(__pyx_v_src);

  /* "pysam/csamfile.pyx":2687
 *             # empty
 *             old_size = pysam_bam_get_l_aux(src)
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              old_size,
 *                              new_size,
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_old_size, __pyx_v_new_size, pysam_bam_get_aux(__pyx_v_src));

  /* "pysam/csamfile.pyx":2693
 * 
 *             # copy data only if there is any
 *             if new_size > 0:             # <<<<<<<<<<<<<<
 * 
 *                 # get location of new data
 */
  __pyx_t_7 = ((__pyx_v_new_size > 0) != 0);
  if (__pyx_t_7) {

    /* "pysam/csamfile.pyx":2696
 * 
 *                 # get location of new data
 *                 s = pysam_bam_get_aux(src)             # <<<<<<<<<<<<<<
 * 
 *                 # check if there is direct path from buffer.raw to tmp
 */
    __pyx_v_s = pysam_bam_get_aux(__pyx_v_src);

    /* "pysam/csamfile.pyx":2699
 * 
 *                 # check if there is direct path from buffer.raw to tmp
 *                 p = buffer.raw             # <<<<<<<<<<<<<<
 *                 # create handle to make sure buffer stays alive long
 *                 # enough for memcpy, see issue 129
 */
    if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_p = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":2702
 *                 # create handle to make sure buffer stays alive long
 *                 # enough for memcpy, see issue 129
 *                 temp = p             # <<<<<<<<<<<<<<
 *                 memcpy(s, temp, new_size)
 * 
 */
    __pyx_t_14 = __Pyx_PyObject_AsString(__pyx_v_p); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_temp = __pyx_t_14;

    /* "pysam/csamfile.pyx":2703
 *                 # enough for memcpy, see issue 129
 *                 temp = p
 *                 memcpy(s, temp, new_size)             # <<<<<<<<<<<<<<
 * 
 *     cpdef setTag(self, tag, value,
 */
    memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_new_size);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "pysam/csamfile.pyx":2663
 *             return result
 * 
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint8_t * s
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.tags.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fmts);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_pytag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XDECREF(__pyx_v_buffer);
  __Pyx_XDECREF(__pyx_v_p);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2705
 *                 memcpy(s, temp, new_size)
 * 
 *     cpdef setTag(self, tag, value,             # <<<<<<<<<<<<<<
 *                  value_type = None,
 *                  replace = True):
 */

static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_13setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_5pysam_8csamfile_11AlignedRead_setTag(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_8csamfile_11AlignedRead_setTag *__pyx_optional_args) {

  /* "pysam/csamfile.pyx":2706
 * 
 *     cpdef setTag(self, tag, value,
 *                  value_type = None,             # <<<<<<<<<<<<<<
 *                  replace = True):
 *         '''
 */
  PyObject *__pyx_v_value_type = ((PyObject *)Py_None);

  /* "pysam/csamfile.pyx":2707
 *     cpdef setTag(self, tag, value,
 *                  value_type = None,
 *                  replace = True):             # <<<<<<<<<<<<<<
 *         '''
 *         Set optional field of alignment *tag* to *value*.  *value_type* may be specified,
 */
  PyObject *__pyx_v_replace = ((PyObject *)Py_True);
  int __pyx_v_value_size;
  uint8_t *__pyx_v_value_ptr;
  uint8_t *__pyx_v_existing_ptr;
  uint8_t __pyx_v_type_code;
  float __pyx_v_float_value;
  double __pyx_v_double_value;
  int32_t __pyx_v_int_value;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  bam1_t *__pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  uint8_t __pyx_t_7;
  struct __pyx_opt_args_5pysam_8csamfile_get_type_code __pyx_t_8;
  char *__pyx_t_9;
  int32_t __pyx_t_10;
  double __pyx_t_11;
  float __pyx_t_12;
  char const *__pyx_t_13;
  char const *__pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setTag", 0);
  __Pyx_TraceCall("setTag", __pyx_f[0], 2705);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_value_type = __pyx_optional_args->value_type;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_replace = __pyx_optional_args->replace;
      }
    }
  }
  __Pyx_INCREF(__pyx_v_tag);
  __Pyx_INCREF(__pyx_v_value);

  /* "pysam/csamfile.pyx":2705
 *                 memcpy(s, temp, new_size)
 * 
 *     cpdef setTag(self, tag, value,             # <<<<<<<<<<<<<<
 *                  value_type = None,
 *                  replace = True):
 */
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setTag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_13setTag)) {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __Pyx_INCREF(__pyx_v_value_type);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_value_type);
      __Pyx_GIVEREF(__pyx_v_value_type);
      __Pyx_INCREF(__pyx_v_replace);
      PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_replace);
      __Pyx_GIVEREF(__pyx_v_replace);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/csamfile.pyx":2723
 *         cdef double   double_value
 *         cdef int32_t  int_value
 *         cdef bam1_t * src = self._delegate             # <<<<<<<<<<<<<<
 *         cdef char * _value_type
 * 
 */
  __pyx_t_4 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_4;

  /* "pysam/csamfile.pyx":2726
 *         cdef char * _value_type
 * 
 *         if len(tag) != 2:             # <<<<<<<<<<<<<<
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2726; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((__pyx_t_5 != 2) != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":2727
 * 
 *         if len(tag) != 2:
 *             raise ValueError('Invalid tag: %s' % tag)             # <<<<<<<<<<<<<<
 * 
 *         type_code = get_type_code(value, value_type)
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_tag_s, __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2727; __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 = 2727; __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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":2729
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 *         type_code = get_type_code(value, value_type)             # <<<<<<<<<<<<<<
 *         if type_code == 0:
 *             raise ValueError("can't guess type or invalid type code specified")
 */
  __pyx_t_8.__pyx_n = 1;
  __pyx_t_8.value_type = __pyx_v_value_type;
  __pyx_t_7 = __pyx_f_5pysam_8csamfile_get_type_code(__pyx_v_value, &__pyx_t_8); 
  __pyx_v_type_code = __pyx_t_7;

  /* "pysam/csamfile.pyx":2730
 * 
 *         type_code = get_type_code(value, value_type)
 *         if type_code == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("can't guess type or invalid type code specified")
 * 
 */
  __pyx_t_6 = ((__pyx_v_type_code == 0) != 0);
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":2731
 *         type_code = get_type_code(value, value_type)
 *         if type_code == 0:
 *             raise ValueError("can't guess type or invalid type code specified")             # <<<<<<<<<<<<<<
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__77, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":2746
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':             # <<<<<<<<<<<<<<
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value
 */
  switch (__pyx_v_type_code) {

    /* "pysam/csamfile.pyx":2734
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 *         if type_code == 'Z':             # <<<<<<<<<<<<<<
 *             value = _forceBytes( value )
 *             value_ptr    = <uint8_t*><char*>value
 */
    case 'Z':

    /* "pysam/csamfile.pyx":2735
 *         # Not Endian-safe, but then again neither is samtools!
 *         if type_code == 'Z':
 *             value = _forceBytes( value )             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*><char*>value
 *             value_size   = len(value)+1
 */
    __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/csamfile.pyx":2736
 *         if type_code == 'Z':
 *             value = _forceBytes( value )
 *             value_ptr    = <uint8_t*><char*>value             # <<<<<<<<<<<<<<
 *             value_size   = len(value)+1
 *         elif type_code == 'i':
 */
    __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_9));

    /* "pysam/csamfile.pyx":2737
 *             value = _forceBytes( value )
 *             value_ptr    = <uint8_t*><char*>value
 *             value_size   = len(value)+1             # <<<<<<<<<<<<<<
 *         elif type_code == 'i':
 *             int_value    = value
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_value_size = (__pyx_t_5 + 1);
    break;

    /* "pysam/csamfile.pyx":2738
 *             value_ptr    = <uint8_t*><char*>value
 *             value_size   = len(value)+1
 *         elif type_code == 'i':             # <<<<<<<<<<<<<<
 *             int_value    = value
 *             value_ptr    = <uint8_t*>&int_value
 */
    case 'i':

    /* "pysam/csamfile.pyx":2739
 *             value_size   = len(value)+1
 *         elif type_code == 'i':
 *             int_value    = value             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*>&int_value
 *             value_size   = sizeof(int32_t)
 */
    __pyx_t_10 = __Pyx_PyInt_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_10 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_int_value = __pyx_t_10;

    /* "pysam/csamfile.pyx":2740
 *         elif type_code == 'i':
 *             int_value    = value
 *             value_ptr    = <uint8_t*>&int_value             # <<<<<<<<<<<<<<
 *             value_size   = sizeof(int32_t)
 *         elif type_code == 'd':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int_value));

    /* "pysam/csamfile.pyx":2741
 *             int_value    = value
 *             value_ptr    = <uint8_t*>&int_value
 *             value_size   = sizeof(int32_t)             # <<<<<<<<<<<<<<
 *         elif type_code == 'd':
 *             double_value = value
 */
    __pyx_v_value_size = (sizeof(int32_t));
    break;

    /* "pysam/csamfile.pyx":2742
 *             value_ptr    = <uint8_t*>&int_value
 *             value_size   = sizeof(int32_t)
 *         elif type_code == 'd':             # <<<<<<<<<<<<<<
 *             double_value = value
 *             value_ptr    = <uint8_t*>&double_value
 */
    case 'd':

    /* "pysam/csamfile.pyx":2743
 *             value_size   = sizeof(int32_t)
 *         elif type_code == 'd':
 *             double_value = value             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)
 */
    __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_double_value = __pyx_t_11;

    /* "pysam/csamfile.pyx":2744
 *         elif type_code == 'd':
 *             double_value = value
 *             value_ptr    = <uint8_t*>&double_value             # <<<<<<<<<<<<<<
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_double_value));

    /* "pysam/csamfile.pyx":2745
 *             double_value = value
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)             # <<<<<<<<<<<<<<
 *         elif type_code == 'f':
 *             float_value  = value
 */
    __pyx_v_value_size = (sizeof(double));
    break;

    /* "pysam/csamfile.pyx":2746
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':             # <<<<<<<<<<<<<<
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value
 */
    case 'f':

    /* "pysam/csamfile.pyx":2747
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':
 *             float_value  = value             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*>&float_value
 *             value_size   = sizeof(float)
 */
    __pyx_t_12 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_12 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_float_value = __pyx_t_12;

    /* "pysam/csamfile.pyx":2748
 *         elif type_code == 'f':
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value             # <<<<<<<<<<<<<<
 *             value_size   = sizeof(float)
 *         else:
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_float_value));

    /* "pysam/csamfile.pyx":2749
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value
 *             value_size   = sizeof(float)             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError('Unsupported value_type in set_option')
 */
    __pyx_v_value_size = (sizeof(float));
    break;
    default:

    /* "pysam/csamfile.pyx":2751
 *             value_size   = sizeof(float)
 *         else:
 *             raise ValueError('Unsupported value_type in set_option')             # <<<<<<<<<<<<<<
 * 
 *         tag = _forceBytes( tag )
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__78, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "pysam/csamfile.pyx":2753
 *             raise ValueError('Unsupported value_type in set_option')
 * 
 *         tag = _forceBytes( tag )             # <<<<<<<<<<<<<<
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 */
  __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_tag, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":2754
 * 
 *         tag = _forceBytes( tag )
 *         if replace:             # <<<<<<<<<<<<<<
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_replace); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":2755
 *         tag = _forceBytes( tag )
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)             # <<<<<<<<<<<<<<
 *             if existing_ptr:
 *                 bam_aux_del(src, existing_ptr)
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_existing_ptr = bam_aux_get(__pyx_v_src, __pyx_t_13);

    /* "pysam/csamfile.pyx":2756
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:             # <<<<<<<<<<<<<<
 *                 bam_aux_del(src, existing_ptr)
 * 
 */
    __pyx_t_6 = (__pyx_v_existing_ptr != 0);
    if (__pyx_t_6) {

      /* "pysam/csamfile.pyx":2757
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 *                 bam_aux_del(src, existing_ptr)             # <<<<<<<<<<<<<<
 * 
 *         bam_aux_append(src,
 */
      bam_aux_del(__pyx_v_src, __pyx_v_existing_ptr);
      goto __pyx_L6;
    }
    __pyx_L6:;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "pysam/csamfile.pyx":2760
 * 
 *         bam_aux_append(src,
 *                        tag,             # <<<<<<<<<<<<<<
 *                        type_code,
 *                        value_size,
 */
  __pyx_t_14 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":2759
 *                 bam_aux_del(src, existing_ptr)
 * 
 *         bam_aux_append(src,             # <<<<<<<<<<<<<<
 *                        tag,
 *                        type_code,
 */
  bam_aux_append(__pyx_v_src, __pyx_t_14, __pyx_v_type_code, __pyx_v_value_size, __pyx_v_value_ptr);

  /* "pysam/csamfile.pyx":2705
 *                 memcpy(s, temp, new_size)
 * 
 *     cpdef setTag(self, tag, value,             # <<<<<<<<<<<<<<
 *                  value_type = None,
 *                  replace = True):
 */

  /* function exit code */
  __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("pysam.csamfile.AlignedRead.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_13setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_12setTag[] = "AlignedRead.setTag(self, tag, value, value_type=None, replace=True)\n\n        Set optional field of alignment *tag* to *value*.  *value_type* may be specified,\n        but if not the type will be inferred based on the Python type of *value*\n\n        An existing value of the same tag will be overwritten unless\n        *replace* is set to False.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_13setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tag = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_value_type = 0;
  PyObject *__pyx_v_replace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("setTag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pysam/csamfile.pyx":2706
 * 
 *     cpdef setTag(self, tag, value,
 *                  value_type = None,             # <<<<<<<<<<<<<<
 *                  replace = True):
 *         '''
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/csamfile.pyx":2707
 *     cpdef setTag(self, tag, value,
 *                  value_type = None,
 *                  replace = True):             # <<<<<<<<<<<<<<
 *         '''
 *         Set optional field of alignment *tag* to *value*.  *value_type* may be specified,
 */
    values[3] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value_type);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_replace);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setTag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tag = values[0];
    __pyx_v_value = values[1];
    __pyx_v_value_type = values[2];
    __pyx_v_replace = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_12setTag(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace);

  /* "pysam/csamfile.pyx":2705
 *                 memcpy(s, temp, new_size)
 * 
 *     cpdef setTag(self, tag, value,             # <<<<<<<<<<<<<<
 *                  value_type = None,
 *                  replace = True):
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_12setTag(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_8csamfile_11AlignedRead_setTag __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("setTag", 0);
  __Pyx_TraceCall("setTag", __pyx_f[0], 2705);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.value_type = __pyx_v_value_type;
  __pyx_t_2.replace = __pyx_v_replace;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_8csamfile_AlignedRead *)__pyx_v_self->__pyx_vtab)->setTag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2767
 *     property flag:
 *         """properties flag"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4flag_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4flag_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4flag___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4flag___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2767);

  /* "pysam/csamfile.pyx":2768
 *         """properties flag"""
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, flag):
 *             pysam_set_flag(self._delegate, flag)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_flag(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2767
 *     property flag:
 *         """properties flag"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.flag.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2769
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):             # <<<<<<<<<<<<<<
 *             pysam_set_flag(self._delegate, flag)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4flag_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_flag));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4flag_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint8_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2769);

  /* "pysam/csamfile.pyx":2770
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 *             pysam_set_flag(self._delegate, flag)             # <<<<<<<<<<<<<<
 * 
 *     property rname:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint8_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_flag(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/csamfile.pyx":2769
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):             # <<<<<<<<<<<<<<
 *             pysam_set_flag(self._delegate, flag)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.flag.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2788
 * 
 *         """
 *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
 *         def __set__(self, tid): self._delegate.core.tid = tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5rname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5rname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5rname___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5rname___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2788);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.rname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2789
 *         """
 *         def __get__(self): return self._delegate.core.tid
 *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
 * 
 *     property tid:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5rname_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5rname_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2789);
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.tid = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.rname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2802
 * 
 *         """
 *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
 *         def __set__(self, tid): self._delegate.core.tid = tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3tid___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3tid___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2802);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2803
 *         """
 *         def __get__(self): return self._delegate.core.tid
 *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
 * 
 *     property pos:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3tid_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3tid_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2803);
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.tid = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2807
 *     property pos:
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
 *         def __set__(self, pos):
 *             ## setting the position requires updating the "bin" attribute
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3pos___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3pos___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2807);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2808
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3pos_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_pos));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3pos_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_pos) {
  bam1_t *__pyx_v_src;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int32_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2808);

  /* "pysam/csamfile.pyx":2811
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2812
 *             cdef bam1_t * src
 *             src = self._delegate
 *             src.core.pos = pos             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src):
 *                 pysam_set_bin(src,
 */
  __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_src->core.pos = __pyx_t_2;

  /* "pysam/csamfile.pyx":2813
 *             src = self._delegate
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 pysam_set_bin(src,
 *                               hts_reg2bin(
 */
  __pyx_t_3 = (pysam_get_n_cigar(__pyx_v_src) != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":2814
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):
 *                 pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                               hts_reg2bin(
 *                                   src.core.pos,
 */
    pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5));
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":2821
 *                                   5))
 *             else:
 *                 pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                               hts_reg2bin(
 *                                   src.core.pos,
 */
    pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1), 14, 5));
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":2808
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2830
 *     property bin:
 *         """properties bin"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3bin_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_3bin_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3bin___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_3bin___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2830);

  /* "pysam/csamfile.pyx":2831
 *         """properties bin"""
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, bin):
 *             pysam_set_bin(self._delegate, bin)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_bin(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2830
 *     property bin:
 *         """properties bin"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.bin.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2832
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):             # <<<<<<<<<<<<<<
 *             pysam_set_bin(self._delegate, bin)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_3bin_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_bin));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_3bin_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2832);

  /* "pysam/csamfile.pyx":2833
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 *             pysam_set_bin(self._delegate, bin)             # <<<<<<<<<<<<<<
 * 
 *     property rlen:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_bin(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/csamfile.pyx":2832
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):             # <<<<<<<<<<<<<<
 *             pysam_set_bin(self._delegate, bin)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.bin.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2842
 * 
 *         Returns 0 if not available."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.l_qseq
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4rlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4rlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4rlen___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4rlen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2842);

  /* "pysam/csamfile.pyx":2843
 *         Returns 0 if not available."""
 *         def __get__(self):
 *             return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     property aend:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2842
 * 
 *         Returns 0 if not available."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.l_qseq
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.rlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2850
 *         aend points to one past the last aligned residue.
 *         Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4aend_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4aend_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4aend___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4aend___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2850);

  /* "pysam/csamfile.pyx":2852
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2853
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_And(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2853; __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_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_5) {
    __pyx_t_6 = (pysam_get_n_cigar(__pyx_v_src) == 0);
    __pyx_t_7 = __pyx_t_6;
  } else {
    __pyx_t_7 = __pyx_t_5;
  }
  if (__pyx_t_7) {

    /* "pysam/csamfile.pyx":2854
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_endpos(src)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2855
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 *             return bam_endpos(src)             # <<<<<<<<<<<<<<
 * 
 *     property alen:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(bam_endpos(__pyx_v_src)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2850
 *         aend points to one past the last aligned residue.
 *         Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.aend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2861
 * 
 *         This is equal to `aend - pos`. Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4alen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4alen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4alen___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4alen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2861);

  /* "pysam/csamfile.pyx":2863
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":2864
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src) - \
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_And(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __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_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!__pyx_t_5) {
    __pyx_t_6 = (pysam_get_n_cigar(__pyx_v_src) == 0);
    __pyx_t_7 = __pyx_t_6;
  } else {
    __pyx_t_7 = __pyx_t_5;
  }
  if (__pyx_t_7) {

    /* "pysam/csamfile.pyx":2865
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_endpos(src) - \
 *                 self._delegate.core.pos
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":2866
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 *             return bam_endpos(src) - \             # <<<<<<<<<<<<<<
 *                 self._delegate.core.pos
 * 
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/csamfile.pyx":2867
 *                 return None
 *             return bam_endpos(src) - \
 *                 self._delegate.core.pos             # <<<<<<<<<<<<<<
 * 
 *     property mapq:
 */
  __pyx_t_4 = __Pyx_PyInt_From_int((bam_endpos(__pyx_v_src) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2861
 * 
 *         This is equal to `aend - pos`. Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.alen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2871
 *     property mapq:
 *         """mapping quality"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4mapq_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4mapq_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4mapq___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4mapq___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2871);

  /* "pysam/csamfile.pyx":2872
 *         """mapping quality"""
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, qual):
 *             pysam_set_qual(self._delegate, qual)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t(pysam_get_qual(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2871
 *     property mapq:
 *         """mapping quality"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mapq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2873
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             pysam_set_qual(self._delegate, qual)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4mapq_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_qual));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4mapq_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint8_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2873);

  /* "pysam/csamfile.pyx":2874
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 *             pysam_set_qual(self._delegate, qual)             # <<<<<<<<<<<<<<
 * 
 *     property mrnm:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint8_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_qual(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/csamfile.pyx":2873
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             pysam_set_qual(self._delegate, qual)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mapq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2880
 *         deprecated, use RNEXT instead.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mtid
 *         def __set__(self, mtid):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4mrnm_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4mrnm_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4mrnm___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4mrnm___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2880);

  /* "pysam/csamfile.pyx":2881
 *         """
 *         def __get__(self):
 *             return self._delegate.core.mtid             # <<<<<<<<<<<<<<
 *         def __set__(self, mtid):
 *             self._delegate.core.mtid = mtid
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2880
 *         deprecated, use RNEXT instead.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mtid
 *         def __set__(self, mtid):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mrnm.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2882
 *         def __get__(self):
 *             return self._delegate.core.mtid
 *         def __set__(self, mtid):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mtid = mtid
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4mrnm_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mtid));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4mrnm_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2882);

  /* "pysam/csamfile.pyx":2883
 *             return self._delegate.core.mtid
 *         def __set__(self, mtid):
 *             self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
 * 
 *     property rnext:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mtid = __pyx_t_1;

  /* "pysam/csamfile.pyx":2882
 *         def __get__(self):
 *             return self._delegate.core.mtid
 *         def __set__(self, mtid):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mtid = mtid
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mrnm.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2887
 *     property rnext:
 *         """the :term:`reference` id of the mate """
 *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
 *         def __set__(self, mtid): self._delegate.core.mtid = mtid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5rnext_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5rnext_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5rnext___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5rnext___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2887);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.rnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2888
 *         """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:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5rnext_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mtid));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5rnext_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2888);
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mtid = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.rnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2893
 *         """the position of the mate
 *         deprecated, use PNEXT instead."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4mpos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4mpos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4mpos___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4mpos___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2893);

  /* "pysam/csamfile.pyx":2894
 *         deprecated, use PNEXT instead."""
 *         def __get__(self):
 *             return self._delegate.core.mpos             # <<<<<<<<<<<<<<
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2893
 *         """the position of the mate
 *         deprecated, use PNEXT instead."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2895
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4mpos_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mpos));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4mpos_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2895);

  /* "pysam/csamfile.pyx":2896
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
 * 
 *     property pnext:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mpos = __pyx_t_1;

  /* "pysam/csamfile.pyx":2895
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mpos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2900
 *     property pnext:
 *         """the position of the mate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5pnext_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5pnext_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5pnext___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5pnext___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2900);

  /* "pysam/csamfile.pyx":2901
 *         """the position of the mate"""
 *         def __get__(self):
 *             return self._delegate.core.mpos             # <<<<<<<<<<<<<<
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2900
 *     property pnext:
 *         """the position of the mate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.pnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2902
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5pnext_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mpos));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5pnext_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2902);

  /* "pysam/csamfile.pyx":2903
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
 * 
 *     #######################################################################
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mpos = __pyx_t_1;

  /* "pysam/csamfile.pyx":2902
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.pnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2912
 *         """the insert size
 *         deprecated: use tlen instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5isize_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_5isize_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5isize___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_5isize___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2912);

  /* "pysam/csamfile.pyx":2913
 *         deprecated: use tlen instead"""
 *         def __get__(self):
 *             return self._delegate.core.isize             # <<<<<<<<<<<<<<
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2912
 *         """the insert size
 *         deprecated: use tlen instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.isize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2914
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 *     property tlen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_5isize_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_isize));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_5isize_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2914);

  /* "pysam/csamfile.pyx":2915
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
 *     property tlen:
 *         """the template length"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.isize = __pyx_t_1;

  /* "pysam/csamfile.pyx":2914
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 *     property tlen:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.isize.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2918
 *     property tlen:
 *         """the template length"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4tlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_4tlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4tlen___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_4tlen___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2918);

  /* "pysam/csamfile.pyx":2919
 *         """the template length"""
 *         def __get__(self):
 *             return self._delegate.core.isize             # <<<<<<<<<<<<<<
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2918
 *     property tlen:
 *         """the template length"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.tlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2920
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 *     property is_paired:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_4tlen_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_isize));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_4tlen_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2920);

  /* "pysam/csamfile.pyx":2921
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.isize = __pyx_t_1;

  /* "pysam/csamfile.pyx":2920
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 *     property is_paired:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.tlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2924
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_9is_paired_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_9is_paired_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_paired___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_9is_paired___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2924);

  /* "pysam/csamfile.pyx":2925
 *         """true if read is paired in sequencing"""
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPAIRED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2925; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2924
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_paired.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2926
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 *     property is_proper_pair:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_paired_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_paired_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2926);

  /* "pysam/csamfile.pyx":2927
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)             # <<<<<<<<<<<<<<
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPAIRED);

  /* "pysam/csamfile.pyx":2926
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 *     property is_proper_pair:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_paired.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2930
 *     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):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_14is_proper_pair_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_14is_proper_pair_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_14is_proper_pair___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_14is_proper_pair___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2930);

  /* "pysam/csamfile.pyx":2931
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPROPER_PAIR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2931; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2930
 *     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):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_proper_pair.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2932
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 *     property is_unmapped:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_14is_proper_pair_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2932);

  /* "pysam/csamfile.pyx":2933
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPROPER_PAIR);

  /* "pysam/csamfile.pyx":2932
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 *     property is_unmapped:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_proper_pair.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2936
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_11is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_11is_unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_11is_unmapped___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_11is_unmapped___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2936);

  /* "pysam/csamfile.pyx":2937
 *         """true if read itself is unmapped"""
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2937; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2936
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2938
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 *     property mate_is_unmapped:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_11is_unmapped_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_11is_unmapped_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2938);

  /* "pysam/csamfile.pyx":2939
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FUNMAP);

  /* "pysam/csamfile.pyx":2938
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 *     property mate_is_unmapped:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2942
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2942);

  /* "pysam/csamfile.pyx":2943
 *         """true if the mate is unmapped"""
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMUNMAP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2942
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mate_is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2944
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 *     property is_reverse:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2944);

  /* "pysam/csamfile.pyx":2945
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMUNMAP);

  /* "pysam/csamfile.pyx":2944
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 *     property is_reverse:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mate_is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2948
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_10is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_10is_reverse_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_10is_reverse___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_10is_reverse___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2948);

  /* "pysam/csamfile.pyx":2949
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREVERSE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2948
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2950
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 *     property mate_is_reverse:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_10is_reverse_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_10is_reverse_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2950);

  /* "pysam/csamfile.pyx":2951
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREVERSE);

  /* "pysam/csamfile.pyx":2950
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 *     property mate_is_reverse:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2954
 *     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):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_15mate_is_reverse___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_15mate_is_reverse___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2954);

  /* "pysam/csamfile.pyx":2955
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMREVERSE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2954
 *     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):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mate_is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2956
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 *     property is_read1:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2956);

  /* "pysam/csamfile.pyx":2957
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)             # <<<<<<<<<<<<<<
 *     property is_read1:
 *         """true if this is read1"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMREVERSE);

  /* "pysam/csamfile.pyx":2956
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 *     property is_read1:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.mate_is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2960
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read1_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read1_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read1___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read1___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2960);

  /* "pysam/csamfile.pyx":2961
 *         """true if this is read1"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2960
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_read1.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2962
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 *     property is_read2:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read1_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read1_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2962);

  /* "pysam/csamfile.pyx":2963
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)             # <<<<<<<<<<<<<<
 *     property is_read2:
 *         """true if this is read2"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD1);

  /* "pysam/csamfile.pyx":2962
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 *     property is_read2:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_read1.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2966
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read2_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read2_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read2___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read2___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2966);

  /* "pysam/csamfile.pyx":2967
 *         """true if this is read2"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2966
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_read2.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2968
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 *     property is_secondary:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read2_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_8is_read2_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2968);

  /* "pysam/csamfile.pyx":2969
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)             # <<<<<<<<<<<<<<
 *     property is_secondary:
 *         """true if not primary alignment"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2969; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD2);

  /* "pysam/csamfile.pyx":2968
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 *     property is_secondary:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_read2.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2972
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_12is_secondary_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_12is_secondary_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_secondary___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_12is_secondary___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2972);

  /* "pysam/csamfile.pyx":2973
 *         """true if not primary alignment"""
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSECONDARY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2973; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2972
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_secondary.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2974
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 *     property is_qcfail:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_secondary_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_secondary_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2974);

  /* "pysam/csamfile.pyx":2975
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)             # <<<<<<<<<<<<<<
 *     property is_qcfail:
 *         """true if QC failure"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSECONDARY);

  /* "pysam/csamfile.pyx":2974
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 *     property is_qcfail:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_secondary.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2978
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_9is_qcfail_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_9is_qcfail_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_qcfail___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_9is_qcfail___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2978);

  /* "pysam/csamfile.pyx":2979
 *         """true if QC failure"""
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FQCFAIL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2979; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2978
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_qcfail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2980
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 *     property is_duplicate:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_qcfail_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_9is_qcfail_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2980);

  /* "pysam/csamfile.pyx":2981
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)             # <<<<<<<<<<<<<<
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FQCFAIL);

  /* "pysam/csamfile.pyx":2980
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 *     property is_duplicate:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_qcfail.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2984
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_12is_duplicate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_12is_duplicate_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_duplicate___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_12is_duplicate___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2984);

  /* "pysam/csamfile.pyx":2985
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FDUP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2985; __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2984
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_duplicate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2986
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_duplicate_2__set__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11AlignedRead_12is_duplicate_2__set__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2986);

  /* "pysam/csamfile.pyx":2987
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)             # <<<<<<<<<<<<<<
 * 
 *     #######################################################################
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FDUP);

  /* "pysam/csamfile.pyx":2986
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.is_duplicate.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":2995
 *     property positions:
 *         """a list of reference positions that this read aligns to."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t k, i, pos
 *             cdef int op
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_9positions_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_9positions_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_9positions___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_9positions___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_i;
  uint32_t __pyx_v_pos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  uint32_t __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2995);

  /* "pysam/csamfile.pyx":3001
 *             cdef bam1_t * src
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src) == 0:
 *                 return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":3002
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return []
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":3003
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:
 *                 return []             # <<<<<<<<<<<<<<
 * 
 *             result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3003; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3005
 *                 return []
 * 
 *             result = []             # <<<<<<<<<<<<<<
 *             pos = src.core.pos
 *             cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":3006
 * 
 *             result = []
 *             pos = src.core.pos             # <<<<<<<<<<<<<<
 *             cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/csamfile.pyx":3007
 *             result = []
 *             pos = src.core.pos
 *             cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":3009
 *             cigar_p = pysam_bam_get_cigar(src)
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":3010
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 if op == BAM_CMATCH:
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/csamfile.pyx":3011
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 if op == BAM_CMATCH:
 *                     for i from pos <= i < pos + l:
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":3012
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append( i )
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":3013
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 if op == BAM_CMATCH:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append( i )
 * 
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/csamfile.pyx":3014
 *                 if op == BAM_CMATCH:
 *                     for i from pos <= i < pos + l:
 *                         result.append( i )             # <<<<<<<<<<<<<<
 * 
 *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysam/csamfile.pyx":3016
 *                         result.append( i )
 * 
 *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     pos += l
 * 
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_2) {
      __pyx_t_9 = ((__pyx_v_op == BAM_CDEL) != 0);
      if (!__pyx_t_9) {
        __pyx_t_10 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
        __pyx_t_11 = __pyx_t_10;
      } else {
        __pyx_t_11 = __pyx_t_9;
      }
      __pyx_t_9 = __pyx_t_11;
    } else {
      __pyx_t_9 = __pyx_t_2;
    }
    if (__pyx_t_9) {

      /* "pysam/csamfile.pyx":3017
 * 
 *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                     pos += l             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
      __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_pos = __pyx_t_7;
      goto __pyx_L9;
    }
    __pyx_L9:;
  }

  /* "pysam/csamfile.pyx":3019
 *                     pos += l
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     property inferred_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":2995
 *     property positions:
 *         """a list of reference positions that this read aligns to."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t k, i, pos
 *             cdef int op
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.positions.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3026
 *         Returns 0 if CIGAR string is not present.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *            cdef uint32_t k, qpos
 *            cdef int op
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_15inferred_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_15inferred_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_15inferred_length___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_15inferred_length___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_qpos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  uint16_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3026);

  /* "pysam/csamfile.pyx":3032
 *            cdef bam1_t * src
 * 
 *            src = self._delegate             # <<<<<<<<<<<<<<
 *            if pysam_get_n_cigar(src) == 0: return 0
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":3033
 * 
 *            src = self._delegate
 *            if pysam_get_n_cigar(src) == 0: return 0             # <<<<<<<<<<<<<<
 * 
 *            qpos = 0
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3035
 *            if pysam_get_n_cigar(src) == 0: return 0
 * 
 *            qpos = 0             # <<<<<<<<<<<<<<
 *            cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_v_qpos = 0;

  /* "pysam/csamfile.pyx":3036
 * 
 *            qpos = 0
 *            cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *            for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":3038
 *            cigar_p = pysam_bam_get_cigar(src)
 * 
 *            for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 */
  __pyx_t_3 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":3039
 * 
 *            for k from 0 <= k < pysam_get_n_cigar(src):
 *                op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 * 
 *                if op == BAM_CMATCH or op == BAM_CINS or \
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/csamfile.pyx":3041
 *                op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 *                if op == BAM_CMATCH or op == BAM_CINS or \             # <<<<<<<<<<<<<<
 *                   op == BAM_CSOFT_CLIP or \
 *                   op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_2) {
      __pyx_t_4 = ((__pyx_v_op == BAM_CINS) != 0);
      if (!__pyx_t_4) {

        /* "pysam/csamfile.pyx":3042
 * 
 *                if op == BAM_CMATCH or op == BAM_CINS or \
 *                   op == BAM_CSOFT_CLIP or \             # <<<<<<<<<<<<<<
 *                   op == BAM_CEQUAL or op == BAM_CDIFF:
 *                    qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
        __pyx_t_5 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
        if (!__pyx_t_5) {

          /* "pysam/csamfile.pyx":3043
 *                if op == BAM_CMATCH or op == BAM_CINS or \
 *                   op == BAM_CSOFT_CLIP or \
 *                   op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                    qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
          __pyx_t_6 = ((__pyx_v_op == BAM_CEQUAL) != 0);
          if (!__pyx_t_6) {
            __pyx_t_7 = ((__pyx_v_op == BAM_CDIFF) != 0);
            __pyx_t_8 = __pyx_t_7;
          } else {
            __pyx_t_8 = __pyx_t_6;
          }
          __pyx_t_6 = __pyx_t_8;
        } else {
          __pyx_t_6 = __pyx_t_5;
        }
        __pyx_t_5 = __pyx_t_6;
      } else {
        __pyx_t_5 = __pyx_t_4;
      }
      __pyx_t_4 = __pyx_t_5;
    } else {
      __pyx_t_4 = __pyx_t_2;
    }
    if (__pyx_t_4) {

      /* "pysam/csamfile.pyx":3044
 *                   op == BAM_CSOFT_CLIP or \
 *                   op == BAM_CEQUAL or op == BAM_CDIFF:
 *                    qpos += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *            return qpos
 */
      __pyx_v_qpos = (__pyx_v_qpos + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysam/csamfile.pyx":3046
 *                    qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *            return qpos             # <<<<<<<<<<<<<<
 * 
 *     property aligned_pairs:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3026
 *         Returns 0 if CIGAR string is not present.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *            cdef uint32_t k, qpos
 *            cdef int op
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.inferred_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3053
 *         Unaligned position are marked by None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t k, i, pos, qpos
 *             cdef int op
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_13aligned_pairs_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_13aligned_pairs_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_13aligned_pairs___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_13aligned_pairs___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_i;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_qpos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  uint32_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3053);

  /* "pysam/csamfile.pyx":3059
 *             cdef bam1_t * src
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src) == 0:
 *                 return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":3060
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return []
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":3061
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:
 *                 return []             # <<<<<<<<<<<<<<
 * 
 *             result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3063
 *                 return []
 * 
 *             result = []             # <<<<<<<<<<<<<<
 *             pos = src.core.pos
 *             qpos = 0
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":3064
 * 
 *             result = []
 *             pos = src.core.pos             # <<<<<<<<<<<<<<
 *             qpos = 0
 *             cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/csamfile.pyx":3065
 *             result = []
 *             pos = src.core.pos
 *             qpos = 0             # <<<<<<<<<<<<<<
 *             cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_v_qpos = 0;

  /* "pysam/csamfile.pyx":3066
 *             pos = src.core.pos
 *             qpos = 0
 *             cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":3068
 *             cigar_p = pysam_bam_get_cigar(src)
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":3069
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/csamfile.pyx":3070
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *                 if op == BAM_CMATCH:
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":3072
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append( (qpos, i) )
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":3073
 * 
 *                 if op == BAM_CMATCH:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append( (qpos, i) )
 *                         qpos += 1
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/csamfile.pyx":3074
 *                 if op == BAM_CMATCH:
 *                     for i from pos <= i < pos + l:
 *                         result.append( (qpos, i) )             # <<<<<<<<<<<<<<
 *                         qpos += 1
 *                     pos += l
 */
        __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3074; __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);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_3);
        __pyx_t_6 = 0;
        __pyx_t_3 = 0;
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pysam/csamfile.pyx":3075
 *                     for i from pos <= i < pos + l:
 *                         result.append( (qpos, i) )
 *                         qpos += 1             # <<<<<<<<<<<<<<
 *                     pos += l
 * 
 */
        __pyx_v_qpos = (__pyx_v_qpos + 1);
      }

      /* "pysam/csamfile.pyx":3076
 *                         result.append( (qpos, i) )
 *                         qpos += 1
 *                     pos += l             # <<<<<<<<<<<<<<
 * 
 *                 elif op == BAM_CINS:
 */
      __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3076; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_pos = __pyx_t_7;
      goto __pyx_L6;
    }

    /* "pysam/csamfile.pyx":3078
 *                     pos += l
 * 
 *                 elif op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append( (qpos, None) )
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CINS) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":3079
 * 
 *                 elif op == BAM_CINS:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append( (qpos, None) )
 *                         qpos += 1
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/csamfile.pyx":3080
 *                 elif op == BAM_CINS:
 *                     for i from pos <= i < pos + l:
 *                         result.append( (qpos, None) )             # <<<<<<<<<<<<<<
 *                         qpos += 1
 * 
 */
        __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        __Pyx_INCREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_3, 1, Py_None);
        __Pyx_GIVEREF(Py_None);
        __pyx_t_8 = 0;
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pysam/csamfile.pyx":3081
 *                     for i from pos <= i < pos + l:
 *                         result.append( (qpos, None) )
 *                         qpos += 1             # <<<<<<<<<<<<<<
 * 
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_v_qpos = (__pyx_v_qpos + 1);
      }
      goto __pyx_L6;
    }

    /* "pysam/csamfile.pyx":3083
 *                         qpos += 1
 * 
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append( (None, i) )
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_2) {
      __pyx_t_10 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
      __pyx_t_11 = __pyx_t_10;
    } else {
      __pyx_t_11 = __pyx_t_2;
    }
    if (__pyx_t_11) {

      /* "pysam/csamfile.pyx":3084
 * 
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append( (None, i) )
 *                     pos += l
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/csamfile.pyx":3085
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                     for i from pos <= i < pos + l:
 *                         result.append( (None, i) )             # <<<<<<<<<<<<<<
 *                     pos += l
 * 
 */
        __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None);
        __Pyx_GIVEREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }

      /* "pysam/csamfile.pyx":3086
 *                     for i from pos <= i < pos + l:
 *                         result.append( (None, i) )
 *                     pos += l             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_v_pos = __pyx_t_7;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysam/csamfile.pyx":3088
 *                     pos += l
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     property blocks:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3053
 *         Unaligned position are marked by None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t k, i, pos, qpos
 *             cdef int op
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.aligned_pairs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3103
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t k, pos, l
 *             cdef int op
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_6blocks_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_6blocks_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_6blocks___get__(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_6blocks___get__(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_l;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3103);

  /* "pysam/csamfile.pyx":3109
 *             cdef bam1_t * src
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src) == 0:
 *                 return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":3110
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return []
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":3111
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:
 *                 return []             # <<<<<<<<<<<<<<
 * 
 *             result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3113
 *                 return []
 * 
 *             result = []             # <<<<<<<<<<<<<<
 *             pos = src.core.pos
 *             cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":3114
 * 
 *             result = []
 *             pos = src.core.pos             # <<<<<<<<<<<<<<
 *             cigar_p = pysam_bam_get_cigar(src)
 *             l = 0
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/csamfile.pyx":3115
 *             result = []
 *             pos = src.core.pos
 *             cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *             l = 0
 * 
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":3116
 *             pos = src.core.pos
 *             cigar_p = pysam_bam_get_cigar(src)
 *             l = 0             # <<<<<<<<<<<<<<
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_l = 0;

  /* "pysam/csamfile.pyx":3118
 *             l = 0
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":3119
 * 
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 if op == BAM_CMATCH:
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/csamfile.pyx":3120
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 if op == BAM_CMATCH:
 *                     result.append((pos, pos + l))
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/csamfile.pyx":3121
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                     result.append((pos, pos + l))
 *                     pos += l
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":3122
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 if op == BAM_CMATCH:
 *                     result.append((pos, pos + l))             # <<<<<<<<<<<<<<
 *                     pos += l
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_pos + __pyx_v_l)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_3 = 0;
      __pyx_t_6 = 0;
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/csamfile.pyx":3123
 *                 if op == BAM_CMATCH:
 *                     result.append((pos, pos + l))
 *                     pos += l             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                     pos += l
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);
      goto __pyx_L6;
    }

    /* "pysam/csamfile.pyx":3124
 *                     result.append((pos, pos + l))
 *                     pos += l
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     pos += l
 * 
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_2) {
      __pyx_t_9 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
      __pyx_t_10 = __pyx_t_9;
    } else {
      __pyx_t_10 = __pyx_t_2;
    }
    if (__pyx_t_10) {

      /* "pysam/csamfile.pyx":3125
 *                     pos += l
 *                 elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                     pos += l             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysam/csamfile.pyx":3127
 *                     pos += l
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     #######################################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3103
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t k, pos, l
 *             cdef int op
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.blocks.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3133
 *     ##
 *     #######################################################################
 *     def overlap( self, uint32_t start, uint32_t end ):             # <<<<<<<<<<<<<<
 *         """return number of aligned bases of read overlapping the interval *start* and *end*
 *         on the reference sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_15overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_14overlap[] = "AlignedRead.overlap(self, uint32_t start, uint32_t end)\nreturn number of aligned bases of read overlapping the interval *start* and *end*\n        on the reference sequence.\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_15overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlap (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_end,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_start == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_As_uint32_t(values[1]); if (unlikely((__pyx_v_end == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3133; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_14overlap(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), __pyx_v_start, __pyx_v_end);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_14overlap(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_overlap;
  int __pyx_v_op;
  int __pyx_v_o;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  uint16_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  uint32_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  uint32_t __pyx_t_10;
  uint32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("overlap", 0);
  __Pyx_TraceCall("overlap", __pyx_f[0], 3133);

  /* "pysam/csamfile.pyx":3142
 *         cdef bam1_t * src
 * 
 *         overlap = 0             # <<<<<<<<<<<<<<
 * 
 *         src = self._delegate
 */
  __pyx_v_overlap = 0;

  /* "pysam/csamfile.pyx":3144
 *         overlap = 0
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return 0
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/csamfile.pyx":3145
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return 0
 *         pos = src.core.pos
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":3146
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return 0             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         o = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3147
 *         if pysam_get_n_cigar(src) == 0:
 *             return 0
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         o = 0
 * 
 */
  __pyx_t_3 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_3;

  /* "pysam/csamfile.pyx":3148
 *             return 0
 *         pos = src.core.pos
 *         o = 0             # <<<<<<<<<<<<<<
 * 
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_v_o = 0;

  /* "pysam/csamfile.pyx":3150
 *         o = 0
 * 
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/csamfile.pyx":3151
 * 
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/csamfile.pyx":3152
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/csamfile.pyx":3153
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH:
 */
    __pyx_t_5 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/csamfile.pyx":3155
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/csamfile.pyx":3156
 * 
 *             if op == BAM_CMATCH:
 *                 o = min( pos + l, end) - max( pos, start )             # <<<<<<<<<<<<<<
 *                 if o > 0: overlap += o
 * 
 */
      __pyx_t_6 = __pyx_v_end;
      __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_5 = __pyx_t_9;
        __pyx_t_9 = 0;
      } else {
        __Pyx_INCREF(__pyx_t_7);
        __pyx_t_5 = __pyx_t_7;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_6 = __pyx_v_start;
      __pyx_t_10 = __pyx_v_pos;
      if (((__pyx_t_6 > __pyx_t_10) != 0)) {
        __pyx_t_11 = __pyx_t_6;
      } else {
        __pyx_t_11 = __pyx_t_10;
      }
      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_o = __pyx_t_12;

      /* "pysam/csamfile.pyx":3157
 *             if op == BAM_CMATCH:
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      __pyx_t_2 = ((__pyx_v_o > 0) != 0);
      if (__pyx_t_2) {
        __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o);
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysam/csamfile.pyx":3159
 *                 if o > 0: overlap += o
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_2) {
      __pyx_t_13 = ((__pyx_v_op == BAM_CDEL) != 0);
      if (!__pyx_t_13) {
        __pyx_t_14 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
        __pyx_t_15 = __pyx_t_14;
      } else {
        __pyx_t_15 = __pyx_t_13;
      }
      __pyx_t_13 = __pyx_t_15;
    } else {
      __pyx_t_13 = __pyx_t_2;
    }
    if (__pyx_t_13) {

      /* "pysam/csamfile.pyx":3160
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return overlap
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_11 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_pos = __pyx_t_11;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "pysam/csamfile.pyx":3162
 *                 pos += l
 * 
 *         return overlap             # <<<<<<<<<<<<<<
 * 
 *     def opt(self, tag):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3133
 *     ##
 *     #######################################################################
 *     def overlap( self, uint32_t start, uint32_t end ):             # <<<<<<<<<<<<<<
 *         """return number of aligned bases of read overlapping the interval *start* and *end*
 *         on the reference sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3164
 *         return overlap
 * 
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         """retrieves optional data given a two-letter *tag*"""
 *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_17opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_16opt[] = "AlignedRead.opt(self, tag)\nretrieves optional data given a two-letter *tag*";
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_17opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("opt (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_16opt(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tag));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_16opt(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag) {
  uint8_t *__pyx_v_v;
  CYTHON_UNUSED int __pyx_v_nvalues;
  PyObject *__pyx_v_btag = NULL;
  PyObject *__pyx_v_auxtype = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_bytesize = NULL;
  PyObject *__pyx_v_values = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char const *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("opt", 0);
  __Pyx_TraceCall("opt", __pyx_f[0], 3164);

  /* "pysam/csamfile.pyx":3169
 *         cdef uint8_t * v
 *         cdef int nvalues
 *         btag = _forceBytes(tag)             # <<<<<<<<<<<<<<
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 */
  __pyx_t_1 = __pyx_f_5pysam_8csamfile__forceBytes(__pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_btag = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3170
 *         cdef int nvalues
 *         btag = _forceBytes(tag)
 *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 *         auxtype = chr(v[0])
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_2);

  /* "pysam/csamfile.pyx":3171
 *         btag = _forceBytes(tag)
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )             # <<<<<<<<<<<<<<
 *         auxtype = chr(v[0])
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 */
  __pyx_t_3 = ((__pyx_v_v == NULL) != 0);
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_tag_s_not_present, __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3171; __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 = 3171; __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 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":3172
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 *         auxtype = chr(v[0])             # <<<<<<<<<<<<<<
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             return <int>bam_aux2i(v)
 */
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __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 = 3172; __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 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_auxtype = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3173
 *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
 *         auxtype = chr(v[0])
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':             # <<<<<<<<<<<<<<
 *             return <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 */
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_3) {
    __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_5) {
      __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_s_2, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (!__pyx_t_6) {
        __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_S, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_8 = __pyx_t_7;
      } else {
        __pyx_t_8 = __pyx_t_6;
      }
      __pyx_t_6 = __pyx_t_8;
    } else {
      __pyx_t_6 = __pyx_t_5;
    }
    __pyx_t_5 = __pyx_t_6;
  } else {
    __pyx_t_5 = __pyx_t_3;
  }
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":3174
 *         auxtype = chr(v[0])
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             return <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'i' or auxtype == 'I':
 *             return <int32_t>bam_aux2i(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3175
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             return <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':             # <<<<<<<<<<<<<<
 *             return <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 */
  __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_5) {
    __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_I, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = __pyx_t_3;
  } else {
    __pyx_t_6 = __pyx_t_5;
  }
  if (__pyx_t_6) {

    /* "pysam/csamfile.pyx":3176
 *             return <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 *             return <int32_t>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'f' or auxtype == 'F':
 *             return <float>bam_aux2f(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3177
 *         elif auxtype == 'i' or auxtype == 'I':
 *             return <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':             # <<<<<<<<<<<<<<
 *             return <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 */
  __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_6) {
    __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_F, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = __pyx_t_5;
  } else {
    __pyx_t_3 = __pyx_t_6;
  }
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":3178
 *             return <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 *             return <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'd' or auxtype == 'D':
 *             return <double>bam_aux2f(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3179
 *         elif auxtype == 'f' or auxtype == 'F':
 *             return <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':             # <<<<<<<<<<<<<<
 *             return <double>bam_aux2f(v)
 *         elif auxtype == 'A':
 */
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_d, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_3) {
    __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_D, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __pyx_t_6;
  } else {
    __pyx_t_5 = __pyx_t_3;
  }
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":3180
 *             return <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 *             return <double>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'A':
 *             # there might a more efficient way
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3181
 *         elif auxtype == 'd' or auxtype == 'D':
 *             return <double>bam_aux2f(v)
 *         elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *             # there might a more efficient way
 *             # to convert a char into a string
 */
  __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":3184
 *             # there might a more efficient way
 *             # to convert a char into a string
 *             return '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'Z':
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3185
 *             # to convert a char into a string
 *             return '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':             # <<<<<<<<<<<<<<
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype == 'B':
 */
  __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_Z, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":3186
 *             return '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':
 *             return _charptr_to_str(<char*>bam_aux2Z(v))             # <<<<<<<<<<<<<<
 *         elif auxtype == 'B':
 *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __pyx_f_5pysam_8csamfile__charptr_to_str(((char *)bam_aux2Z(__pyx_v_v))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "pysam/csamfile.pyx":3187
 *         elif auxtype == 'Z':
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
 *             return values
 */
  __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_5) {

    /* "pysam/csamfile.pyx":3188
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype == 'B':
 *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )             # <<<<<<<<<<<<<<
 *             return values
 *         else:
 */
    __pyx_t_4 = __pyx_f_5pysam_8csamfile_convertBinaryTagToList((__pyx_v_v + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_10 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_10);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_11 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_10);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_12 = NULL;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_12 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L6_unpacking_done:;
    }
    __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_bytesize = __pyx_t_1;
    __pyx_t_1 = 0;
    __pyx_v_nvalues = __pyx_t_13;
    __pyx_v_values = __pyx_t_10;
    __pyx_t_10 = 0;

    /* "pysam/csamfile.pyx":3189
 *         elif auxtype == 'B':
 *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
 *             return values             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("unknown auxilliary type '%s'" % auxtype)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_values);
    __pyx_r = __pyx_v_values;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":3191
 *             return values
 *         else:
 *             raise ValueError("unknown auxilliary type '%s'" % auxtype)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unknown_auxilliary_type_s, __pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":3164
 *         return overlap
 * 
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         """retrieves optional data given a two-letter *tag*"""
 *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.csamfile.AlignedRead.opt", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_btag);
  __Pyx_XDECREF(__pyx_v_auxtype);
  __Pyx_XDECREF(__pyx_v_bytesize);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3194
 * 
 * 
 *     def fancy_str (self):             # <<<<<<<<<<<<<<
 *         """returns list of fieldnames/values in pretty format for debugging.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_19fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_11AlignedRead_18fancy_str[] = "AlignedRead.fancy_str(self)\nreturns list of fieldnames/values in pretty format for debugging.\n\n        ";
static PyObject *__pyx_pw_5pysam_8csamfile_11AlignedRead_19fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fancy_str (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11AlignedRead_18fancy_str(((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11AlignedRead_18fancy_str(struct __pyx_obj_5pysam_8csamfile_AlignedRead *__pyx_v_self) {
  PyObject *__pyx_v_ret_string = NULL;
  PyObject *__pyx_v_field_names = NULL;
  PyObject *__pyx_v_fields_names_in_order = NULL;
  PyObject *__pyx_v_f = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("fancy_str", 0);
  __Pyx_TraceCall("fancy_str", __pyx_f[0], 3194);

  /* "pysam/csamfile.pyx":3198
 * 
 *         """
 *         ret_string = []             # <<<<<<<<<<<<<<
 * 
 *         # Originally written by Leo. Note that not all of these fields
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_ret_string = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3202
 *         # Originally written by Leo. Note that not all of these fields
 *         # exist. Deprecate?
 *         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 = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_tid, __pyx_kp_s_Contig_index) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_kp_s_Mapped_position_on_contig) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mtid, __pyx_kp_s_Contig_index_for_mate_pair) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_mpos, __pyx_kp_s_Position_of_mate_pair) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_isize, __pyx_kp_s_Insert_size) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_flag, __pyx_kp_s_Binary_flag) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_n_cigar, __pyx_kp_s_Count_of_cigar_entries) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_cigar, __pyx_kp_s_Cigar_entries) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_qual, __pyx_kp_s_Mapping_quality) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_bin, __pyx_kp_s_Bam_index_bin_number) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_l_qname, __pyx_kp_s_Length_of_query_name) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_qname, __pyx_kp_s_Query_name) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_l_qseq, __pyx_kp_s_Length_of_query_sequence) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_qseq, __pyx_kp_s_Query_sequence) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_bqual, __pyx_kp_s_Quality_scores) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_l_data, __pyx_kp_s_Length_of_auxilary_data) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_m_data, __pyx_kp_s_Maximum_data_length) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_field_names = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3221
 *            "m_data":        "Maximum 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_data", "m_data"]
 */
  __pyx_t_1 = PyList_New(17); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_tid);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_tid);
  __Pyx_GIVEREF(__pyx_n_s_tid);
  __Pyx_INCREF(__pyx_n_s_pos);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_pos);
  __Pyx_GIVEREF(__pyx_n_s_pos);
  __Pyx_INCREF(__pyx_n_s_mtid);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_mtid);
  __Pyx_GIVEREF(__pyx_n_s_mtid);
  __Pyx_INCREF(__pyx_n_s_mpos);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_mpos);
  __Pyx_GIVEREF(__pyx_n_s_mpos);
  __Pyx_INCREF(__pyx_n_s_isize);
  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_isize);
  __Pyx_GIVEREF(__pyx_n_s_isize);
  __Pyx_INCREF(__pyx_n_s_flag);
  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_flag);
  __Pyx_GIVEREF(__pyx_n_s_flag);
  __Pyx_INCREF(__pyx_n_s_n_cigar);
  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_s_n_cigar);
  __Pyx_GIVEREF(__pyx_n_s_n_cigar);
  __Pyx_INCREF(__pyx_n_s_cigar);
  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_s_cigar);
  __Pyx_GIVEREF(__pyx_n_s_cigar);
  __Pyx_INCREF(__pyx_n_s_qual);
  PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_s_qual);
  __Pyx_GIVEREF(__pyx_n_s_qual);
  __Pyx_INCREF(__pyx_n_s_bin);
  PyList_SET_ITEM(__pyx_t_1, 9, __pyx_n_s_bin);
  __Pyx_GIVEREF(__pyx_n_s_bin);
  __Pyx_INCREF(__pyx_n_s_l_qname);
  PyList_SET_ITEM(__pyx_t_1, 10, __pyx_n_s_l_qname);
  __Pyx_GIVEREF(__pyx_n_s_l_qname);
  __Pyx_INCREF(__pyx_n_s_qname);
  PyList_SET_ITEM(__pyx_t_1, 11, __pyx_n_s_qname);
  __Pyx_GIVEREF(__pyx_n_s_qname);
  __Pyx_INCREF(__pyx_n_s_l_qseq);
  PyList_SET_ITEM(__pyx_t_1, 12, __pyx_n_s_l_qseq);
  __Pyx_GIVEREF(__pyx_n_s_l_qseq);
  __Pyx_INCREF(__pyx_n_s_qseq);
  PyList_SET_ITEM(__pyx_t_1, 13, __pyx_n_s_qseq);
  __Pyx_GIVEREF(__pyx_n_s_qseq);
  __Pyx_INCREF(__pyx_n_s_bqual);
  PyList_SET_ITEM(__pyx_t_1, 14, __pyx_n_s_bqual);
  __Pyx_GIVEREF(__pyx_n_s_bqual);
  __Pyx_INCREF(__pyx_n_s_l_data);
  PyList_SET_ITEM(__pyx_t_1, 15, __pyx_n_s_l_data);
  __Pyx_GIVEREF(__pyx_n_s_l_data);
  __Pyx_INCREF(__pyx_n_s_m_data);
  PyList_SET_ITEM(__pyx_t_1, 16, __pyx_n_s_m_data);
  __Pyx_GIVEREF(__pyx_n_s_m_data);
  __pyx_v_fields_names_in_order = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3225
 *                                  "l_qseq", "qseq", "bqual", "l_data", "m_data"]
 * 
 *         for f in fields_names_in_order:             # <<<<<<<<<<<<<<
 *             if f not in dir(self):
 *                 continue
 */
  __pyx_t_1 = __pyx_v_fields_names_in_order; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/csamfile.pyx":3226
 * 
 *         for f in fields_names_in_order:
 *             if f not in dir(self):             # <<<<<<<<<<<<<<
 *                 continue
 *             ret_string.append("%-30s %-10s= %s" %
 */
    __pyx_t_3 = PyObject_Dir(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = (__Pyx_PySequence_Contains(__pyx_v_f, __pyx_t_3, Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {

      /* "pysam/csamfile.pyx":3227
 *         for f in fields_names_in_order:
 *             if f not in dir(self):
 *                 continue             # <<<<<<<<<<<<<<
 *             ret_string.append("%-30s %-10s= %s" %
 *                               (field_names[f],
 */
      goto __pyx_L3_continue;
    }

    /* "pysam/csamfile.pyx":3229
 *                 continue
 *             ret_string.append("%-30s %-10s= %s" %
 *                               (field_names[f],             # <<<<<<<<<<<<<<
 *                                "(" + f + ")",
 *                                self.__getattribute__(f)))
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_field_names, __pyx_v_f); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3229; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/csamfile.pyx":3230
 *             ret_string.append("%-30s %-10s= %s" %
 *                               (field_names[f],
 *                                "(" + f + ")",             # <<<<<<<<<<<<<<
 *                                self.__getattribute__(f)))
 * 
 */
    __pyx_t_6 = PyNumber_Add(__pyx_kp_s__79, __pyx_v_f); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_kp_s__80); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/csamfile.pyx":3231
 *                               (field_names[f],
 *                                "(" + f + ")",
 *                                self.__getattribute__(f)))             # <<<<<<<<<<<<<<
 * 
 *         return ret_string
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getattribute); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __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 = 3231; __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 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3231; __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;

    /* "pysam/csamfile.pyx":3229
 *                 continue
 *             ret_string.append("%-30s %-10s= %s" %
 *                               (field_names[f],             # <<<<<<<<<<<<<<
 *                                "(" + f + ")",
 *                                self.__getattribute__(f)))
 */
    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3229; __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;

    /* "pysam/csamfile.pyx":3228
 *             if f not in dir(self):
 *                 continue
 *             ret_string.append("%-30s %-10s= %s" %             # <<<<<<<<<<<<<<
 *                               (field_names[f],
 *                                "(" + f + ")",
 */
    __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_30s_10s_s, __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_ret_string, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3233
 *                                self.__getattribute__(f)))
 * 
 *         return ret_string             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupProxy:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret_string);
  __pyx_r = __pyx_v_ret_string;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3194
 * 
 * 
 *     def fancy_str (self):             # <<<<<<<<<<<<<<
 *         """returns list of fieldnames/values in pretty format for debugging.
 * 
 */

  /* function exit code */
  __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("pysam.csamfile.AlignedRead.fancy_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ret_string);
  __Pyx_XDECREF(__pyx_v_field_names);
  __Pyx_XDECREF(__pyx_v_fields_names_in_order);
  __Pyx_XDECREF(__pyx_v_f);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3252
 *     will change.
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11PileupProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11PileupProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 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, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy___init__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11PileupProxy___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 3252);

  /* "pysam/csamfile.pyx":3253
 *     '''
 *     def __init__(self):
 *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__81, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":3252
 *     will change.
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupProxy.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3255
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_3__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_3__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy_2__str__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_2__str__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 3255);

  /* "pysam/csamfile.pyx":3256
 * 
 *     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);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __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);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __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_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":3258
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\
 *             "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
 * 
 *     property tid:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pileups); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__4, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":3257
 *     def __str__(self):
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\             # <<<<<<<<<<<<<<
 *             "\n".join( map(str, self.pileups) )
 * 
 */
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3257; __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_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3255
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
 *             "\n" +\
 */

  /* function exit code */
  __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("pysam.csamfile.PileupProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3262
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self): return self.tid             # <<<<<<<<<<<<<<
 * 
 *     property n:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy_3tid___get__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_3tid___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3262);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupProxy.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3266
 *     property n:
 *         '''number of reads mapping to this column.'''
 *         def __get__(self): return self.n_pu             # <<<<<<<<<<<<<<
 *         def __set__(self, n): self.n_pu = n
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_1n_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_1n_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy_1n___get__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_1n___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3266);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupProxy.n.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3267
 *         '''number of reads mapping to this column.'''
 *         def __get__(self): return self.n_pu
 *         def __set__(self, n): self.n_pu = n             # <<<<<<<<<<<<<<
 * 
 *     property pos:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_11PileupProxy_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
static int __pyx_pw_5pysam_8csamfile_11PileupProxy_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy_1n_2__set__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self), ((PyObject *)__pyx_v_n));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_11PileupProxy_1n_2__set__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3267);
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->n_pu = __pyx_t_1;

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.PileupProxy.n.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3270
 * 
 *     property pos:
 *         def __get__(self): return self.pos             # <<<<<<<<<<<<<<
 * 
 *     property pileups:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy_3pos___get__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_3pos___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3270);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupProxy.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3274
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_7pileups_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_11PileupProxy_7pileups_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_11PileupProxy_7pileups___get__(((struct __pyx_obj_5pysam_8csamfile_PileupProxy *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_11PileupProxy_7pileups___get__(struct __pyx_obj_5pysam_8csamfile_PileupProxy *__pyx_v_self) {
  int __pyx_v_x;
  PyObject *__pyx_v_pileups = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3274);

  /* "pysam/csamfile.pyx":3276
 *         def __get__(self):
 *             cdef int x
 *             pileups = []             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_pileups = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":3278
 *             pileups = []
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError("PileupProxy accessed after iterator finished")
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->plp == NULL) != 0);
  if (!__pyx_t_2) {
    __pyx_t_3 = (((__pyx_v_self->plp[0]) == NULL) != 0);
    __pyx_t_4 = __pyx_t_3;
  } else {
    __pyx_t_4 = __pyx_t_2;
  }
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":3279
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 *                 raise ValueError("PileupProxy accessed after iterator finished")             # <<<<<<<<<<<<<<
 * 
 *             # warning: there could be problems if self.n and self.buf are
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__82, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":3283
 *             # 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[0][x])))
 *             return pileups
 */
  __pyx_t_5 = __pyx_v_self->n_pu;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {

    /* "pysam/csamfile.pyx":3284
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append(makePileupRead(&(self.plp[0][x])))             # <<<<<<<<<<<<<<
 *             return pileups
 * 
 */
    __pyx_t_1 = __pyx_f_5pysam_8csamfile_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_pileups, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/csamfile.pyx":3285
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append(makePileupRead(&(self.plp[0][x])))
 *             return pileups             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupRead:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_pileups);
  __pyx_r = __pyx_v_pileups;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3274
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupProxy.pileups.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pileups);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3291
 *     '''
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 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, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead___init__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 3291);

  /* "pysam/csamfile.pyx":3292
 * 
 *     def __init__(self):
 *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":3291
 *     '''
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3294
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 *     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 ) ) )
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_3__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_3__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_2__str__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_2__str__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 3294);

  /* "pysam/csamfile.pyx":3295
 * 
 *     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 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_qpos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_indel); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_level); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_head); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_tail); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyTuple_New(7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __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_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __pyx_t_1 = 0;
  __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_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3294
 *         raise TypeError("This class cannot be instantiated from Python")
 * 
 *     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 ) ) )
 * 
 */

  /* function exit code */
  __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_AddTraceback("pysam.csamfile.PileupRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3299
 *     property alignment:
 *         """a :class:`pysam.AlignedRead` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 *     property qpos:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_9alignment___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3299);

  /* "pysam/csamfile.pyx":3300
 *         """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 *)__pyx_v_self->_alignment));
  __pyx_r = ((PyObject *)__pyx_v_self->_alignment);
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3299
 *     property alignment:
 *         """a :class:`pysam.AlignedRead` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 *     property qpos:
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3303
 *     property qpos:
 *         """position of the read base at the pileup site, 0-based"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._qpos
 *     property indel:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_4qpos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_4qpos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_4qpos___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_4qpos___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3303);

  /* "pysam/csamfile.pyx":3304
 *         """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_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3303
 *     property qpos:
 *         """position of the read base at the pileup site, 0-based"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._qpos
 *     property indel:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.qpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3307
 *     property indel:
 *         """indel length; 0 for no indel, positive for ins and negative for del"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 *     property is_del:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_5indel___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3307);

  /* "pysam/csamfile.pyx":3308
 *         """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 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3307
 *     property indel:
 *         """indel length; 0 for no indel, positive for ins and negative for del"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 *     property is_del:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.indel.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3311
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 *     property is_head:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_6is_del___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3311);

  /* "pysam/csamfile.pyx":3312
 *         """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_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3311
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 *     property is_head:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.is_del.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3314
 *             return self._is_del
 *     property is_head:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 *     property is_tail:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_7is_head___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3314);

  /* "pysam/csamfile.pyx":3315
 *     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_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3314
 *             return self._is_del
 *     property is_head:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 *     property is_tail:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.is_head.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3317
 *             return self._is_head
 *     property is_tail:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 *     property level:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_7is_tail___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3317);

  /* "pysam/csamfile.pyx":3318
 *     property is_tail:
 *         def __get__(self):
 *             return self._is_tail             # <<<<<<<<<<<<<<
 *     property level:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3317
 *             return self._is_head
 *     property is_tail:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 *     property level:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.is_tail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3320
 *             return self._is_tail
 *     property level:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_5level_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_10PileupRead_5level_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_10PileupRead_5level___get__(((struct __pyx_obj_5pysam_8csamfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_10PileupRead_5level___get__(struct __pyx_obj_5pysam_8csamfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3320);

  /* "pysam/csamfile.pyx":3321
 *     property level:
 *         def __get__(self):
 *             return self._level             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3320
 *             return self._is_tail
 *     property level:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.PileupRead.level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3337
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_3tid___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3337);

  /* "pysam/csamfile.pyx":3338
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):
 *             return self._tid             # <<<<<<<<<<<<<<
 * 
 *     property pos:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3337
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._tid
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3342
 *     property pos:
 *        '''nucleotide position of SNP.'''
 *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
 * 
 *     property reference_base:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_3pos___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3342);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3346
 *     property reference_base:
 *        '''reference base at pos. ``N`` if no reference sequence supplied.'''
 *        def __get__(self): return from_string_and_size( &self._reference_base, 1 )             # <<<<<<<<<<<<<<
 * 
 *     property genotype:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_14reference_base___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3346);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_8csamfile_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.reference_base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3350
 *     property genotype:
 *        '''the genotype called.'''
 *        def __get__(self): return from_string_and_size( &self._genotype, 1 )             # <<<<<<<<<<<<<<
 * 
 *     property consensus_quality:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_8genotype___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3350);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_8csamfile_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.genotype.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3354
 *     property consensus_quality:
 *        '''the genotype quality (Phred-scaled).'''
 *        def __get__(self): return self._consensus_quality             # <<<<<<<<<<<<<<
 * 
 *     property snp_quality:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_17consensus_quality___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3354);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.consensus_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3358
 *     property snp_quality:
 *        '''the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.'''
 *        def __get__(self): return self._snp_quality             # <<<<<<<<<<<<<<
 * 
 *     property mapping_quality:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_11snp_quality___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3358);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.snp_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3362
 *     property mapping_quality:
 *        '''the root mean square (rms) of the mapping quality of all reads involved in the call.'''
 *        def __get__(self): return self._rms_mapping_quality             # <<<<<<<<<<<<<<
 * 
 *     property coverage:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_15mapping_quality___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3362);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3366
 *     property coverage:
 *        '''coverage or read depth - the number of reads involved in the call.'''
 *        def __get__(self): return self._coverage             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall_8coverage___get__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3366);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.csamfile.SNPCall.coverage.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3368
 *        def __get__(self): return self._coverage
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( map(str, (
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_1__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_8csamfile_7SNPCall_1__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_7SNPCall___str__(((struct __pyx_obj_5pysam_8csamfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_7SNPCall___str__(struct __pyx_obj_5pysam_8csamfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 3368);

  /* "pysam/csamfile.pyx":3370
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/csamfile.pyx":3371
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/csamfile.pyx":3372
 *         return "\t".join( map(str, (
 *                     self.tid,
 *                     self.pos,             # <<<<<<<<<<<<<<
 *                     self.reference_base,
 *                     self.genotype,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/csamfile.pyx":3373
 *                     self.tid,
 *                     self.pos,
 *                     self.reference_base,             # <<<<<<<<<<<<<<
 *                     self.genotype,
 *                     self.consensus_quality,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_base); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/csamfile.pyx":3374
 *                     self.pos,
 *                     self.reference_base,
 *                     self.genotype,             # <<<<<<<<<<<<<<
 *                     self.consensus_quality,
 *                     self.snp_quality,
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_genotype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/csamfile.pyx":3375
 *                     self.reference_base,
 *                     self.genotype,
 *                     self.consensus_quality,             # <<<<<<<<<<<<<<
 *                     self.snp_quality,
 *                     self.mapping_quality,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_consensus_quality); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/csamfile.pyx":3376
 *                     self.genotype,
 *                     self.consensus_quality,
 *                     self.snp_quality,             # <<<<<<<<<<<<<<
 *                     self.mapping_quality,
 *                     self.coverage ) ) )
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_snp_quality); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/csamfile.pyx":3377
 *                     self.consensus_quality,
 *                     self.snp_quality,
 *                     self.mapping_quality,             # <<<<<<<<<<<<<<
 *                     self.coverage ) ) )
 * 
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/csamfile.pyx":3378
 *                     self.snp_quality,
 *                     self.mapping_quality,
 *                     self.coverage ) ) )             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_coverage); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/csamfile.pyx":3371
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_1 = 0;
  __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;

  /* "pysam/csamfile.pyx":3370
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __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 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "pysam/csamfile.pyx":3368
 *        def __get__(self): return self._coverage
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( map(str, (
 */

  /* function exit code */
  __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("pysam.csamfile.SNPCall.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3391
 *     """
 * 
 *     def __init__(self, Samfile samfile, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as this
 */

/* Python wrapper */
static int __pyx_pw_5pysam_8csamfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_8csamfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile = 0;
  int __pyx_v_reopen;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_reopen,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_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;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reopen);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      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);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)values[0]);
    if (values[1]) {
      __pyx_v_reopen = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_reopen = ((int)1);
    }
  }
  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 = 3391; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.csamfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_8csamfile_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_8csamfile_12IndexedReads___init__(((struct __pyx_obj_5pysam_8csamfile_IndexedReads *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_8csamfile_12IndexedReads___init__(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_8csamfile_Samfile *__pyx_v_samfile, int __pyx_v_reopen) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  char const *__pyx_t_2;
  htsFile *__pyx_t_3;
  BGZF *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 3391);

  /* "pysam/csamfile.pyx":3395
 *         # makes sure that samfile stays alive as long as this
 *         # object is alive.
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 * 
 *         assert samfile.isbam, "can only IndexReads on bam files"
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GOTREF(__pyx_v_self->samfile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/csamfile.pyx":3397
 *         self.samfile = samfile
 * 
 *         assert samfile.isbam, "can only IndexReads on bam files"             # <<<<<<<<<<<<<<
 * 
 *         # reopen the file - note that this makes the iterator
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!(__pyx_v_samfile->isbam != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_can_only_IndexReads_on_bam_files);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

  /* "pysam/csamfile.pyx":3401
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if reopen:             # <<<<<<<<<<<<<<
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL
 */
  __pyx_t_1 = (__pyx_v_reopen != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":3402
 *         # slow and causes pileup to slow down significantly.
 *         if reopen:
 *             self.htsfile = hts_open(samfile._filename, 'r')             # <<<<<<<<<<<<<<
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 */
    __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_samfile->_filename); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_2, __pyx_k_r);

    /* "pysam/csamfile.pyx":3403
 *         if reopen:
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL             # <<<<<<<<<<<<<<
 *             # read header - required for accurate positioning
 *             sam_hdr_read(self.htsfile)
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "pysam/csamfile.pyx":3405
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 *             sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             self.owns_samfile = True
 *         else:
 */
    sam_hdr_read(__pyx_v_self->htsfile);

    /* "pysam/csamfile.pyx":3406
 *             # read header - required for accurate positioning
 *             sam_hdr_read(self.htsfile)
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 *         else:
 *             self.htsfile = self.samfile.htsfile
 */
    __pyx_v_self->owns_samfile = 1;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":3408
 *             self.owns_samfile = True
 *         else:
 *             self.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 * 
 */
    __pyx_t_3 = __pyx_v_self->samfile->htsfile;
    __pyx_v_self->htsfile = __pyx_t_3;

    /* "pysam/csamfile.pyx":3409
 *         else:
 *             self.htsfile = self.samfile.htsfile
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *         # TODO: BAM file specific
 */
    __pyx_v_self->owns_samfile = 0;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":3412
 * 
 *         # TODO: BAM file specific
 *         self.fp = self.htsfile.fp.bgzf             # <<<<<<<<<<<<<<
 * 
 *     def build(self):
 */
  __pyx_t_4 = __pyx_v_self->htsfile->fp.bgzf;
  __pyx_v_self->fp = __pyx_t_4;

  /* "pysam/csamfile.pyx":3391
 *     """
 * 
 *     def __init__(self, Samfile samfile, int reopen=True):             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as this
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.csamfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3414
 *         self.fp = self.htsfile.fp.bgzf
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build index.'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_12IndexedReads_3build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_8csamfile_12IndexedReads_2build[] = "IndexedReads.build(self)\nbuild index.";
static PyObject *__pyx_pw_5pysam_8csamfile_12IndexedReads_3build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("build (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_12IndexedReads_2build(((struct __pyx_obj_5pysam_8csamfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_12IndexedReads_2build(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self) {
  int __pyx_v_ret;
  bam1_t *__pyx_v_b;
  uint64_t __pyx_v_pos;
  PyObject *__pyx_v_qname = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("build", 0);
  __Pyx_TraceCall("build", __pyx_f[0], 3414);

  /* "pysam/csamfile.pyx":3417
 *         '''build index.'''
 * 
 *         self.index = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 * 
 *         # this method will start indexing from the current file position
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __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 = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyList_Type))));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)(&PyList_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyList_Type))));
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __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_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->index);
  __Pyx_DECREF(__pyx_v_self->index);
  __pyx_v_self->index = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysam/csamfile.pyx":3421
 *         # this method will start indexing from the current file position
 *         # if you decide
 *         cdef int ret = 1             # <<<<<<<<<<<<<<
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 * 
 */
  __pyx_v_ret = 1;

  /* "pysam/csamfile.pyx":3422
 *         # if you decide
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))             # <<<<<<<<<<<<<<
 * 
 *         cdef uint64_t pos
 */
  __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/csamfile.pyx":3426
 *         cdef uint64_t pos
 * 
 *         while ret > 0:             # <<<<<<<<<<<<<<
 *             pos = bgzf_tell(self.fp)
 *             ret = sam_read1(self.htsfile,
 */
  while (1) {
    __pyx_t_4 = ((__pyx_v_ret > 0) != 0);
    if (!__pyx_t_4) break;

    /* "pysam/csamfile.pyx":3427
 * 
 *         while ret > 0:
 *             pos = bgzf_tell(self.fp)             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             self.samfile.header,
 */
    __pyx_v_pos = bgzf_tell(__pyx_v_self->fp);

    /* "pysam/csamfile.pyx":3428
 *         while ret > 0:
 *             pos = bgzf_tell(self.fp)
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             self.samfile.header,
 *                             b)
 */
    __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_self->samfile->header, __pyx_v_b);

    /* "pysam/csamfile.pyx":3431
 *                             self.samfile.header,
 *                             b)
 *             if ret > 0:             # <<<<<<<<<<<<<<
 *                 qname = _charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)
 */
    __pyx_t_4 = ((__pyx_v_ret > 0) != 0);
    if (__pyx_t_4) {

      /* "pysam/csamfile.pyx":3432
 *                             b)
 *             if ret > 0:
 *                 qname = _charptr_to_str(pysam_bam_get_qname(b))             # <<<<<<<<<<<<<<
 *                 self.index[qname].append(pos)
 * 
 */
      __pyx_t_3 = __pyx_f_5pysam_8csamfile__charptr_to_str(pysam_bam_get_qname(__pyx_v_b)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_qname, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/csamfile.pyx":3433
 *             if ret > 0:
 *                 qname = _charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)             # <<<<<<<<<<<<<<
 * 
 *         bam_destroy1(b)
 */
      __pyx_t_3 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3433; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysam/csamfile.pyx":3435
 *                 self.index[qname].append(pos)
 * 
 *         bam_destroy1(b)             # <<<<<<<<<<<<<<
 * 
 *     def find(self, qname):
 */
  bam_destroy1(__pyx_v_b);

  /* "pysam/csamfile.pyx":3414
 *         self.fp = self.htsfile.fp.bgzf
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build index.'''
 * 
 */

  /* function exit code */
  __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("pysam.csamfile.IndexedReads.build", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qname);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3437
 *         bam_destroy1(b)
 * 
 *     def find(self, qname):             # <<<<<<<<<<<<<<
 *         if qname in self.index:
 *             return IteratorRowSelection(
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_8csamfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
static char __pyx_doc_5pysam_8csamfile_12IndexedReads_4find[] = "IndexedReads.find(self, qname)";
static PyObject *__pyx_pw_5pysam_8csamfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_8csamfile_12IndexedReads_4find(((struct __pyx_obj_5pysam_8csamfile_IndexedReads *)__pyx_v_self), ((PyObject *)__pyx_v_qname));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_8csamfile_12IndexedReads_4find(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_qname) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("find", 0);
  __Pyx_TraceCall("find", __pyx_f[0], 3437);

  /* "pysam/csamfile.pyx":3438
 * 
 *     def find(self, qname):
 *         if qname in self.index:             # <<<<<<<<<<<<<<
 *             return IteratorRowSelection(
 *                 self.samfile,
 */
  __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_v_qname, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3438; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/csamfile.pyx":3439
 *     def find(self, qname):
 *         if qname in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[qname],
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/csamfile.pyx":3441
 *             return IteratorRowSelection(
 *                 self.samfile,
 *                 self.index[qname],             # <<<<<<<<<<<<<<
 *                 reopen = False)
 *         else:
 */
    __pyx_t_3 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3441; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/csamfile.pyx":3439
 *     def find(self, qname):
 *         if qname in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[qname],
 */
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self->samfile));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/csamfile.pyx":3442
 *                 self.samfile,
 *                 self.index[qname],
 *                 reopen = False)             # <<<<<<<<<<<<<<
 *         else:
 *             raise KeyError("read %s not found" % qname)
 */
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reopen, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/csamfile.pyx":3439
 *     def find(self, qname):
 *         if qname in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[qname],
 */
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_8csamfile_IteratorRowSelection)), __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":3444
 *                 reopen = False)
 *         else:
 *             raise KeyError("read %s not found" % qname)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_read_s_not_found, __pyx_v_qname); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/csamfile.pyx":3437
 *         bam_destroy1(b)
 * 
 *     def find(self, qname):             # <<<<<<<<<<<<<<
 *         if qname in self.index:
 *             return IteratorRowSelection(
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.csamfile.IndexedReads.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/csamfile.pyx":3446
 *             raise KeyError("read %s not found" % qname)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

/* Python wrapper */
static void __pyx_pw_5pysam_8csamfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_8csamfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_8csamfile_12IndexedReads_6__dealloc__(((struct __pyx_obj_5pysam_8csamfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_8csamfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_8csamfile_IndexedReads *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3446);

  /* "pysam/csamfile.pyx":3447
 * 
 *     def __dealloc__(self):
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 * 
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/csamfile.pyx":3448
 *     def __dealloc__(self):
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 * 
 * __all__ = ["Samfile",
 */
    hts_close(__pyx_v_self->htsfile);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":3446
 *             raise KeyError("read %s not found" % qname)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}
static struct __pyx_vtabstruct_5pysam_8csamfile_AlignedRead __pyx_vtable_5pysam_8csamfile_AlignedRead;

static PyObject *__pyx_tp_new_5pysam_8csamfile_AlignedRead(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_AlignedRead *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_AlignedRead;
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_AlignedRead(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_8csamfile_11AlignedRead_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_qname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5qname_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_qname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_5qname_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_cigar(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5cigar_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_cigar(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_5cigar_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_cigarstring(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_11cigarstring_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_cigarstring(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_11cigarstring_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_seq(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_3seq_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_seq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_3seq_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_qual(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4qual_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_qual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4qual_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_query(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5query_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_qqual(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5qqual_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_qstart(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_6qstart_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_qend(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4qend_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_qlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4qlen_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_tags(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4tags_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_tags(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4tags_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_flag(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4flag_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_flag(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4flag_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_rname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5rname_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_rname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_5rname_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_3tid_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_3tid_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_3pos_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_3pos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_bin(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_3bin_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_bin(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_3bin_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_rlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4rlen_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_aend(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4aend_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_alen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4alen_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_mapq(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4mapq_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_mapq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4mapq_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_mrnm(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4mrnm_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_mrnm(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4mrnm_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_rnext(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5rnext_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_rnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_5rnext_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_mpos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4mpos_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_mpos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4mpos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_pnext(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5pnext_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_pnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_5pnext_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_isize(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_5isize_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_isize(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_5isize_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_tlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_4tlen_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_tlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_4tlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_paired(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_paired_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_paired(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_paired_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_proper_pair(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_14is_proper_pair_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_proper_pair(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_14is_proper_pair_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_11is_unmapped_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_11is_unmapped_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_mate_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_mate_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_16mate_is_unmapped_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_reverse(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_10is_reverse_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_10is_reverse_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_mate_is_reverse(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_mate_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_15mate_is_reverse_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_read1(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read1_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_read1(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read1_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_read2(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read2_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_read2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_8is_read2_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_secondary(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_secondary_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_secondary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_secondary_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_qcfail(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_qcfail_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_qcfail(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_9is_qcfail_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_is_duplicate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_duplicate_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_duplicate(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11AlignedRead_12is_duplicate_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_positions(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_9positions_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_inferred_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_15inferred_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_aligned_pairs(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_13aligned_pairs_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11AlignedRead_blocks(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11AlignedRead_6blocks_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_AlignedRead[] = {
  {__Pyx_NAMESTR("compare"), (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_7compare, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_11AlignedRead_6compare)},
  {__Pyx_NAMESTR("_convert_python_tag"), (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_11_convert_python_tag, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_11AlignedRead_10_convert_python_tag)},
  {__Pyx_NAMESTR("setTag"), (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_13setTag, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_11AlignedRead_12setTag)},
  {__Pyx_NAMESTR("overlap"), (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_15overlap, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_11AlignedRead_14overlap)},
  {__Pyx_NAMESTR("opt"), (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_17opt, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_11AlignedRead_16opt)},
  {__Pyx_NAMESTR("fancy_str"), (PyCFunction)__pyx_pw_5pysam_8csamfile_11AlignedRead_19fancy_str, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_11AlignedRead_18fancy_str)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_8csamfile_AlignedRead[] = {
  {(char *)"qname", __pyx_getprop_5pysam_8csamfile_11AlignedRead_qname, __pyx_setprop_5pysam_8csamfile_11AlignedRead_qname, __Pyx_DOCSTR(__pyx_k_the_query_name_None_if_not_prese), 0},
  {(char *)"cigar", __pyx_getprop_5pysam_8csamfile_11AlignedRead_cigar, __pyx_setprop_5pysam_8csamfile_11AlignedRead_cigar, __Pyx_DOCSTR(__pyx_k_the_term_cigar_alignment_The_ali), 0},
  {(char *)"cigarstring", __pyx_getprop_5pysam_8csamfile_11AlignedRead_cigarstring, __pyx_setprop_5pysam_8csamfile_11AlignedRead_cigarstring, __Pyx_DOCSTR(__pyx_k_the_term_cigar_alignment_as_a_st), 0},
  {(char *)"seq", __pyx_getprop_5pysam_8csamfile_11AlignedRead_seq, __pyx_setprop_5pysam_8csamfile_11AlignedRead_seq, __Pyx_DOCSTR(__pyx_k_read_sequence_bases_including_te), 0},
  {(char *)"qual", __pyx_getprop_5pysam_8csamfile_11AlignedRead_qual, __pyx_setprop_5pysam_8csamfile_11AlignedRead_qual, __Pyx_DOCSTR(__pyx_k_read_sequence_base_qualities_inc), 0},
  {(char *)"query", __pyx_getprop_5pysam_8csamfile_11AlignedRead_query, 0, __Pyx_DOCSTR(__pyx_k_aligned_portion_of_the_read_This), 0},
  {(char *)"qqual", __pyx_getprop_5pysam_8csamfile_11AlignedRead_qqual, 0, __Pyx_DOCSTR(__pyx_k_aligned_query_sequence_quality_v), 0},
  {(char *)"qstart", __pyx_getprop_5pysam_8csamfile_11AlignedRead_qstart, 0, __Pyx_DOCSTR(__pyx_k_start_index_of_the_aligned_query), 0},
  {(char *)"qend", __pyx_getprop_5pysam_8csamfile_11AlignedRead_qend, 0, __Pyx_DOCSTR(__pyx_k_end_index_of_the_aligned_query_p), 0},
  {(char *)"qlen", __pyx_getprop_5pysam_8csamfile_11AlignedRead_qlen, 0, __Pyx_DOCSTR(__pyx_k_length_of_the_aligned_query_sequ), 0},
  {(char *)"tags", __pyx_getprop_5pysam_8csamfile_11AlignedRead_tags, __pyx_setprop_5pysam_8csamfile_11AlignedRead_tags, __Pyx_DOCSTR(__pyx_k_the_tags_in_the_AUX_field_This_p), 0},
  {(char *)"flag", __pyx_getprop_5pysam_8csamfile_11AlignedRead_flag, __pyx_setprop_5pysam_8csamfile_11AlignedRead_flag, __Pyx_DOCSTR(__pyx_k_properties_flag), 0},
  {(char *)"rname", __pyx_getprop_5pysam_8csamfile_11AlignedRead_rname, __pyx_setprop_5pysam_8csamfile_11AlignedRead_rname, __Pyx_DOCSTR(__pyx_k_term_target_ID_DEPRECATED_from), 0},
  {(char *)"tid", __pyx_getprop_5pysam_8csamfile_11AlignedRead_tid, __pyx_setprop_5pysam_8csamfile_11AlignedRead_tid, __Pyx_DOCSTR(__pyx_k_term_target_ID_note_This_field), 0},
  {(char *)"pos", __pyx_getprop_5pysam_8csamfile_11AlignedRead_pos, __pyx_setprop_5pysam_8csamfile_11AlignedRead_pos, __Pyx_DOCSTR(__pyx_k_0_based_leftmost_coordinate), 0},
  {(char *)"bin", __pyx_getprop_5pysam_8csamfile_11AlignedRead_bin, __pyx_setprop_5pysam_8csamfile_11AlignedRead_bin, __Pyx_DOCSTR(__pyx_k_properties_bin), 0},
  {(char *)"rlen", __pyx_getprop_5pysam_8csamfile_11AlignedRead_rlen, 0, __Pyx_DOCSTR(__pyx_k_length_of_the_read_This_includes), 0},
  {(char *)"aend", __pyx_getprop_5pysam_8csamfile_11AlignedRead_aend, 0, __Pyx_DOCSTR(__pyx_k_aligned_reference_position_of_th), 0},
  {(char *)"alen", __pyx_getprop_5pysam_8csamfile_11AlignedRead_alen, 0, __Pyx_DOCSTR(__pyx_k_aligned_length_of_the_read_on_th), 0},
  {(char *)"mapq", __pyx_getprop_5pysam_8csamfile_11AlignedRead_mapq, __pyx_setprop_5pysam_8csamfile_11AlignedRead_mapq, __Pyx_DOCSTR(__pyx_k_mapping_quality_2), 0},
  {(char *)"mrnm", __pyx_getprop_5pysam_8csamfile_11AlignedRead_mrnm, __pyx_setprop_5pysam_8csamfile_11AlignedRead_mrnm, __Pyx_DOCSTR(__pyx_k_the_term_reference_id_of_the_mat), 0},
  {(char *)"rnext", __pyx_getprop_5pysam_8csamfile_11AlignedRead_rnext, __pyx_setprop_5pysam_8csamfile_11AlignedRead_rnext, __Pyx_DOCSTR(__pyx_k_the_term_reference_id_of_the_mat_2), 0},
  {(char *)"mpos", __pyx_getprop_5pysam_8csamfile_11AlignedRead_mpos, __pyx_setprop_5pysam_8csamfile_11AlignedRead_mpos, __Pyx_DOCSTR(__pyx_k_the_position_of_the_mate_depreca), 0},
  {(char *)"pnext", __pyx_getprop_5pysam_8csamfile_11AlignedRead_pnext, __pyx_setprop_5pysam_8csamfile_11AlignedRead_pnext, __Pyx_DOCSTR(__pyx_k_the_position_of_the_mate), 0},
  {(char *)"isize", __pyx_getprop_5pysam_8csamfile_11AlignedRead_isize, __pyx_setprop_5pysam_8csamfile_11AlignedRead_isize, __Pyx_DOCSTR(__pyx_k_the_insert_size_deprecated_use_t), 0},
  {(char *)"tlen", __pyx_getprop_5pysam_8csamfile_11AlignedRead_tlen, __pyx_setprop_5pysam_8csamfile_11AlignedRead_tlen, __Pyx_DOCSTR(__pyx_k_the_template_length), 0},
  {(char *)"is_paired", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_paired, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_paired, __Pyx_DOCSTR(__pyx_k_true_if_read_is_paired_in_sequen), 0},
  {(char *)"is_proper_pair", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_proper_pair, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_proper_pair, __Pyx_DOCSTR(__pyx_k_true_if_read_is_mapped_in_a_prop), 0},
  {(char *)"is_unmapped", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_unmapped, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_unmapped, __Pyx_DOCSTR(__pyx_k_true_if_read_itself_is_unmapped), 0},
  {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_8csamfile_11AlignedRead_mate_is_unmapped, __pyx_setprop_5pysam_8csamfile_11AlignedRead_mate_is_unmapped, __Pyx_DOCSTR(__pyx_k_true_if_the_mate_is_unmapped), 0},
  {(char *)"is_reverse", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_reverse, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_reverse, __Pyx_DOCSTR(__pyx_k_true_if_read_is_mapped_to_revers), 0},
  {(char *)"mate_is_reverse", __pyx_getprop_5pysam_8csamfile_11AlignedRead_mate_is_reverse, __pyx_setprop_5pysam_8csamfile_11AlignedRead_mate_is_reverse, __Pyx_DOCSTR(__pyx_k_true_is_read_is_mapped_to_revers), 0},
  {(char *)"is_read1", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_read1, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_read1, __Pyx_DOCSTR(__pyx_k_true_if_this_is_read1), 0},
  {(char *)"is_read2", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_read2, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_read2, __Pyx_DOCSTR(__pyx_k_true_if_this_is_read2), 0},
  {(char *)"is_secondary", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_secondary, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_secondary, __Pyx_DOCSTR(__pyx_k_true_if_not_primary_alignment), 0},
  {(char *)"is_qcfail", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_qcfail, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_qcfail, __Pyx_DOCSTR(__pyx_k_true_if_QC_failure), 0},
  {(char *)"is_duplicate", __pyx_getprop_5pysam_8csamfile_11AlignedRead_is_duplicate, __pyx_setprop_5pysam_8csamfile_11AlignedRead_is_duplicate, __Pyx_DOCSTR(__pyx_k_true_if_optical_or_PCR_duplicate), 0},
  {(char *)"positions", __pyx_getprop_5pysam_8csamfile_11AlignedRead_positions, 0, __Pyx_DOCSTR(__pyx_k_a_list_of_reference_positions_th), 0},
  {(char *)"inferred_length", __pyx_getprop_5pysam_8csamfile_11AlignedRead_inferred_length, 0, __Pyx_DOCSTR(__pyx_k_inferred_read_length_from_CIGAR), 0},
  {(char *)"aligned_pairs", __pyx_getprop_5pysam_8csamfile_11AlignedRead_aligned_pairs, 0, __Pyx_DOCSTR(__pyx_k_a_list_of_aligned_read_and_refer), 0},
  {(char *)"blocks", __pyx_getprop_5pysam_8csamfile_11AlignedRead_blocks, 0, __Pyx_DOCSTR(__pyx_k_a_list_of_start_and_end_positio), 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_AlignedRead = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.AlignedRead"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_AlignedRead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  __pyx_pw_5pysam_8csamfile_11AlignedRead_9__hash__, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_8csamfile_11AlignedRead_5__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  __Pyx_DOCSTR("AlignedRead()\n\n    Class representing an aligned read. See the SAM format specification for\n    the 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 be resized if\n    a field is updated. Furthermore, the BAM entry might be\n    in an inconsistent state.\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\n    In Python 3, the fields containing sequence and quality\n    (seq, query, qual and qqual) data are of type bytes. Other\n    string data, such as the qname field and strings in the\n    tags tuple, is represented as unicode strings. On assignment,\n    both bytes and unicode objects are allowed, but unicode strings\n    must contain only ASCII characters.\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_AlignedRead, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_8csamfile_AlignedRead, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_8csamfile_11AlignedRead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_Samfile __pyx_vtable_5pysam_8csamfile_Samfile;

static PyObject *__pyx_tp_new_5pysam_8csamfile_Samfile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_Samfile;
  p->_filename = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_8csamfile_7Samfile_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_Samfile(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_Samfile *p = (struct __pyx_obj_5pysam_8csamfile_Samfile *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_8csamfile_7Samfile_33__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_filename);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_Samfile(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_Samfile *p = (struct __pyx_obj_5pysam_8csamfile_Samfile *)o;
  if (p->_filename) {
    e = (*v)(p->_filename, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_Samfile(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_Samfile *p = (struct __pyx_obj_5pysam_8csamfile_Samfile *)o;
  tmp = ((PyObject*)p->_filename);
  p->_filename = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_filename(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_8filename_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_7lengths_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_mapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_6mapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_8unmapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_nocoordinate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_12nocoordinate_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_text(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_4text_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7Samfile_header(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7Samfile_6header_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_Samfile[] = {
  {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_3_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_2_isOpen)},
  {__Pyx_NAMESTR("_hasIndex"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_5_hasIndex, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_4_hasIndex)},
  {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_7_open, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_6_open)},
  {__Pyx_NAMESTR("gettid"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_9gettid, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_8gettid)},
  {__Pyx_NAMESTR("getrname"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_11getrname, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_10getrname)},
  {__Pyx_NAMESTR("_parseRegion"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_13_parseRegion, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_12_parseRegion)},
  {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_15reset, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_14reset)},
  {__Pyx_NAMESTR("seek"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_17seek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_16seek)},
  {__Pyx_NAMESTR("tell"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_19tell, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_18tell)},
  {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_21fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_20fetch)},
  {__Pyx_NAMESTR("head"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_23head, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_22head)},
  {__Pyx_NAMESTR("mate"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_25mate, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_24mate)},
  {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_27count, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_26count)},
  {__Pyx_NAMESTR("pileup"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_29pileup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_28pileup)},
  {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_31close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_30close)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_35write, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_34write)},
  {__Pyx_NAMESTR("__enter__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_37__enter__, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_36__enter__)},
  {__Pyx_NAMESTR("__exit__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_39__exit__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_38__exit__)},
  {__Pyx_NAMESTR("_checkIndex"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_41_checkIndex, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_40_checkIndex)},
  {__Pyx_NAMESTR("_buildLine"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_43_buildLine, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_42_buildLine)},
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_7Samfile_47__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_7Samfile_46__next__)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_8csamfile_Samfile[] = {
  {(char *)"filename", __pyx_getprop_5pysam_8csamfile_7Samfile_filename, 0, __Pyx_DOCSTR(__pyx_k_number_of_term_filename_associat), 0},
  {(char *)"nreferences", __pyx_getprop_5pysam_8csamfile_7Samfile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_number_of_term_reference_sequenc), 0},
  {(char *)"references", __pyx_getprop_5pysam_8csamfile_7Samfile_references, 0, __Pyx_DOCSTR(__pyx_k_tuple_with_the_names_of_term_ref), 0},
  {(char *)"lengths", __pyx_getprop_5pysam_8csamfile_7Samfile_lengths, 0, __Pyx_DOCSTR(__pyx_k_tuple_of_the_lengths_of_the_term), 0},
  {(char *)"mapped", __pyx_getprop_5pysam_8csamfile_7Samfile_mapped, 0, __Pyx_DOCSTR(__pyx_k_total_number_of_mapped_alignment), 0},
  {(char *)"unmapped", __pyx_getprop_5pysam_8csamfile_7Samfile_unmapped, 0, __Pyx_DOCSTR(__pyx_k_total_number_of_unmapped_reads_i), 0},
  {(char *)"nocoordinate", __pyx_getprop_5pysam_8csamfile_7Samfile_nocoordinate, 0, __Pyx_DOCSTR(__pyx_k_total_number_of_reads_without_co), 0},
  {(char *)"text", __pyx_getprop_5pysam_8csamfile_7Samfile_text, 0, __Pyx_DOCSTR(__pyx_k_full_contents_of_the_term_sam_fi), 0},
  {(char *)"header", __pyx_getprop_5pysam_8csamfile_7Samfile_header, 0, __Pyx_DOCSTR(__pyx_k_header_information_within_the_te), 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_Samfile = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.Samfile"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_Samfile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("*(filename, mode=None, template = None,\n         referencenames = None, referencelengths = None,\n         text = NULL, header = None,\n         add_sq_text = False, check_header = True,\n         check_sq = True )*\n\n    A :term:`SAM`/:term:`BAM` formatted file. The file is\n    automatically opened.\n\n    *mode* should be ``r`` for reading or ``w`` for writing. The\n    default is text mode (:term:`SAM`). For binary (:term:`BAM`) I/O\n    you should append ``b`` for compressed or ``u`` for uncompressed\n    :term:`BAM` output.  Use ``h`` to output header information in\n    text (:term:`TAM`) mode.\n\n    If ``b`` is present, it must immediately follow ``r`` or ``w``.\n    Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb`` and\n    ``wbu``. For instance, to open a :term:`BAM` formatted file for\n    reading, type::\n\n        f = pysam.Samfile('ex1.bam','rb')\n\n    If mode is not specified, we will try to auto-detect in the order\n    'rb', 'r', thus both the following should work::\n\n        f1 = pysam.Samfile('ex1.bam' )\n        f2 = pysam.Samfile('ex1.sam' )\n\n    If an index for a BAM file exists (.bai), it will be opened\n    automatically. Without an index random access to reads via\n    :meth:`fetch` and :meth:`pileup` is disabled.\n\n    For writing, the header of a :term:`SAM` file/:term:`BAM` file can\n    be constituted from several sources (see also the samtools format\n    specification):\n\n        1. If *template* is given, the header is copied from a another\n           *Samfile* (*template* must be of type *Samfile*).\n\n        2. If *header* is given, the header is built from a\n           multi-level dictionary. The first level are the four types\n           ('HD', 'SQ', ...). The second level are a list of lines,\n           with each line being a list of tag-value pairs. The header\n           is constructed first from all the defined fields, followed\n           by user tags in alphabetical order.\n\n        3. If *text* is given, new header text is copied from raw\n           text.\n\n        4. The names (*referencenames*) and lengths\n           (*referencelengths*) are supplied directly as lists.  By\n           default, 'SQ' and 'LN' tags will be added to the header\n           text. This option can be changed by unsetting the flag\n           *add_sq_text*.\n\n    By default, if a file is opened in mode 'r', it is checked\n    for a valid header (*check_header* = True) and a definition of\n    chromosome names (*check_sq* = True).\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_Samfile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_Samfile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_7Samfile_45__iter__, /*tp_iter*/
  __pyx_pw_5pysam_8csamfile_7Samfile_47__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_Samfile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_8csamfile_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_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_8csamfile_PileupProxy(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_PileupProxy(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11PileupProxy_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11PileupProxy_3tid_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11PileupProxy_n(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11PileupProxy_1n_1__get__(o);
}

static int __pyx_setprop_5pysam_8csamfile_11PileupProxy_n(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_8csamfile_11PileupProxy_1n_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11PileupProxy_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11PileupProxy_3pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_11PileupProxy_pileups(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_11PileupProxy_7pileups_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_PileupProxy[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_8csamfile_PileupProxy[] = {
  {(char *)"tid", __pyx_getprop_5pysam_8csamfile_11PileupProxy_tid, 0, __Pyx_DOCSTR(__pyx_k_the_chromosome_ID_as_is_defined), 0},
  {(char *)"n", __pyx_getprop_5pysam_8csamfile_11PileupProxy_n, __pyx_setprop_5pysam_8csamfile_11PileupProxy_n, __Pyx_DOCSTR(__pyx_k_number_of_reads_mapping_to_this), 0},
  {(char *)"pos", __pyx_getprop_5pysam_8csamfile_11PileupProxy_pos, 0, 0, 0},
  {(char *)"pileups", __pyx_getprop_5pysam_8csamfile_11PileupProxy_pileups, 0, __Pyx_DOCSTR(__pyx_k_list_of_reads_class_pysam_Pileup), 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_PileupProxy = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.PileupProxy"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_PileupProxy), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_8csamfile_11PileupProxy_3__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  __Pyx_DOCSTR("PileupProxy()\nA 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_5pysam_8csamfile_PileupProxy, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_8csamfile_PileupProxy, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_8csamfile_11PileupProxy_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_8csamfile_PileupRead(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_PileupRead *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_PileupRead *)o);
  p->_alignment = ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_PileupRead(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_PileupRead *p = (struct __pyx_obj_5pysam_8csamfile_PileupRead *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->_alignment);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_PileupRead(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_PileupRead *p = (struct __pyx_obj_5pysam_8csamfile_PileupRead *)o;
  if (p->_alignment) {
    e = (*v)(((PyObject*)p->_alignment), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_PileupRead(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_PileupRead *p = (struct __pyx_obj_5pysam_8csamfile_PileupRead *)o;
  tmp = ((PyObject*)p->_alignment);
  p->_alignment = ((struct __pyx_obj_5pysam_8csamfile_AlignedRead *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_alignment(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_9alignment_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_qpos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_4qpos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_indel(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_5indel_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_is_del(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_6is_del_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_is_head(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_7is_head_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_is_tail(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_7is_tail_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_10PileupRead_level(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_10PileupRead_5level_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_PileupRead[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_8csamfile_PileupRead[] = {
  {(char *)"alignment", __pyx_getprop_5pysam_8csamfile_10PileupRead_alignment, 0, __Pyx_DOCSTR(__pyx_k_a_class_pysam_AlignedRead_object), 0},
  {(char *)"qpos", __pyx_getprop_5pysam_8csamfile_10PileupRead_qpos, 0, __Pyx_DOCSTR(__pyx_k_position_of_the_read_base_at_the), 0},
  {(char *)"indel", __pyx_getprop_5pysam_8csamfile_10PileupRead_indel, 0, __Pyx_DOCSTR(__pyx_k_indel_length_0_for_no_indel_posi), 0},
  {(char *)"is_del", __pyx_getprop_5pysam_8csamfile_10PileupRead_is_del, 0, __Pyx_DOCSTR(__pyx_k_1_iff_the_base_on_the_padded_rea), 0},
  {(char *)"is_head", __pyx_getprop_5pysam_8csamfile_10PileupRead_is_head, 0, 0, 0},
  {(char *)"is_tail", __pyx_getprop_5pysam_8csamfile_10PileupRead_is_tail, 0, 0, 0},
  {(char *)"level", __pyx_getprop_5pysam_8csamfile_10PileupRead_level, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_PileupRead = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.PileupRead"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_PileupRead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_8csamfile_10PileupRead_3__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("PileupRead()\nA read aligned to a column.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_PileupRead, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_PileupRead, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_PileupRead, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_8csamfile_PileupRead, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_8csamfile_10PileupRead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRow(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorRow *)o);
  p->samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_IteratorRow(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRow *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRow *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_8csamfile_11IteratorRow_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_IteratorRow(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_IteratorRow *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRow *)o;
  if (p->samfile) {
    e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_IteratorRow(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_IteratorRow *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRow *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorRow[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorRow = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorRow"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorRow), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IteratorRow(Samfile samfile, int reopen=True)\nabstract base class for iterators over mapped reads.\n\n    Various iterators implement different behaviours for wrapping around\n    contig boundaries. Examples include:\n\n    :class:`pysam.IteratorRowRegion`\n        iterate within a single contig and a defined region.\n\n    :class:`pysam.IteratorRowAll`\n        iterate until EOF. This iterator will also include unmapped reads.\n\n    :class:`pysam.IteratorRowAllRefs`\n        iterate over all reads in all reference sequences.\n\n    The method :meth:`Samfile.fetch` returns an IteratorRow.\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitely. It is returned as a result of call to a :meth:`Samfile.fetch`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_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*/
  __pyx_pw_5pysam_8csamfile_11IteratorRow_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowRegion __pyx_vtable_5pysam_8csamfile_IteratorRowRegion;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_IteratorRowRegion;
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_IteratorRowRegion(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_7__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_8csamfile_IteratorRow(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorRowRegion[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_17IteratorRowRegion_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_17IteratorRowRegion_4__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorRowRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorRowRegion"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_IteratorRowRegion, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IteratorRowRegion(Samfile samfile, int tid, int beg, int end, int reopen=True)\n*(Samfile samfile, int tid, int beg, int end, int reopen = True )*\n\n    iterate over mapped reads in a region.\n\n    By default, the file is re-openend to avoid conflicts between\n    multiple iterators working on the same file. Set *reopen* = False\n    to not re-open *samfile*.\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\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitely. It is returned as a result of call to a :meth:`Samfile.fetch`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorRowRegion, /*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*/
  __pyx_pw_5pysam_8csamfile_17IteratorRowRegion_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_IteratorRowRegion, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowHead __pyx_vtable_5pysam_8csamfile_IteratorRowHead;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_IteratorRowHead;
  return o;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorRowHead[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_15IteratorRowHead_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_15IteratorRowHead_4__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorRowHead = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorRowHead"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IteratorRowHead(Samfile samfile, int n, int reopen=True)\n*(Samfile samfile, n, int reopen = True)*\n\n    iterate over first n reads in *samfile*\n\n    By default, the file is re-openend to avoid conflicts between\n    multiple iterators working on the same file. Set *reopen* = False\n    to not re-open *samfile*.\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitely. It is returned as a result of call to a :meth:`Samfile.head`.\n        \n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_15IteratorRowHead_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_8csamfile_15IteratorRowHead_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorRowHead, /*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*/
  __pyx_pw_5pysam_8csamfile_15IteratorRowHead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_IteratorRowHead, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowAll __pyx_vtable_5pysam_8csamfile_IteratorRowAll;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_IteratorRowAll;
  return o;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorRowAll[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_14IteratorRowAll_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_14IteratorRowAll_4__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorRowAll = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorRowAll"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IteratorRowAll(Samfile samfile, int reopen=True)\n*(Samfile samfile, int reopen = True)*\n\n    iterate over all reads in *samfile*\n\n    By default, the file is re-openend to avoid conflicts between\n    multiple iterators working on the same file. Set *reopen* = False\n    to not re-open *samfile*.\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitely. It is returned as a result of call to a :meth:`Samfile.fetch`.\n        \n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_14IteratorRowAll_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_8csamfile_14IteratorRowAll_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_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*/
  __pyx_pw_5pysam_8csamfile_14IteratorRowAll_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)o);
  p->rowiter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_IteratorRowAllRefs(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->rowiter);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_8csamfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_IteratorRowAllRefs(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)o;
  e = __pyx_tp_traverse_5pysam_8csamfile_IteratorRow(o, v, a); if (e) return e;
  if (p->rowiter) {
    e = (*v)(((PyObject*)p->rowiter), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_IteratorRowAllRefs(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs *)o;
  __pyx_tp_clear_5pysam_8csamfile_IteratorRow(o);
  tmp = ((PyObject*)p->rowiter);
  p->rowiter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorRowAllRefs[] = {
  {__Pyx_NAMESTR("nextiter"), (PyCFunction)__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_3nextiter, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_18IteratorRowAllRefs_2nextiter)},
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_7__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_18IteratorRowAllRefs_6__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorRowAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorRowAllRefs"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorRowAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_IteratorRowAllRefs, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IteratorRowAllRefs(Samfile samfile, reopen=True)\niterates over all mapped reads by chaining iterators over each reference\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitely. It is returned as a result of call to a :meth:`Samfile.fetch`.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorRowAllRefs, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorRowAllRefs, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_5__iter__, /*tp_iter*/
  __pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_7__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorRowAllRefs, /*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*/
  __pyx_pw_5pysam_8csamfile_18IteratorRowAllRefs_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_IteratorRowAllRefs, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorRowSelection __pyx_vtable_5pysam_8csamfile_IteratorRowSelection;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_IteratorRowSelection;
  p->positions = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_IteratorRowSelection(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->positions);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_8csamfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_IteratorRowSelection(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)o;
  e = __pyx_tp_traverse_5pysam_8csamfile_IteratorRow(o, v, a); if (e) return e;
  if (p->positions) {
    e = (*v)(p->positions, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_IteratorRowSelection(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *)o;
  __pyx_tp_clear_5pysam_8csamfile_IteratorRow(o);
  tmp = ((PyObject*)p->positions);
  p->positions = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorRowSelection[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_20IteratorRowSelection_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_20IteratorRowSelection_4__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorRowSelection = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorRowSelection"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_IteratorRowSelection, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IteratorRowSelection(Samfile samfile, positions, int reopen=True)\n*(Samfile samfile)*\n\n    iterate over reads in *samfile* at a given list of file positions.\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitely. It is returned as a result of call to a :meth:`Samfile.fetch`.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorRowSelection, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorRowSelection, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_20IteratorRowSelection_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_8csamfile_20IteratorRowSelection_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorRowSelection, /*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*/
  __pyx_pw_5pysam_8csamfile_20IteratorRowSelection_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_IteratorRowSelection, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn __pyx_vtable_5pysam_8csamfile_IteratorColumn;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorColumn *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_8csamfile_IteratorColumn;
  p->iter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  p->samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None); Py_INCREF(Py_None);
  p->fastafile = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)Py_None); Py_INCREF(Py_None);
  p->stepper = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_8csamfile_14IteratorColumn_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_IteratorColumn(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_IteratorColumn *p = (struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_8csamfile_14IteratorColumn_9__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->iter);
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->fastafile);
  Py_CLEAR(p->stepper);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_IteratorColumn(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_IteratorColumn *p = (struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)o;
  if (p->iter) {
    e = (*v)(((PyObject*)p->iter), a); if (e) return e;
  }
  if (p->samfile) {
    e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
  }
  if (p->fastafile) {
    e = (*v)(((PyObject*)p->fastafile), a); if (e) return e;
  }
  if (p->stepper) {
    e = (*v)(p->stepper, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_IteratorColumn(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_IteratorColumn *p = (struct __pyx_obj_5pysam_8csamfile_IteratorColumn *)o;
  tmp = ((PyObject*)p->iter);
  p->iter = ((struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->fastafile);
  p->fastafile = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->stepper);
  p->stepper = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_8csamfile_14IteratorColumn_seq_len(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_14IteratorColumn_7seq_len_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorColumn[] = {
  {__Pyx_NAMESTR("addReference"), (PyCFunction)__pyx_pw_5pysam_8csamfile_14IteratorColumn_5addReference, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_14IteratorColumn_4addReference)},
  {__Pyx_NAMESTR("hasReference"), (PyCFunction)__pyx_pw_5pysam_8csamfile_14IteratorColumn_7hasReference, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_14IteratorColumn_6hasReference)},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_8csamfile_IteratorColumn[] = {
  {(char *)"seq_len", __pyx_getprop_5pysam_8csamfile_14IteratorColumn_seq_len, 0, __Pyx_DOCSTR(__pyx_k_current_sequence_length), 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorColumn"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("abstract base class for iterators over columns.\n\n    IteratorColumn objects wrap the pileup functionality of samtools.\n\n    For reasons of efficiency, the iterator points to the current\n    pileup buffer. The pileup buffer is updated at every iteration.\n    This might cause some unexpected behavious. For example,\n    consider the conversion to a list::\n\n       f = Samfile(\"file.bam\", \"rb\")\n       result = list( f.pileup() )\n\n    Here, ``result`` will contain ``n`` objects of type\n    :class:`PileupProxy` for ``n`` columns, but each object in\n    ``result`` will contain the same information.\n\n    The desired behaviour can be achieved by list comprehension::\n\n       result = [ x.pileups() for x in f.pileup() ]\n\n    ``result`` will be a list of ``n`` lists of objects of type :class:`PileupRead`.\n\n    If the iterator is associated with a :class:`Fastafile` using the\n    :meth:`addReference` method, then the iterator will export the\n    current sequence via the methods :meth:`getSequence` and\n    :meth:`seq_len`.\n\n    Optional kwargs to the iterator:\n\n    stepper\n       The stepper controls how the iterator advances.\n\n       Valid values are None, \"all\" or \"samtools\".\n\n       The default stepper \"all\" uses all reads for\n       computing the pileup. This corresponds to the\n       mpileup options \"-B\" and \"-A\".\n\n       The stepper \"samtools\" uses the mpileup default\n       parameterization to advance.\n\n    fastafile\n       A :class:`FastaFile` object\n\n    max_depth\n       maximum read depth. The default is 8000.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_8csamfile_14IteratorColumn_3__iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorColumn, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_8csamfile_IteratorColumn, /*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_5pysam_8csamfile_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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnRegion __pyx_vtable_5pysam_8csamfile_IteratorColumnRegion;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn*)__pyx_vtabptr_5pysam_8csamfile_IteratorColumnRegion;
  if (unlikely(__pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorColumnRegion[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_3__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_20IteratorColumnRegion_2__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorColumnRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorColumnRegion"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorColumnRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("iterates over a region only.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_8csamfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_8csamfile_20IteratorColumnRegion_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorColumnRegion, /*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_5pysam_8csamfile_IteratorColumnRegion, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumnAllRefs __pyx_vtable_5pysam_8csamfile_IteratorColumnAllRefs;

static PyObject *__pyx_tp_new_5pysam_8csamfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_8csamfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_8csamfile_IteratorColumn*)__pyx_vtabptr_5pysam_8csamfile_IteratorColumnAllRefs;
  if (unlikely(__pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IteratorColumnAllRefs[] = {
  {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_3__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IteratorColumnAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IteratorColumnAllRefs"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IteratorColumnAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("iterates over all columns by chaining iterators over each reference\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_8csamfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_8csamfile_21IteratorColumnAllRefs_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IteratorColumnAllRefs, /*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_5pysam_8csamfile_IteratorColumnAllRefs, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_8csamfile_IndexedReads(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_8csamfile_IndexedReads *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_8csamfile_IndexedReads *)o);
  p->samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None); Py_INCREF(Py_None);
  p->index = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_IndexedReads(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile_IndexedReads *p = (struct __pyx_obj_5pysam_8csamfile_IndexedReads *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_8csamfile_12IndexedReads_7__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->index);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_8csamfile_IndexedReads(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile_IndexedReads *p = (struct __pyx_obj_5pysam_8csamfile_IndexedReads *)o;
  if (p->samfile) {
    e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
  }
  if (p->index) {
    e = (*v)(p->index, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile_IndexedReads(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile_IndexedReads *p = (struct __pyx_obj_5pysam_8csamfile_IndexedReads *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_8csamfile_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->index);
  p->index = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_IndexedReads[] = {
  {__Pyx_NAMESTR("build"), (PyCFunction)__pyx_pw_5pysam_8csamfile_12IndexedReads_3build, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_12IndexedReads_2build)},
  {__Pyx_NAMESTR("find"), (PyCFunction)__pyx_pw_5pysam_8csamfile_12IndexedReads_5find, METH_O, __Pyx_DOCSTR(__pyx_doc_5pysam_8csamfile_12IndexedReads_4find)},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_IndexedReads = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.IndexedReads"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_IndexedReads), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_IndexedReads, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("IndexedReads(Samfile samfile, int reopen=True)\nindex a bamfile by read.\n\n    The index is kept in memory.\n\n    By default, the file is re-openend to avoid conflicts if\n    multiple operators work on the same file. Set *reopen* = False\n    to not re-open *samfile*.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile_IndexedReads, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile_IndexedReads, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_IndexedReads, /*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*/
  __pyx_pw_5pysam_8csamfile_12IndexedReads_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_8csamfile_IndexedReads, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_8csamfile_SNPCall(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile_SNPCall(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_3tid_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_3pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_reference_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_14reference_base_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_genotype(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_8genotype_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_consensus_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_17consensus_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_snp_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_11snp_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_15mapping_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_8csamfile_7SNPCall_coverage(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_8csamfile_7SNPCall_8coverage_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_8csamfile_SNPCall[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_8csamfile_SNPCall[] = {
  {(char *)"tid", __pyx_getprop_5pysam_8csamfile_7SNPCall_tid, 0, __Pyx_DOCSTR(__pyx_k_the_chromosome_ID_as_is_defined), 0},
  {(char *)"pos", __pyx_getprop_5pysam_8csamfile_7SNPCall_pos, 0, __Pyx_DOCSTR(__pyx_k_nucleotide_position_of_SNP), 0},
  {(char *)"reference_base", __pyx_getprop_5pysam_8csamfile_7SNPCall_reference_base, 0, __Pyx_DOCSTR(__pyx_k_reference_base_at_pos_N_if_no_re), 0},
  {(char *)"genotype", __pyx_getprop_5pysam_8csamfile_7SNPCall_genotype, 0, __Pyx_DOCSTR(__pyx_k_the_genotype_called), 0},
  {(char *)"consensus_quality", __pyx_getprop_5pysam_8csamfile_7SNPCall_consensus_quality, 0, __Pyx_DOCSTR(__pyx_k_the_genotype_quality_Phred_scale), 0},
  {(char *)"snp_quality", __pyx_getprop_5pysam_8csamfile_7SNPCall_snp_quality, 0, __Pyx_DOCSTR(__pyx_k_the_snp_quality_Phred_scaled_pro), 0},
  {(char *)"mapping_quality", __pyx_getprop_5pysam_8csamfile_7SNPCall_mapping_quality, 0, __Pyx_DOCSTR(__pyx_k_the_root_mean_square_rms_of_the), 0},
  {(char *)"coverage", __pyx_getprop_5pysam_8csamfile_7SNPCall_coverage, 0, __Pyx_DOCSTR(__pyx_k_coverage_or_read_depth_the_numbe), 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_8csamfile_SNPCall = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.SNPCall"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile_SNPCall), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile_SNPCall, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_8csamfile_7SNPCall_1__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  __Pyx_DOCSTR("the results of a SNP call."), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_8csamfile_SNPCall, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_8csamfile_SNPCall, /*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_5pysam_8csamfile_SNPCall, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *__pyx_freelist_5pysam_8csamfile___pyx_scope_struct__genexpr[8];
static int __pyx_freecount_5pysam_8csamfile___pyx_scope_struct__genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_8csamfile___pyx_scope_struct__genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (likely((__pyx_freecount_5pysam_8csamfile___pyx_scope_struct__genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_8csamfile___pyx_scope_struct__genexpr[--__pyx_freecount_5pysam_8csamfile___pyx_scope_struct__genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile___pyx_scope_struct__genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_v_y);
  Py_CLEAR(p->__pyx_t_0);
  Py_CLEAR(p->__pyx_t_1);
  if ((__pyx_freecount_5pysam_8csamfile___pyx_scope_struct__genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr))) {
    __pyx_freelist_5pysam_8csamfile___pyx_scope_struct__genexpr[__pyx_freecount_5pysam_8csamfile___pyx_scope_struct__genexpr++] = ((struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_8csamfile___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *)o;
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, a); if (e) return e;
  }
  if (p->__pyx_v_y) {
    e = (*v)(p->__pyx_v_y, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  if (p->__pyx_t_1) {
    e = (*v)(p->__pyx_t_1, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile___pyx_scope_struct__genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr *)o;
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_y);
  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_0);
  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_1);
  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_8csamfile___pyx_scope_struct__genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.__pyx_scope_struct__genexpr"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct__genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile___pyx_scope_struct__genexpr, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile___pyx_scope_struct__genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile___pyx_scope_struct__genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*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_5pysam_8csamfile___pyx_scope_struct__genexpr, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_8csamfile___pyx_scope_struct_1_genexpr[8];
static int __pyx_freecount_5pysam_8csamfile___pyx_scope_struct_1_genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_8csamfile___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (likely((__pyx_freecount_5pysam_8csamfile___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_8csamfile___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_8csamfile___pyx_scope_struct_1_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_8csamfile___pyx_scope_struct_1_genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_v_y);
  Py_CLEAR(p->__pyx_t_0);
  Py_CLEAR(p->__pyx_t_1);
  if ((__pyx_freecount_5pysam_8csamfile___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr))) {
    __pyx_freelist_5pysam_8csamfile___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_8csamfile___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_8csamfile___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *)o;
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, a); if (e) return e;
  }
  if (p->__pyx_v_y) {
    e = (*v)(p->__pyx_v_y, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  if (p->__pyx_t_1) {
    e = (*v)(p->__pyx_t_1, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_8csamfile___pyx_scope_struct_1_genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr *)o;
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_y);
  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_0);
  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_1);
  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_8csamfile___pyx_scope_struct_1_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysam.csamfile.__pyx_scope_struct_1_genexpr"), /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_8csamfile___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_8csamfile___pyx_scope_struct_1_genexpr, /*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*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_8csamfile___pyx_scope_struct_1_genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_8csamfile___pyx_scope_struct_1_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*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_5pysam_8csamfile___pyx_scope_struct_1_genexpr, /*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
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    __Pyx_NAMESTR("csamfile"),
    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_2scB, __pyx_k_2scB, sizeof(__pyx_k_2scB), 0, 0, 1, 0},
  {&__pyx_kp_s_2scH, __pyx_k_2scH, sizeof(__pyx_k_2scH), 0, 0, 1, 0},
  {&__pyx_kp_s_2scI, __pyx_k_2scI, sizeof(__pyx_k_2scI), 0, 0, 1, 0},
  {&__pyx_kp_s_2sc_is, __pyx_k_2sc_is, sizeof(__pyx_k_2sc_is), 0, 0, 1, 0},
  {&__pyx_kp_s_2scb, __pyx_k_2scb, sizeof(__pyx_k_2scb), 0, 0, 1, 0},
  {&__pyx_kp_s_2scc, __pyx_k_2scc, sizeof(__pyx_k_2scc), 0, 0, 1, 0},
  {&__pyx_kp_s_2sccI_i_s, __pyx_k_2sccI_i_s, sizeof(__pyx_k_2sccI_i_s), 0, 0, 1, 0},
  {&__pyx_kp_s_2scf, __pyx_k_2scf, sizeof(__pyx_k_2scf), 0, 0, 1, 0},
  {&__pyx_kp_s_2sch, __pyx_k_2sch, sizeof(__pyx_k_2sch), 0, 0, 1, 0},
  {&__pyx_kp_s_2sci, __pyx_k_2sci, sizeof(__pyx_k_2sci), 0, 0, 1, 0},
  {&__pyx_kp_s_30s_10s_s, __pyx_k_30s_10s_s, sizeof(__pyx_k_30s_10s_s), 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_kp_s_A_pileup_column_A_pileup_column, __pyx_k_A_pileup_column_A_pileup_column, sizeof(__pyx_k_A_pileup_column_A_pileup_column), 0, 0, 1, 0},
  {&__pyx_n_s_AlignedRead, __pyx_k_AlignedRead, sizeof(__pyx_k_AlignedRead), 0, 0, 1, 1},
  {&__pyx_kp_u_Argument_must_be_string_bytes_or, __pyx_k_Argument_must_be_string_bytes_or, sizeof(__pyx_k_Argument_must_be_string_bytes_or), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_must_be_string_or_unico, __pyx_k_Argument_must_be_string_or_unico, sizeof(__pyx_k_Argument_must_be_string_or_unico), 0, 1, 0, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1},
  {&__pyx_kp_s_Bam_index_bin_number, __pyx_k_Bam_index_bin_number, sizeof(__pyx_k_Bam_index_bin_number), 0, 0, 1, 0},
  {&__pyx_kp_s_Binary_flag, __pyx_k_Binary_flag, sizeof(__pyx_k_Binary_flag), 0, 0, 1, 0},
  {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
  {&__pyx_n_s_CIGAR2CODE, __pyx_k_CIGAR2CODE, sizeof(__pyx_k_CIGAR2CODE), 0, 0, 1, 1},
  {&__pyx_n_s_CIGAR_REGEX, __pyx_k_CIGAR_REGEX, sizeof(__pyx_k_CIGAR_REGEX), 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_kp_s_Cigar_entries, __pyx_k_Cigar_entries, sizeof(__pyx_k_Cigar_entries), 0, 0, 1, 0},
  {&__pyx_kp_s_Contig_index, __pyx_k_Contig_index, sizeof(__pyx_k_Contig_index), 0, 0, 1, 0},
  {&__pyx_kp_s_Contig_index_for_mate_pair, __pyx_k_Contig_index_for_mate_pair, sizeof(__pyx_k_Contig_index_for_mate_pair), 0, 0, 1, 0},
  {&__pyx_kp_s_Count_of_cigar_entries, __pyx_k_Count_of_cigar_entries, sizeof(__pyx_k_Count_of_cigar_entries), 0, 0, 1, 0},
  {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 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_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1},
  {&__pyx_n_s_FO, __pyx_k_FO, sizeof(__pyx_k_FO), 0, 0, 1, 1},
  {&__pyx_n_s_GO, __pyx_k_GO, sizeof(__pyx_k_GO), 0, 0, 1, 1},
  {&__pyx_n_s_H, __pyx_k_H, sizeof(__pyx_k_H), 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_IS_PYTHON3, __pyx_k_IS_PYTHON3, sizeof(__pyx_k_IS_PYTHON3), 0, 0, 1, 1},
  {&__pyx_kp_s_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 0, 1, 0},
  {&__pyx_n_s_IndexedReads, __pyx_k_IndexedReads, sizeof(__pyx_k_IndexedReads), 0, 0, 1, 1},
  {&__pyx_kp_s_Insert_size, __pyx_k_Insert_size, sizeof(__pyx_k_Insert_size), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_tag_s, __pyx_k_Invalid_tag_s, sizeof(__pyx_k_Invalid_tag_s), 0, 0, 1, 0},
  {&__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_KS, __pyx_k_KS, sizeof(__pyx_k_KS), 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_kp_s_Length_of_auxilary_data, __pyx_k_Length_of_auxilary_data, sizeof(__pyx_k_Length_of_auxilary_data), 0, 0, 1, 0},
  {&__pyx_kp_s_Length_of_query_name, __pyx_k_Length_of_query_name, sizeof(__pyx_k_Length_of_query_name), 0, 0, 1, 0},
  {&__pyx_kp_s_Length_of_query_sequence, __pyx_k_Length_of_query_sequence, sizeof(__pyx_k_Length_of_query_sequence), 0, 0, 1, 0},
  {&__pyx_n_s_M5, __pyx_k_M5, sizeof(__pyx_k_M5), 0, 0, 1, 1},
  {&__pyx_kp_s_Mapped_position_on_contig, __pyx_k_Mapped_position_on_contig, sizeof(__pyx_k_Mapped_position_on_contig), 0, 0, 1, 0},
  {&__pyx_kp_s_Mapping_quality, __pyx_k_Mapping_quality, sizeof(__pyx_k_Mapping_quality), 0, 0, 1, 0},
  {&__pyx_kp_s_Maximum_data_length, __pyx_k_Maximum_data_length, sizeof(__pyx_k_Maximum_data_length), 0, 0, 1, 0},
  {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
  {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1},
  {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 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_PN, __pyx_k_PN, sizeof(__pyx_k_PN), 0, 0, 1, 1},
  {&__pyx_n_s_PP, __pyx_k_PP, sizeof(__pyx_k_PP), 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_PileupColumn___str, __pyx_k_PileupColumn___str, sizeof(__pyx_k_PileupColumn___str), 0, 0, 1, 1},
  {&__pyx_n_s_PileupProxy, __pyx_k_PileupProxy, sizeof(__pyx_k_PileupProxy), 0, 0, 1, 1},
  {&__pyx_kp_s_PileupProxy_accessed_after_itera, __pyx_k_PileupProxy_accessed_after_itera, sizeof(__pyx_k_PileupProxy_accessed_after_itera), 0, 0, 1, 0},
  {&__pyx_n_s_PileupRead, __pyx_k_PileupRead, sizeof(__pyx_k_PileupRead), 0, 0, 1, 1},
  {&__pyx_kp_s_Position_of_mate_pair, __pyx_k_Position_of_mate_pair, sizeof(__pyx_k_Position_of_mate_pair), 0, 0, 1, 0},
  {&__pyx_kp_s_Quality_scores, __pyx_k_Quality_scores, sizeof(__pyx_k_Quality_scores), 0, 0, 1, 0},
  {&__pyx_kp_s_Query_name, __pyx_k_Query_name, sizeof(__pyx_k_Query_name), 0, 0, 1, 0},
  {&__pyx_kp_s_Query_sequence, __pyx_k_Query_sequence, sizeof(__pyx_k_Query_sequence), 0, 0, 1, 0},
  {&__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_kp_s_SQ_SN_s_LN_s, __pyx_k_SQ_SN_s_LN_s, sizeof(__pyx_k_SQ_SN_s_LN_s), 0, 0, 1, 0},
  {&__pyx_n_s_Samfile, __pyx_k_Samfile, sizeof(__pyx_k_Samfile), 0, 0, 1, 1},
  {&__pyx_kp_s_Samfile_mapped_only_available_in, __pyx_k_Samfile_mapped_only_available_in, sizeof(__pyx_k_Samfile_mapped_only_available_in), 0, 0, 1, 0},
  {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1},
  {&__pyx_kp_s_This_class_cannot_be_instantiate, __pyx_k_This_class_cannot_be_instantiate, sizeof(__pyx_k_This_class_cannot_be_instantiate), 0, 0, 1, 0},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_n_s_UR, __pyx_k_UR, sizeof(__pyx_k_UR), 0, 0, 1, 1},
  {&__pyx_kp_s_Unsupported_value_type_in_set_op, __pyx_k_Unsupported_value_type_in_set_op, sizeof(__pyx_k_Unsupported_value_type_in_set_op), 0, 0, 1, 0},
  {&__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_Zidf, __pyx_k_Zidf, sizeof(__pyx_k_Zidf), 0, 0, 1, 1},
  {&__pyx_kp_s__14, __pyx_k__14, sizeof(__pyx_k__14), 0, 0, 1, 0},
  {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0},
  {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0},
  {&__pyx_kp_s__41, __pyx_k__41, sizeof(__pyx_k__41), 0, 0, 1, 0},
  {&__pyx_kp_s__47, __pyx_k__47, sizeof(__pyx_k__47), 0, 0, 1, 0},
  {&__pyx_kp_b__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 0, 0},
  {&__pyx_kp_s__76, __pyx_k__76, sizeof(__pyx_k__76), 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__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 0, 1, 0},
  {&__pyx_n_s_add_sq_text, __pyx_k_add_sq_text, sizeof(__pyx_k_add_sq_text), 0, 0, 1, 1},
  {&__pyx_n_s_alignment, __pyx_k_alignment, sizeof(__pyx_k_alignment), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_all_2, __pyx_k_all_2, sizeof(__pyx_k_all_2), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_kp_b_bai, __pyx_k_bai, sizeof(__pyx_k_bai), 0, 0, 0, 0},
  {&__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_buildLine, __pyx_k_buildLine, sizeof(__pyx_k_buildLine), 0, 0, 1, 1},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_kp_s_c_2, __pyx_k_c_2, sizeof(__pyx_k_c_2), 0, 0, 1, 0},
  {&__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_kp_s_callback_not_implemented_yet, __pyx_k_callback_not_implemented_yet, sizeof(__pyx_k_callback_not_implemented_yet), 0, 0, 1, 0},
  {&__pyx_kp_s_can_not_iterate_over_samfile_wit, __pyx_k_can_not_iterate_over_samfile_wit, sizeof(__pyx_k_can_not_iterate_over_samfile_wit), 0, 0, 1, 0},
  {&__pyx_kp_s_can_only_IndexReads_on_bam_files, __pyx_k_can_only_IndexReads_on_bam_files, sizeof(__pyx_k_can_only_IndexReads_on_bam_files), 0, 0, 1, 0},
  {&__pyx_kp_s_can_t_guess_type_or_invalid_type, __pyx_k_can_t_guess_type_or_invalid_type, sizeof(__pyx_k_can_t_guess_type_or_invalid_type), 0, 0, 1, 0},
  {&__pyx_n_s_checkIndex, __pyx_k_checkIndex, sizeof(__pyx_k_checkIndex), 0, 0, 1, 1},
  {&__pyx_n_s_check_header, __pyx_k_check_header, sizeof(__pyx_k_check_header), 0, 0, 1, 1},
  {&__pyx_n_s_check_sq, __pyx_k_check_sq, sizeof(__pyx_k_check_sq), 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_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1},
  {&__pyx_n_s_consensus_quality, __pyx_k_consensus_quality, sizeof(__pyx_k_consensus_quality), 0, 0, 1, 1},
  {&__pyx_kp_s_could_not_open_file_mode_s_is_it, __pyx_k_could_not_open_file_mode_s_is_it, sizeof(__pyx_k_could_not_open_file_mode_s_is_it), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_open_file_s, __pyx_k_could_not_open_file_s, sizeof(__pyx_k_could_not_open_file_s), 0, 0, 1, 0},
  {&__pyx_n_s_coverage, __pyx_k_coverage, sizeof(__pyx_k_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_create_string_buffer, __pyx_k_create_string_buffer, sizeof(__pyx_k_create_string_buffer), 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_kp_s_d_MIDNSHP_X, __pyx_k_d_MIDNSHP_X, sizeof(__pyx_k_d_MIDNSHP_X), 0, 0, 1, 0},
  {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1},
  {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1},
  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
  {&__pyx_kp_s_either_supply_options_template_h, __pyx_k_either_supply_options_template_h, sizeof(__pyx_k_either_supply_options_template_h), 0, 0, 1, 0},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_kp_s_end_out_of_range_i, __pyx_k_end_out_of_range_i, sizeof(__pyx_k_end_out_of_range_i), 0, 0, 1, 0},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_kp_s_error_during_iteration, __pyx_k_error_during_iteration, sizeof(__pyx_k_error_during_iteration), 0, 0, 1, 0},
  {&__pyx_kp_s_error_while_opening_index_s, __pyx_k_error_while_opening_index_s, sizeof(__pyx_k_error_while_opening_index_s), 0, 0, 1, 0},
  {&__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_extend, __pyx_k_extend, sizeof(__pyx_k_extend), 0, 0, 1, 1},
  {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1},
  {&__pyx_n_s_fastafile, __pyx_k_fastafile, sizeof(__pyx_k_fastafile), 0, 0, 1, 1},
  {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1},
  {&__pyx_kp_s_fetch_called_for_htsfile_without, __pyx_k_fetch_called_for_htsfile_without, sizeof(__pyx_k_fetch_called_for_htsfile_without), 0, 0, 1, 0},
  {&__pyx_kp_s_fetch_called_on_bamfile_without, __pyx_k_fetch_called_on_bamfile_without, sizeof(__pyx_k_fetch_called_on_bamfile_without), 0, 0, 1, 0},
  {&__pyx_kp_s_fetching_by_region_is_not_availa, __pyx_k_fetching_by_region_is_not_availa, sizeof(__pyx_k_fetching_by_region_is_not_availa), 0, 0, 1, 0},
  {&__pyx_n_s_fields, __pyx_k_fields, sizeof(__pyx_k_fields), 0, 0, 1, 1},
  {&__pyx_kp_s_file_does_not_have_valid_header, __pyx_k_file_does_not_have_valid_header, sizeof(__pyx_k_file_does_not_have_valid_header), 0, 0, 1, 0},
  {&__pyx_kp_s_file_does_not_have_valid_header_2, __pyx_k_file_does_not_have_valid_header_2, sizeof(__pyx_k_file_does_not_have_valid_header_2), 0, 0, 1, 0},
  {&__pyx_kp_s_file_header_is_empty_mode_s_is_i, __pyx_k_file_header_is_empty_mode_s_is_i, sizeof(__pyx_k_file_header_is_empty_mode_s_is_i), 0, 0, 1, 0},
  {&__pyx_kp_s_file_s_not_found, __pyx_k_file_s_not_found, sizeof(__pyx_k_file_s_not_found), 0, 0, 1, 0},
  {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1},
  {&__pyx_n_s_findall, __pyx_k_findall, sizeof(__pyx_k_findall), 0, 0, 1, 1},
  {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1},
  {&__pyx_n_s_fmts, __pyx_k_fmts, sizeof(__pyx_k_fmts), 0, 0, 1, 1},
  {&__pyx_kp_b_ftp, __pyx_k_ftp, sizeof(__pyx_k_ftp), 0, 0, 0, 0},
  {&__pyx_n_s_genotype, __pyx_k_genotype, sizeof(__pyx_k_genotype), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_n_s_getattribute, __pyx_k_getattribute, sizeof(__pyx_k_getattribute), 0, 0, 1, 1},
  {&__pyx_n_s_getdefaultencoding, __pyx_k_getdefaultencoding, sizeof(__pyx_k_getdefaultencoding), 0, 0, 1, 1},
  {&__pyx_n_s_getfilesystemencoding, __pyx_k_getfilesystemencoding, sizeof(__pyx_k_getfilesystemencoding), 0, 0, 1, 1},
  {&__pyx_n_s_gettid, __pyx_k_gettid, sizeof(__pyx_k_gettid), 0, 0, 1, 1},
  {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1},
  {&__pyx_n_s_hasIndex, __pyx_k_hasIndex, sizeof(__pyx_k_hasIndex), 0, 0, 1, 1},
  {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1},
  {&__pyx_kp_s_header_line_with_invalid_type_s, __pyx_k_header_line_with_invalid_type_s, sizeof(__pyx_k_header_line_with_invalid_type_s), 0, 0, 1, 0},
  {&__pyx_kp_s_header_line_without_s, __pyx_k_header_line_without_s, sizeof(__pyx_k_header_line_without_s), 0, 0, 1, 0},
  {&__pyx_kp_s_home_andreas_devel_pysam_pysam, __pyx_k_home_andreas_devel_pysam_pysam, sizeof(__pyx_k_home_andreas_devel_pysam_pysam), 0, 0, 1, 0},
  {&__pyx_kp_b_http, __pyx_k_http, sizeof(__pyx_k_http), 0, 0, 0, 0},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_kp_s_i_c, __pyx_k_i_c, sizeof(__pyx_k_i_c), 0, 0, 1, 0},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_kp_s_incomplete_sequence_information, __pyx_k_incomplete_sequence_information, sizeof(__pyx_k_incomplete_sequence_information), 0, 0, 1, 0},
  {&__pyx_n_s_indel, __pyx_k_indel, sizeof(__pyx_k_indel), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
  {&__pyx_kp_s_integer_i_out_of_range_of_BAM_SA, __pyx_k_integer_i_out_of_range_of_BAM_SA, sizeof(__pyx_k_integer_i_out_of_range_of_BAM_SA), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_coordinates_start_i_end, __pyx_k_invalid_coordinates_start_i_end, sizeof(__pyx_k_invalid_coordinates_start_i_end), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_file_opening_mode_s, __pyx_k_invalid_file_opening_mode_s, sizeof(__pyx_k_invalid_file_opening_mode_s), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_reference_s, __pyx_k_invalid_reference_s, sizeof(__pyx_k_invalid_reference_s), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_k_invalid_type_for_record_s_s_expe, sizeof(__pyx_k_invalid_type_for_record_s_s_expe), 0, 0, 1, 0},
  {&__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_isize, __pyx_k_isize, sizeof(__pyx_k_isize), 0, 0, 1, 1},
  {&__pyx_n_s_islower, __pyx_k_islower, sizeof(__pyx_k_islower), 0, 0, 1, 1},
  {&__pyx_n_s_isupper, __pyx_k_isupper, sizeof(__pyx_k_isupper), 0, 0, 1, 1},
  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 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_data, __pyx_k_l_data, sizeof(__pyx_k_l_data), 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_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 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_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_kp_s_malformatted_header_no_in_field, __pyx_k_malformatted_header_no_in_field, sizeof(__pyx_k_malformatted_header_no_in_field), 0, 0, 1, 0},
  {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1},
  {&__pyx_kp_s_mapping_information_not_recorded, __pyx_k_mapping_information_not_recorded, sizeof(__pyx_k_mapping_information_not_recorded), 0, 0, 1, 0},
  {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1},
  {&__pyx_n_s_mapq, __pyx_k_mapq, sizeof(__pyx_k_mapq), 0, 0, 1, 1},
  {&__pyx_kp_s_mate_not_found, __pyx_k_mate_not_found, sizeof(__pyx_k_mate_not_found), 0, 0, 1, 0},
  {&__pyx_kp_s_mate_s_is_unmapped, __pyx_k_mate_s_is_unmapped, sizeof(__pyx_k_mate_s_is_unmapped), 0, 0, 1, 0},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_max_depth, __pyx_k_max_depth, sizeof(__pyx_k_max_depth), 0, 0, 1, 1},
  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
  {&__pyx_n_s_mpos, __pyx_k_mpos, sizeof(__pyx_k_mpos), 0, 0, 1, 1},
  {&__pyx_n_s_mrnm, __pyx_k_mrnm, sizeof(__pyx_k_mrnm), 0, 0, 1, 1},
  {&__pyx_n_s_mtid, __pyx_k_mtid, sizeof(__pyx_k_mtid), 0, 0, 1, 1},
  {&__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_k_multiple_s_lines_are_not_permitt, sizeof(__pyx_k_multiple_s_lines_are_not_permitt), 0, 0, 1, 0},
  {&__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_nextiter, __pyx_k_nextiter, sizeof(__pyx_k_nextiter), 0, 0, 1, 1},
  {&__pyx_kp_s_no_index_available_for_fetch, __pyx_k_no_index_available_for_fetch, sizeof(__pyx_k_no_index_available_for_fetch), 0, 0, 1, 0},
  {&__pyx_kp_s_no_index_available_for_iteration, __pyx_k_no_index_available_for_iteration, sizeof(__pyx_k_no_index_available_for_iteration), 0, 0, 1, 0},
  {&__pyx_kp_s_no_index_available_for_pileup, __pyx_k_no_index_available_for_pileup, sizeof(__pyx_k_no_index_available_for_pileup), 0, 0, 1, 0},
  {&__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_ord, __pyx_k_ord, sizeof(__pyx_k_ord), 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_parseRegion, __pyx_k_parseRegion, sizeof(__pyx_k_parseRegion), 0, 0, 1, 1},
  {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1},
  {&__pyx_kp_s_pileup_of_samfiles_not_implement, __pyx_k_pileup_of_samfiles_not_implement, sizeof(__pyx_k_pileup_of_samfiles_not_implement), 0, 0, 1, 0},
  {&__pyx_n_s_pileups, __pyx_k_pileups, sizeof(__pyx_k_pileups), 0, 0, 1, 1},
  {&__pyx_n_s_platform, __pyx_k_platform, sizeof(__pyx_k_platform), 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_positions, __pyx_k_positions, sizeof(__pyx_k_positions), 0, 0, 1, 1},
  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
  {&__pyx_n_s_pysam_csamfile, __pyx_k_pysam_csamfile, sizeof(__pyx_k_pysam_csamfile), 0, 0, 1, 1},
  {&__pyx_n_s_pytag, __pyx_k_pytag, sizeof(__pyx_k_pytag), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 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_kp_s_quality_and_sequence_mismatch_i, __pyx_k_quality_and_sequence_mismatch_i, sizeof(__pyx_k_quality_and_sequence_mismatch_i), 0, 0, 1, 0},
  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_rU, __pyx_k_rU, sizeof(__pyx_k_rU), 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_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
  {&__pyx_kp_s_read_s_is_unpaired, __pyx_k_read_s_is_unpaired, sizeof(__pyx_k_read_s_is_unpaired), 0, 0, 1, 0},
  {&__pyx_kp_s_read_s_not_found, __pyx_k_read_s_not_found, sizeof(__pyx_k_read_s_not_found), 0, 0, 1, 0},
  {&__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_reference_base, __pyx_k_reference_base, sizeof(__pyx_k_reference_base), 0, 0, 1, 1},
  {&__pyx_kp_s_reference_sequence_for_s_tid_i_n, __pyx_k_reference_sequence_for_s_tid_i_n, sizeof(__pyx_k_reference_sequence_for_s_tid_i_n), 0, 0, 1, 0},
  {&__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_references, __pyx_k_references, sizeof(__pyx_k_references), 0, 0, 1, 1},
  {&__pyx_n_s_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1},
  {&__pyx_n_s_reopen, __pyx_k_reopen, sizeof(__pyx_k_reopen), 0, 0, 1, 1},
  {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
  {&__pyx_n_s_rlen, __pyx_k_rlen, sizeof(__pyx_k_rlen), 0, 0, 1, 1},
  {&__pyx_n_s_rname, __pyx_k_rname, sizeof(__pyx_k_rname), 0, 0, 1, 1},
  {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0},
  {&__pyx_n_s_s_2, __pyx_k_s_2, sizeof(__pyx_k_s_2), 0, 0, 1, 1},
  {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0},
  {&__pyx_n_s_samfile, __pyx_k_samfile, sizeof(__pyx_k_samfile), 0, 0, 1, 1},
  {&__pyx_n_s_samtools, __pyx_k_samtools, sizeof(__pyx_k_samtools), 0, 0, 1, 1},
  {&__pyx_n_s_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 0, 0, 1, 1},
  {&__pyx_kp_s_seek_no_available_in_streams, __pyx_k_seek_no_available_in_streams, sizeof(__pyx_k_seek_no_available_in_streams), 0, 0, 1, 0},
  {&__pyx_kp_s_seek_only_available_in_bam_files, __pyx_k_seek_only_available_in_bam_files, sizeof(__pyx_k_seek_only_available_in_bam_files), 0, 0, 1, 0},
  {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
  {&__pyx_n_s_setTag, __pyx_k_setTag, sizeof(__pyx_k_setTag), 0, 0, 1, 1},
  {&__pyx_n_s_snp_quality, __pyx_k_snp_quality, sizeof(__pyx_k_snp_quality), 0, 0, 1, 1},
  {&__pyx_n_s_sorted, __pyx_k_sorted, sizeof(__pyx_k_sorted), 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_kp_s_start_out_of_range_i, __pyx_k_start_out_of_range_i, sizeof(__pyx_k_start_out_of_range_i), 0, 0, 1, 0},
  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
  {&__pyx_n_s_stepper, __pyx_k_stepper, sizeof(__pyx_k_stepper), 0, 0, 1, 1},
  {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 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_tag, __pyx_k_tag, sizeof(__pyx_k_tag), 0, 0, 1, 1},
  {&__pyx_kp_s_tag_s_not_present, __pyx_k_tag_s_not_present, sizeof(__pyx_k_tag_s_not_present), 0, 0, 1, 0},
  {&__pyx_n_s_tags, __pyx_k_tags, sizeof(__pyx_k_tags), 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_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 0, 1, 1},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1},
  {&__pyx_kp_s_tid_i_out_of_range_0_tid_i, __pyx_k_tid_i_out_of_range_0_tid_i, sizeof(__pyx_k_tid_i_out_of_range_0_tid_i), 0, 0, 1, 0},
  {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_truncate, __pyx_k_truncate, sizeof(__pyx_k_truncate), 0, 0, 1, 1},
  {&__pyx_n_s_types, __pyx_k_types, sizeof(__pyx_k_types), 0, 0, 1, 1},
  {&__pyx_kp_s_unable_to_open_index_for_s, __pyx_k_unable_to_open_index_for_s, sizeof(__pyx_k_unable_to_open_index_for_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unequal_names_and_lengths_of_ref, __pyx_k_unequal_names_and_lengths_of_ref, sizeof(__pyx_k_unequal_names_and_lengths_of_ref), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_auxilliary_type_s, __pyx_k_unknown_auxilliary_type_s, sizeof(__pyx_k_unknown_auxilliary_type_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_field_code_s_in_record_s, __pyx_k_unknown_field_code_s_in_record_s, sizeof(__pyx_k_unknown_field_code_s_in_record_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_k_unknown_stepper_option_s_in_Iter, sizeof(__pyx_k_unknown_stepper_option_s_in_Iter), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_type_s, __pyx_k_unknown_type_s, sizeof(__pyx_k_unknown_type_s), 0, 0, 1, 0},
  {&__pyx_n_s_until_eof, __pyx_k_until_eof, sizeof(__pyx_k_until_eof), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_s_value_type, __pyx_k_value_type, sizeof(__pyx_k_value_type), 0, 0, 1, 1},
  {&__pyx_n_s_version_info, __pyx_k_version_info, sizeof(__pyx_k_version_info), 0, 0, 1, 1},
  {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1},
  {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1},
  {&__pyx_n_s_warnings, __pyx_k_warnings, sizeof(__pyx_k_warnings), 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_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ord = __Pyx_GetBuiltinName(__pyx_n_s_ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_sorted = __Pyx_GetBuiltinName(__pyx_n_s_sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pysam/csamfile.pyx":66
 *         return s
 *     elif PyUnicode_Check(s):
 *         return s.encode('ascii')             # <<<<<<<<<<<<<<
 *     else:
 *         raise TypeError, u"Argument must be string, bytes or unicode."
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "pysam/csamfile.pyx":87
 *         return s
 *     elif PyBytes_Check(s):
 *         return s.decode('ascii')             # <<<<<<<<<<<<<<
 *     else:
 *         # assume unicode
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "pysam/csamfile.pyx":379
 *             self.close()
 * 
 *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
 *         self._filename = filename = _encodeFilename(filename)
 *         self.isstream = filename == b"-"
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "pysam/csamfile.pyx":385
 *         self.isbam = len(mode) > 1 and mode[1] == 'b'
 * 
 *         self.isremote = filename.startswith(b"http:") or \             # <<<<<<<<<<<<<<
 *                         filename.startswith(b"ftp:")
 * 
 */
  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_b_http); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "pysam/csamfile.pyx":386
 * 
 *         self.isremote = filename.startswith(b"http:") or \
 *                         filename.startswith(b"ftp:")             # <<<<<<<<<<<<<<
 * 
 *         cdef char * ctext
 */
  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_b_ftp); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "pysam/csamfile.pyx":503
 *             if not self.isremote:
 *                 if not os.path.exists(filename + b".bai") \
 *                         and not os.path.exists( filename[:-4] + b".bai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 else:
 */
  __pyx_slice__10 = PySlice_New(Py_None, __pyx_int_neg_4, Py_None); if (unlikely(!__pyx_slice__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__10);
  __Pyx_GIVEREF(__pyx_slice__10);

  /* "pysam/csamfile.pyx":525
 *         '''
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         reference = _forceBytes(reference)
 *         return bam_name2id(self.header, reference)
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "pysam/csamfile.pyx":533
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "pysam/csamfile.pyx":543
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         if not 0 <= tid < self.header.n_targets:
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "pysam/csamfile.pyx":595
 * 
 *         if not reference:
 *             return 0, 0, 0, 0             # <<<<<<<<<<<<<<
 * 
 *         if tid is not None:
 */
  __pyx_tuple__15 = PyTuple_Pack(4, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "pysam/csamfile.pyx":625
 * 
 *         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_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "pysam/csamfile.pyx":627
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
 *         if self.isstream:
 *             raise OSError("seek no available in streams")
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_seek_only_available_in_bam_files); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "pysam/csamfile.pyx":629
 *             raise NotImplementedError("seek only available in bam files")
 *         if self.isstream:
 *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
 * 
 *         return bgzf_seek(self.fp, offset, where)
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_seek_no_available_in_streams); if (unlikely(!__pyx_tuple__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "pysam/csamfile.pyx":638
 *         '''
 *         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_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "pysam/csamfile.pyx":640
 *             raise ValueError( "I/O operation on closed file" )
 *         if not self.isbam:
 *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
 * 
 *         return bgzf_tell(self.fp)
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_seek_only_available_in_bam_files); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "pysam/csamfile.pyx":686
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(reference,
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pysam/csamfile.pyx":700
 *         if self.isbam:
 *             if not until_eof and not self._hasIndex() and not self.isremote:
 *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
 * 
 *             if has_coord:
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_on_bamfile_without); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "pysam/csamfile.pyx":713
 *         else:
 *             if has_coord:
 *                 raise ValueError ("fetching by region is not available for sam files")             # <<<<<<<<<<<<<<
 * 
 *             if callback:
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_fetching_by_region_is_not_availa); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "pysam/csamfile.pyx":716
 * 
 *             if callback:
 *                 raise NotImplementedError("callback not implemented yet")             # <<<<<<<<<<<<<<
 * 
 *             if self.header == NULL:
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_callback_not_implemented_yet); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "pysam/csamfile.pyx":719
 * 
 *             if self.header == NULL:
 *                 raise ValueError("fetch called for htsfile without header")             # <<<<<<<<<<<<<<
 * 
 *             # check if targets are defined
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_for_htsfile_without); if (unlikely(!__pyx_tuple__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "pysam/csamfile.pyx":724
 *             # give warning, sam_read1 segfaults
 *             if self.header.n_targets == 0:
 *                 warnings.warn("fetch called for htsfile without header")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorRowAll(self, reopen=reopen)
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_for_htsfile_without); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "pysam/csamfile.pyx":777
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_mate_not_found); if (unlikely(!__pyx_tuple__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "pysam/csamfile.pyx":802
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         for read in self.fetch(reference=reference,
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "pysam/csamfile.pyx":868
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "pysam/csamfile.pyx":875
 *         if self.isbam:
 *             if not self._hasIndex():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             if has_coord:
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_pileup); if (unlikely(!__pyx_tuple__30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "pysam/csamfile.pyx":887
 * 
 *         else:
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
 * 
 *     def close( self ):
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_pileup_of_samfiles_not_implement); if (unlikely(!__pyx_tuple__31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "pysam/csamfile.pyx":941
 *         '''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.header.n_targets
 * 
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "pysam/csamfile.pyx":947
 *         """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.header.n_targets:
 */
  __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "pysam/csamfile.pyx":958
 *         """
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "pysam/csamfile.pyx":981
 *         an error.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.isbam:
 *             raise AttributeError("Samfile.mapped only available in bam files")
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "pysam/csamfile.pyx":983
 *             raise ValueError("I/O operation on closed file")
 *         if not self.isbam:
 *             raise AttributeError("Samfile.mapped only available in bam files")             # <<<<<<<<<<<<<<
 *         if self.index == NULL:
 *             raise ValueError("mapping information not recorded in index "
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_Samfile_mapped_only_available_in); if (unlikely(!__pyx_tuple__36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "pysam/csamfile.pyx":985
 *             raise AttributeError("Samfile.mapped only available in bam files")
 *         if self.index == NULL:
 *             raise ValueError("mapping information not recorded in index "             # <<<<<<<<<<<<<<
 *                                  "or index not available")
 * 
 */
  __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_mapping_information_not_recorded); if (unlikely(!__pyx_tuple__37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "pysam/csamfile.pyx":1012
 *         '''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 from_string_and_size(self.header.text, self.header.l_text)
 * 
 */
  __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "pysam/csamfile.pyx":1020
 *         '''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *             result = {}
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "pysam/csamfile.pyx":1027
 *                 # 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_tuple__40 = PyTuple_Pack(1, __pyx_kp_s__4); if (unlikely(!__pyx_tuple__40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "pysam/csamfile.pyx":1029
 *                 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]
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s__41); if (unlikely(!__pyx_tuple__42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "pysam/csamfile.pyx":1030
 *                     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_slice__43 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__43);
  __Pyx_GIVEREF(__pyx_slice__43);
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "pysam/csamfile.pyx":1037
 *                     if record == "CO":
 *                         if record not in result: result[record] = []
 *                         result[record].append( "\t".join( fields[1:] ) )             # <<<<<<<<<<<<<<
 *                         continue
 *                     # the following is clumsy as generators do not work?
 */
  __pyx_slice__45 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__45);
  __Pyx_GIVEREF(__pyx_slice__45);

  /* "pysam/csamfile.pyx":1041
 *                     # the following is clumsy as generators do not work?
 *                     x = {}
 *                     for field in fields[1:]:             # <<<<<<<<<<<<<<
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )
 */
  __pyx_slice__46 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__46);
  __Pyx_GIVEREF(__pyx_slice__46);

  /* "pysam/csamfile.pyx":1043
 *                     for field in fields[1:]:
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
 *                         key, value = field.split(":",1)
 *                         # uppercase keys must be valid
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_malformatted_header_no_in_field); if (unlikely(!__pyx_tuple__48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "pysam/csamfile.pyx":1044
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )
 *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
 *                         # uppercase keys must be valid
 *                         # lowercase are permitted for user fields
 */
  __pyx_tuple__49 = PyTuple_Pack(2, __pyx_kp_s__47, __pyx_int_1); if (unlikely(!__pyx_tuple__49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "pysam/csamfile.pyx":1144
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
 *         strncpy( dest.text, btext, dest.l_text )
 * 
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "pysam/csamfile.pyx":1164
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
 *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
 *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
 *                 dest.target_len[x] = seqlen
 */
  __pyx_tuple__51 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "pysam/csamfile.pyx":1180
 *     def __iter__(self):
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         if not self.isbam and self.header.n_targets == 0:
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "pysam/csamfile.pyx":1183
 * 
 *         if not self.isbam and self.header.n_targets == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
  __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_can_not_iterate_over_samfile_wit); if (unlikely(!__pyx_tuple__53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "pysam/csamfile.pyx":1239
 * 
 *         if not samfile._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as the
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "pysam/csamfile.pyx":1298
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
 * 
 *         self.iter = sam_itr_queryi(
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_iteration); if (unlikely(!__pyx_tuple__55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "pysam/csamfile.pyx":1443
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_fetch); if (unlikely(!__pyx_tuple__56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "pysam/csamfile.pyx":1805
 *             self.cnext()
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL:
 */
  __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "pysam/csamfile.pyx":1843
 * 
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             # return result, if within same reference
 */
  __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "pysam/csamfile.pyx":1978
 * 
 *     if not type(pytag) is bytes:
 *         pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
 *     t = type(value)
 * 
 */
  __pyx_tuple__60 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);

  /* "pysam/csamfile.pyx":2005
 * 
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),
 */
  __pyx_slice__61 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__61);
  __Pyx_GIVEREF(__pyx_slice__61);

  /* "pysam/csamfile.pyx":2006
 *         datafmt = "2sccI%i%s" % (len(value), datafmt)
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                       datatype.encode('ascii'),
 *                       len(value)] + list(value) )
 */
  __pyx_tuple__62 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2006; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "pysam/csamfile.pyx":2007
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),
 *                       datatype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                       len(value)] + list(value) )
 *         fmts.append( datafmt )
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);

  /* "pysam/csamfile.pyx":2030
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:
 *             value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *         if len(value) == 1:
 *             fmt, pytype = "2scc", 'A'
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);

  /* "pysam/csamfile.pyx":2036
 *             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 * 
 *     args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                   pytype.encode('ascii'),
 *                   value ] )
 */
  __pyx_slice__65 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__65);
  __Pyx_GIVEREF(__pyx_slice__65);

  /* "pysam/csamfile.pyx":2037
 * 
 *     args.extend( [pytag[:2],
 *                   pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                   value ] )
 * 
 */
  __pyx_tuple__66 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__66)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__66);
  __Pyx_GIVEREF(__pyx_tuple__66);

  /* "pysam/csamfile.pyx":2104
 *             qual = self.qual
 *         else:
 *             seq = self.seq.decode('ascii')             # <<<<<<<<<<<<<<
 *             qual = self.qual.decode('ascii')
 *         return "\t".join(map(str, (self.qname,
 */
  __pyx_tuple__67 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);

  /* "pysam/csamfile.pyx":2105
 *         else:
 *             seq = self.seq.decode('ascii')
 *             qual = self.qual.decode('ascii')             # <<<<<<<<<<<<<<
 *         return "\t".join(map(str, (self.qname,
 *                                    self.flag,
 */
  __pyx_tuple__68 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);

  /* "pysam/csamfile.pyx":2156
 * 
 *         if not type(pytag) is bytes:
 *             pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
 *         t = type(value)
 * 
 */
  __pyx_tuple__69 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);

  /* "pysam/csamfile.pyx":2183
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 *             args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),
 */
  __pyx_slice__70 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__70);
  __Pyx_GIVEREF(__pyx_slice__70);

  /* "pysam/csamfile.pyx":2184
 *             datafmt = "2sccI%i%s" % (len(value), datafmt)
 *             args.extend( [pytag[:2],
 *                           pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                           datatype.encode('ascii'),
 *                           len(value)] + list(value) )
 */
  __pyx_tuple__71 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);

  /* "pysam/csamfile.pyx":2185
 *             args.extend( [pytag[:2],
 *                           pytype.encode('ascii'),
 *                           datatype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                           len(value)] + list(value) )
 *             fmts.append( datafmt )
 */
  __pyx_tuple__72 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__72);
  __Pyx_GIVEREF(__pyx_tuple__72);

  /* "pysam/csamfile.pyx":2208
 *             # Note: hex strings (H) are not supported yet
 *             if t is not bytes:
 *                 value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *             if len(value) == 1:
 *                 fmt, pytype = "2scc", 'A'
 */
  __pyx_tuple__73 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);

  /* "pysam/csamfile.pyx":2214
 *                 fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
 * 
 *         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
 *                       pytype.encode('ascii'),
 *                       value ] )
 */
  __pyx_slice__74 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__74)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__74);
  __Pyx_GIVEREF(__pyx_slice__74);

  /* "pysam/csamfile.pyx":2215
 * 
 *         args.extend( [pytag[:2],
 *                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
 *                       value ] )
 * 
 */
  __pyx_tuple__75 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);

  /* "pysam/csamfile.pyx":2731
 *         type_code = get_type_code(value, value_type)
 *         if type_code == 0:
 *             raise ValueError("can't guess type or invalid type code specified")             # <<<<<<<<<<<<<<
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 */
  __pyx_tuple__77 = PyTuple_Pack(1, __pyx_kp_s_can_t_guess_type_or_invalid_type); if (unlikely(!__pyx_tuple__77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);

  /* "pysam/csamfile.pyx":2751
 *             value_size   = sizeof(float)
 *         else:
 *             raise ValueError('Unsupported value_type in set_option')             # <<<<<<<<<<<<<<
 * 
 *         tag = _forceBytes( tag )
 */
  __pyx_tuple__78 = PyTuple_Pack(1, __pyx_kp_s_Unsupported_value_type_in_set_op); if (unlikely(!__pyx_tuple__78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);

  /* "pysam/csamfile.pyx":3253
 *     '''
 *     def __init__(self):
 *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_tuple__81 = PyTuple_Pack(1, __pyx_kp_s_This_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__81)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);

  /* "pysam/csamfile.pyx":3279
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 *                 raise ValueError("PileupProxy accessed after iterator finished")             # <<<<<<<<<<<<<<
 * 
 *             # warning: there could be problems if self.n and self.buf are
 */
  __pyx_tuple__82 = PyTuple_Pack(1, __pyx_kp_s_PileupProxy_accessed_after_itera); if (unlikely(!__pyx_tuple__82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);

  /* "pysam/csamfile.pyx":3292
 * 
 *     def __init__(self):
 *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_s_This_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);

  /* "pysam/csamfile.pyx":108
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_tuple__84 = PyTuple_Pack(1, __pyx_kp_s_d_MIDNSHP_X); if (unlikely(!__pyx_tuple__84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);

  /* "pysam/csamfile.pyx":210
 *         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_tuple__85 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__85);
  __Pyx_GIVEREF(__pyx_tuple__85);
  __pyx_codeobj__86 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__85, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_andreas_devel_pysam_pysam, __pyx_n_s_str, 210, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":223
 * 
 * # order of records within sam headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # type conversions within sam header records
 */
  __pyx_tuple__87 = PyTuple_Pack(5, __pyx_n_s_HD, __pyx_n_s_SQ, __pyx_n_s_RG, __pyx_n_s_PG, __pyx_n_s_CO); if (unlikely(!__pyx_tuple__87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);

  /* "pysam/csamfile.pyx":237
 * 
 * # output order of fields within records
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 */
  __pyx_tuple__88 = PyTuple_Pack(3, __pyx_n_s_VN, __pyx_n_s_SO, __pyx_n_s_GO); if (unlikely(!__pyx_tuple__88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__88);
  __Pyx_GIVEREF(__pyx_tuple__88);

  /* "pysam/csamfile.pyx":238
 * # 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",
 */
  __pyx_tuple__89 = PyTuple_Pack(6, __pyx_n_s_SN, __pyx_n_s_LN, __pyx_n_s_AS, __pyx_n_s_M5, __pyx_n_s_UR, __pyx_n_s_SP); if (unlikely(!__pyx_tuple__89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__89);
  __Pyx_GIVEREF(__pyx_tuple__89);

  /* "pysam/csamfile.pyx":240
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 *                       "RG" : ("ID", "SM", "LB", "DS",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 */
  __pyx_tuple__90 = PyTuple_Pack(12, __pyx_n_s_ID, __pyx_n_s_SM, __pyx_n_s_LB, __pyx_n_s_DS, __pyx_n_s_PU, __pyx_n_s_PI, __pyx_n_s_CN, __pyx_n_s_DT, __pyx_n_s_PL, __pyx_n_s_FO, __pyx_n_s_KS, __pyx_n_s_PG); if (unlikely(!__pyx_tuple__90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__90);
  __Pyx_GIVEREF(__pyx_tuple__90);

  /* "pysam/csamfile.pyx":243
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 *                       "PG" : ("PN", "ID", "VN", "CL",             # <<<<<<<<<<<<<<
 *                               "PP"),}
 * 
 */
  __pyx_tuple__91 = PyTuple_Pack(5, __pyx_n_s_PN, __pyx_n_s_ID, __pyx_n_s_VN, __pyx_n_s_CL, __pyx_n_s_PP); if (unlikely(!__pyx_tuple__91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__91);
  __Pyx_GIVEREF(__pyx_tuple__91);
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  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_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__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_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_65535 = PyInt_FromLong(65535L); if (unlikely(!__pyx_int_65535)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_536870912 = PyInt_FromLong(536870912L); if (unlikely(!__pyx_int_536870912)) {__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_4 = PyInt_FromLong(-4); if (unlikely(!__pyx_int_neg_4)) {__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_neg_32767 = PyInt_FromLong(-32767L); if (unlikely(!__pyx_int_neg_32767)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_2147483648 = PyInt_FromLong(-2147483648L); 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 initcsamfile(void); /*proto*/
PyMODINIT_FUNC initcsamfile(void)
#else
PyMODINIT_FUNC PyInit_csamfile(void); /*proto*/
PyMODINIT_FUNC PyInit_csamfile(void)
#endif
{
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __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");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_csamfile(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __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_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_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("csamfile"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  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 PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_pysam__csamfile) {
    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;};
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "pysam.csamfile")) {
      if (unlikely(PyDict_SetItemString(modules, "pysam.csamfile", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_5pysam_8csamfile__FILENAME_ENCODING = ((PyObject*)Py_None); Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_5pysam_8csamfile_AlignedRead = &__pyx_vtable_5pysam_8csamfile_AlignedRead;
  __pyx_vtable_5pysam_8csamfile_AlignedRead.setTag = (PyObject *(*)(struct __pyx_obj_5pysam_8csamfile_AlignedRead *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_8csamfile_11AlignedRead_setTag *__pyx_optional_args))__pyx_f_5pysam_8csamfile_11AlignedRead_setTag;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_AlignedRead.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_AlignedRead, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_11AlignedRead_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_11AlignedRead_4__str__.doc = __pyx_doc_5pysam_8csamfile_11AlignedRead_4__str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_11AlignedRead_4__str__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_AlignedRead.tp_dict, __pyx_vtabptr_5pysam_8csamfile_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "AlignedRead", (PyObject *)&__pyx_type_5pysam_8csamfile_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_AlignedRead = &__pyx_type_5pysam_8csamfile_AlignedRead;
  __pyx_vtabptr_5pysam_8csamfile_Samfile = &__pyx_vtable_5pysam_8csamfile_Samfile;
  __pyx_vtable_5pysam_8csamfile_Samfile._buildHeader = (bam_hdr_t *(*)(struct __pyx_obj_5pysam_8csamfile_Samfile *, PyObject *))__pyx_f_5pysam_8csamfile_7Samfile__buildHeader;
  __pyx_vtable_5pysam_8csamfile_Samfile.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_8csamfile_Samfile *))__pyx_f_5pysam_8csamfile_7Samfile_getCurrent;
  __pyx_vtable_5pysam_8csamfile_Samfile.cnext = (int (*)(struct __pyx_obj_5pysam_8csamfile_Samfile *))__pyx_f_5pysam_8csamfile_7Samfile_cnext;
  __pyx_vtable_5pysam_8csamfile_Samfile.write = (int (*)(struct __pyx_obj_5pysam_8csamfile_Samfile *, struct __pyx_obj_5pysam_8csamfile_AlignedRead *, int __pyx_skip_dispatch))__pyx_f_5pysam_8csamfile_7Samfile_write;
  __pyx_vtable_5pysam_8csamfile_Samfile._getrname = (char *(*)(struct __pyx_obj_5pysam_8csamfile_Samfile *, int))__pyx_f_5pysam_8csamfile_7Samfile__getrname;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_Samfile.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_Samfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_7Samfile_46__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_7Samfile_46__next__.doc = __pyx_doc_5pysam_8csamfile_7Samfile_46__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_7Samfile_46__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_Samfile.tp_dict, __pyx_vtabptr_5pysam_8csamfile_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "Samfile", (PyObject *)&__pyx_type_5pysam_8csamfile_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_Samfile = &__pyx_type_5pysam_8csamfile_Samfile;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_PileupProxy.tp_print = 0;
  if (__Pyx_SetAttrString(__pyx_m, "PileupProxy", (PyObject *)&__pyx_type_5pysam_8csamfile_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_PileupProxy = &__pyx_type_5pysam_8csamfile_PileupProxy;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_PileupRead.tp_print = 0;
  if (__Pyx_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_8csamfile_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_PileupRead = &__pyx_type_5pysam_8csamfile_PileupRead;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorRow.tp_print = 0;
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorRow = &__pyx_type_5pysam_8csamfile_IteratorRow;
  __pyx_vtabptr_5pysam_8csamfile_IteratorRowRegion = &__pyx_vtable_5pysam_8csamfile_IteratorRowRegion;
  __pyx_vtable_5pysam_8csamfile_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *))__pyx_f_5pysam_8csamfile_17IteratorRowRegion_getCurrent;
  __pyx_vtable_5pysam_8csamfile_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowRegion *))__pyx_f_5pysam_8csamfile_17IteratorRowRegion_cnext;
  __pyx_type_5pysam_8csamfile_IteratorRowRegion.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorRowRegion.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_17IteratorRowRegion_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_17IteratorRowRegion_4__next__.doc = __pyx_doc_5pysam_8csamfile_17IteratorRowRegion_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_17IteratorRowRegion_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorRowRegion = &__pyx_type_5pysam_8csamfile_IteratorRowRegion;
  __pyx_vtabptr_5pysam_8csamfile_IteratorRowHead = &__pyx_vtable_5pysam_8csamfile_IteratorRowHead;
  __pyx_vtable_5pysam_8csamfile_IteratorRowHead.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *))__pyx_f_5pysam_8csamfile_15IteratorRowHead_getCurrent;
  __pyx_vtable_5pysam_8csamfile_IteratorRowHead.cnext = (int (*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowHead *))__pyx_f_5pysam_8csamfile_15IteratorRowHead_cnext;
  __pyx_type_5pysam_8csamfile_IteratorRowHead.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorRowHead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorRowHead.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowHead, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_15IteratorRowHead_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_15IteratorRowHead_4__next__.doc = __pyx_doc_5pysam_8csamfile_15IteratorRowHead_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_15IteratorRowHead_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorRowHead.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorRowHead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowHead", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowHead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorRowHead = &__pyx_type_5pysam_8csamfile_IteratorRowHead;
  __pyx_vtabptr_5pysam_8csamfile_IteratorRowAll = &__pyx_vtable_5pysam_8csamfile_IteratorRowAll;
  __pyx_vtable_5pysam_8csamfile_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *))__pyx_f_5pysam_8csamfile_14IteratorRowAll_getCurrent;
  __pyx_vtable_5pysam_8csamfile_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowAll *))__pyx_f_5pysam_8csamfile_14IteratorRowAll_cnext;
  __pyx_type_5pysam_8csamfile_IteratorRowAll.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorRowAll.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_14IteratorRowAll_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_14IteratorRowAll_4__next__.doc = __pyx_doc_5pysam_8csamfile_14IteratorRowAll_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_14IteratorRowAll_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorRowAll = &__pyx_type_5pysam_8csamfile_IteratorRowAll;
  __pyx_type_5pysam_8csamfile_IteratorRowAllRefs.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorRowAllRefs.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_18IteratorRowAllRefs_6__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_18IteratorRowAllRefs_6__next__.doc = __pyx_doc_5pysam_8csamfile_18IteratorRowAllRefs_6__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_18IteratorRowAllRefs_6__next__;
    }
  }
  #endif
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorRowAllRefs = &__pyx_type_5pysam_8csamfile_IteratorRowAllRefs;
  __pyx_vtabptr_5pysam_8csamfile_IteratorRowSelection = &__pyx_vtable_5pysam_8csamfile_IteratorRowSelection;
  __pyx_vtable_5pysam_8csamfile_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *))__pyx_f_5pysam_8csamfile_20IteratorRowSelection_getCurrent;
  __pyx_vtable_5pysam_8csamfile_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_5pysam_8csamfile_IteratorRowSelection *))__pyx_f_5pysam_8csamfile_20IteratorRowSelection_cnext;
  __pyx_type_5pysam_8csamfile_IteratorRowSelection.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorRowSelection.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowSelection, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_20IteratorRowSelection_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_20IteratorRowSelection_4__next__.doc = __pyx_doc_5pysam_8csamfile_20IteratorRowSelection_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_20IteratorRowSelection_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorRowSelection = &__pyx_type_5pysam_8csamfile_IteratorRowSelection;
  __pyx_vtabptr_5pysam_8csamfile_IteratorColumn = &__pyx_vtable_5pysam_8csamfile_IteratorColumn;
  __pyx_vtable_5pysam_8csamfile_IteratorColumn.cnext = (int (*)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *))__pyx_f_5pysam_8csamfile_14IteratorColumn_cnext;
  __pyx_vtable_5pysam_8csamfile_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *))__pyx_f_5pysam_8csamfile_14IteratorColumn_getSequence;
  __pyx_vtable_5pysam_8csamfile_IteratorColumn.setMask = (PyObject *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *, PyObject *))__pyx_f_5pysam_8csamfile_14IteratorColumn_setMask;
  __pyx_vtable_5pysam_8csamfile_IteratorColumn.setupIteratorData = (PyObject *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_8csamfile_14IteratorColumn_setupIteratorData *__pyx_optional_args))__pyx_f_5pysam_8csamfile_14IteratorColumn_setupIteratorData;
  __pyx_vtable_5pysam_8csamfile_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_5pysam_8csamfile_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_5pysam_8csamfile_14IteratorColumn_reset;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorColumn.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorColumn = &__pyx_type_5pysam_8csamfile_IteratorColumn;
  __pyx_vtabptr_5pysam_8csamfile_IteratorColumnRegion = &__pyx_vtable_5pysam_8csamfile_IteratorColumnRegion;
  __pyx_vtable_5pysam_8csamfile_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_5pysam_8csamfile_IteratorColumn;
  __pyx_type_5pysam_8csamfile_IteratorColumnRegion.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorColumnRegion.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorColumnRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_20IteratorColumnRegion_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_20IteratorColumnRegion_2__next__.doc = __pyx_doc_5pysam_8csamfile_20IteratorColumnRegion_2__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_20IteratorColumnRegion_2__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorColumnRegion = &__pyx_type_5pysam_8csamfile_IteratorColumnRegion;
  __pyx_vtabptr_5pysam_8csamfile_IteratorColumnAllRefs = &__pyx_vtable_5pysam_8csamfile_IteratorColumnAllRefs;
  __pyx_vtable_5pysam_8csamfile_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_5pysam_8csamfile_IteratorColumn;
  __pyx_type_5pysam_8csamfile_IteratorColumnAllRefs.tp_base = __pyx_ptype_5pysam_8csamfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IteratorColumnAllRefs.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_5pysam_8csamfile_IteratorColumnAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__.doc = __pyx_doc_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_8csamfile_21IteratorColumnAllRefs_2__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_8csamfile_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_8csamfile_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_5pysam_8csamfile_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IteratorColumnAllRefs = &__pyx_type_5pysam_8csamfile_IteratorColumnAllRefs;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_IndexedReads.tp_print = 0;
  if (__Pyx_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_5pysam_8csamfile_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3381; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_IndexedReads = &__pyx_type_5pysam_8csamfile_IndexedReads;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile_SNPCall.tp_print = 0;
  if (__Pyx_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_5pysam_8csamfile_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_8csamfile_SNPCall = &__pyx_type_5pysam_8csamfile_SNPCall;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile___pyx_scope_struct__genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile___pyx_scope_struct__genexpr.tp_print = 0;
  __pyx_ptype_5pysam_8csamfile___pyx_scope_struct__genexpr = &__pyx_type_5pysam_8csamfile___pyx_scope_struct__genexpr;
  if (PyType_Ready(&__pyx_type_5pysam_8csamfile___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_8csamfile___pyx_scope_struct_1_genexpr.tp_print = 0;
  __pyx_ptype_5pysam_8csamfile___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_8csamfile___pyx_scope_struct_1_genexpr;
  /*--- Type import code ---*/
  __pyx_ptype_5pysam_6cfaidx_Fastafile = __Pyx_ImportType("pysam.cfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqProxy = __Pyx_ImportType("pysam.cfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqProxy)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastqfile = __Pyx_ImportType("pysam.cfaidx", "Fastqfile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastqfile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastqfile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastqfile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastqfile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastqfile)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "pysam/csamfile.pyx":4
 * # cython: profile=True
 * # adds doc-strings for sphinx
 * import tempfile             # <<<<<<<<<<<<<<
 * import os
 * import sys
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":5
 * # adds doc-strings for sphinx
 * import tempfile
 * import os             # <<<<<<<<<<<<<<
 * import sys
 * import types
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); 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 (PyDict_SetItem(__pyx_d, __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;

  /* "pysam/csamfile.pyx":6
 * import tempfile
 * import os
 * import sys             # <<<<<<<<<<<<<<
 * import types
 * import itertools
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":7
 * import os
 * import sys
 * import types             # <<<<<<<<<<<<<<
 * import itertools
 * import struct
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_types, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_types, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":8
 * import sys
 * import types
 * import itertools             # <<<<<<<<<<<<<<
 * import struct
 * import ctypes
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_itertools, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itertools, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":9
 * import types
 * import itertools
 * import struct             # <<<<<<<<<<<<<<
 * import ctypes
 * import collections
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":10
 * import itertools
 * import struct
 * import ctypes             # <<<<<<<<<<<<<<
 * import collections
 * import re
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_ctypes, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctypes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":11
 * import struct
 * import ctypes
 * import collections             # <<<<<<<<<<<<<<
 * import re
 * import platform
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":12
 * import ctypes
 * import collections
 * import re             # <<<<<<<<<<<<<<
 * import platform
 * import warnings
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":13
 * import collections
 * import re
 * import platform             # <<<<<<<<<<<<<<
 * import warnings
 * from cpython cimport PyErr_SetString, \
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_platform, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_platform, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":14
 * import re
 * import platform
 * import warnings             # <<<<<<<<<<<<<<
 * from cpython cimport PyErr_SetString, \
 *     PyBytes_Check, \
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_warnings, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":27
 * ## Python 3 compatibility functions
 * ########################################################################
 * IS_PYTHON3 = PY_MAJOR_VERSION >= 3             # <<<<<<<<<<<<<<
 * cdef from_string_and_size(char* s, size_t length):
 *     if PY_MAJOR_VERSION < 3:
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong((PY_MAJOR_VERSION >= 3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_IS_PYTHON3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":36
 * # filename encoding (copied from lxml.etree.pyx)
 * cdef str _FILENAME_ENCODING
 * _FILENAME_ENCODING = sys.getfilesystemencoding()             # <<<<<<<<<<<<<<
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __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_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_XGOTREF(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING);
  __Pyx_DECREF_SET(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING, ((PyObject*)__pyx_t_1));
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":37
 * cdef str _FILENAME_ENCODING
 * _FILENAME_ENCODING = sys.getfilesystemencoding()
 * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:
 */
  __pyx_t_3 = (__pyx_v_5pysam_8csamfile__FILENAME_ENCODING == ((PyObject*)Py_None));
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "pysam/csamfile.pyx":38
 * _FILENAME_ENCODING = sys.getfilesystemencoding()
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()             # <<<<<<<<<<<<<<
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = 'ascii'
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getdefaultencoding); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __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_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XGOTREF(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING);
    __Pyx_DECREF_SET(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING, ((PyObject*)__pyx_t_1));
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "pysam/csamfile.pyx":39
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
 *     _FILENAME_ENCODING = 'ascii'
 * 
 */
  __pyx_t_4 = (__pyx_v_5pysam_8csamfile__FILENAME_ENCODING == ((PyObject*)Py_None));
  __pyx_t_3 = (__pyx_t_4 != 0);
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":40
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = 'ascii'             # <<<<<<<<<<<<<<
 * 
 * #cdef char* _C_FILENAME_ENCODING
 */
    __Pyx_INCREF(__pyx_n_s_ascii);
    __Pyx_XGOTREF(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING);
    __Pyx_DECREF_SET(__pyx_v_5pysam_8csamfile__FILENAME_ENCODING, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/csamfile.pyx":103
 * DEF SEEK_END = 2
 * 
 * cdef char* CODE2CIGAR= "MIDNSHP=X"             # <<<<<<<<<<<<<<
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 */
  __pyx_v_5pysam_8csamfile_CODE2CIGAR = __pyx_k_MIDNSHP_X;

  /* "pysam/csamfile.pyx":104
 * 
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:             # <<<<<<<<<<<<<<
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 * else:
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_IS_PYTHON3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __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 = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "pysam/csamfile.pyx":105
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 */
    __pyx_t_1 = __pyx_pf_5pysam_8csamfile_genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __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 = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/csamfile.pyx":107
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
 * 
 */
    __pyx_t_1 = __pyx_pf_5pysam_8csamfile_3genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __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 = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L4:;

  /* "pysam/csamfile.pyx":108
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __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_PyObject_Call(__pyx_t_2, __pyx_tuple__84, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_REGEX, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":112
 * #####################################################################
 * # hard-coded constants
 * cdef int max_pos = 2 << 29             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_v_5pysam_8csamfile_max_pos = 1073741824;

  /* "pysam/csamfile.pyx":197
 * 
 * 
 * class PileupColumn(object):             # <<<<<<<<<<<<<<
 *     '''A pileup column. A pileup column contains
 *     all the reads that map to a certain target base.
 */
  __pyx_t_1 = PyTuple_New(1); 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(__pyx_builtin_object);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_builtin_object);
  __Pyx_GIVEREF(__pyx_builtin_object);
  __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_PileupColumn, __pyx_n_s_PileupColumn, (PyObject *) NULL, __pyx_n_s_pysam_csamfile, __pyx_kp_s_A_pileup_column_A_pileup_column); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/csamfile.pyx":210
 *         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_6 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_8csamfile_12PileupColumn_1__str__, 0, __pyx_n_s_PileupColumn___str, NULL, __pyx_n_s_pysam_csamfile, PyModule_GetDict(__pyx_m), ((PyObject *)__pyx_codeobj__86)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyObject_SetItem(__pyx_t_5, __pyx_n_s_str, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/csamfile.pyx":197
 * 
 * 
 * class PileupColumn(object):             # <<<<<<<<<<<<<<
 *     '''A pileup column. A pileup column contains
 *     all the reads that map to a certain target base.
 */
  __pyx_t_6 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_PileupColumn, __pyx_t_1, __pyx_t_5, NULL, 0, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_PileupColumn, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":216
 * 
 * # 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 = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, ((PyObject *)((PyObject*)(&PyDict_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":217
 * # valid types for sam headers
 * VALID_HEADER_TYPES = {"HD" : dict,
 *                       "SQ" : list,             # <<<<<<<<<<<<<<
 *                       "RG" : list,
 *                       "PG" : list,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":218
 * VALID_HEADER_TYPES = {"HD" : dict,
 *                       "SQ" : list,
 *                       "RG" : list,             # <<<<<<<<<<<<<<
 *                       "PG" : list,
 *                       "CO" : list}
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":219
 *                       "SQ" : list,
 *                       "RG" : list,
 *                       "PG" : list,             # <<<<<<<<<<<<<<
 *                       "CO" : list}
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":220
 *                       "RG" : list,
 *                       "PG" : list,
 *                       "CO" : list}             # <<<<<<<<<<<<<<
 * 
 * # order of records within sam headers
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_CO, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_TYPES, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":223
 * 
 * # order of records within sam headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # type conversions within sam header records
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADERS, __pyx_tuple__87) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":226
 * 
 * # 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, "SP" : str, "UR" : str,},
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_VN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SO, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_GO, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":227
 * # 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, "SP" : str, "UR" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_LN, ((PyObject *)((PyObject*)(&PyInt_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_AS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":228
 * VALID_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,},             # <<<<<<<<<<<<<<
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_M5, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SP, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_UR, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":229
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,             # <<<<<<<<<<<<<<
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_ID, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_CN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_DS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":230
 *                                "M5" : str, "SP" : str, "UR" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,             # <<<<<<<<<<<<<<
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PU" : str, "SM" : str,},
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_DT, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_FO, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_KS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":231
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,             # <<<<<<<<<<<<<<
 *                                "PL" : str, "PU" : str, "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_LB, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PG, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PI, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":232
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PU" : str, "SM" : str,},             # <<<<<<<<<<<<<<
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PL, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PU, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SM, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/csamfile.pyx":233
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PU" : str, "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,             # <<<<<<<<<<<<<<
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_ID, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_CL, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":234
 *                                "PL" : str, "PU" : str, "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}             # <<<<<<<<<<<<<<
 * 
 * # output order of fields within records
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PP, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_DS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_VN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_FIELDS, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":237
 * 
 * # output order of fields within records
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_tuple__88) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":238
 * # 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",
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, __pyx_tuple__89) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":240
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 *                       "RG" : ("ID", "SM", "LB", "DS",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_tuple__90) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/csamfile.pyx":243
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 *                       "PG" : ("PN", "ID", "VN", "CL",             # <<<<<<<<<<<<<<
 *                               "PP"),}
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_tuple__91) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_ORDER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.pyx":1788
 *                   int tid = 0,
 *                   int start = 0,
 *                   int end = max_pos,             # <<<<<<<<<<<<<<
 *                   int truncate = False,
 *                   **kwargs ):
 */
  __pyx_k__57 = __pyx_v_5pysam_8csamfile_max_pos;

  /* "pysam/csamfile.pyx":3450
 *             hts_close(self.htsfile)
 * 
 * __all__ = ["Samfile",             # <<<<<<<<<<<<<<
 *            "IteratorRow",
 *            "IteratorColumn",
 */
  __pyx_t_1 = PyList_New(8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_Samfile);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Samfile);
  __Pyx_GIVEREF(__pyx_n_s_Samfile);
  __Pyx_INCREF(__pyx_n_s_IteratorRow);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_IteratorRow);
  __Pyx_GIVEREF(__pyx_n_s_IteratorRow);
  __Pyx_INCREF(__pyx_n_s_IteratorColumn);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_IteratorColumn);
  __Pyx_GIVEREF(__pyx_n_s_IteratorColumn);
  __Pyx_INCREF(__pyx_n_s_AlignedRead);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_AlignedRead);
  __Pyx_GIVEREF(__pyx_n_s_AlignedRead);
  __Pyx_INCREF(__pyx_n_s_PileupColumn);
  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_PileupColumn);
  __Pyx_GIVEREF(__pyx_n_s_PileupColumn);
  __Pyx_INCREF(__pyx_n_s_PileupProxy);
  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_PileupProxy);
  __Pyx_GIVEREF(__pyx_n_s_PileupProxy);
  __Pyx_INCREF(__pyx_n_s_PileupRead);
  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_s_PileupRead);
  __Pyx_GIVEREF(__pyx_n_s_PileupRead);
  __Pyx_INCREF(__pyx_n_s_IndexedReads);
  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_s_IndexedReads);
  __Pyx_GIVEREF(__pyx_n_s_IndexedReads);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/csamfile.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(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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);
  if (__pyx_m) {
    __Pyx_AddTraceback("init pysam.csamfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysam.csamfile");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */
#if CYTHON_REFNANNY
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;
}
#endif /* CYTHON_REFNANNY */

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    int retval;
    PyThreadState* tstate = PyThreadState_GET();
    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
        if (*code == NULL) {
            *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
            if (*code == NULL) return 0;
        }
        *frame = PyFrame_New(
            tstate,                          /*PyThreadState *tstate*/
            *code,                           /*PyCodeObject *code*/
            __pyx_d,                  /*PyObject *globals*/
            0                                /*PyObject *locals*/
        );
        if (*frame == NULL) return 0;
        if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
            Py_INCREF(Py_None);
            (*frame)->f_trace = Py_None;
        }
#if PY_VERSION_HEX < 0x030400B1
    } else {
        (*frame)->f_tstate = tstate;
#endif
    }
    (*frame)->f_lineno = firstlineno;
    tstate->use_tracing = 0;
    #if CYTHON_TRACE
    if (tstate->c_tracefunc)
        tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL);
    if (!tstate->c_profilefunc)
        retval = 1;
    else
    #endif
        retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
    tstate->use_tracing = (tstate->c_profilefunc ||
                           (CYTHON_TRACE && tstate->c_tracefunc));
    return tstate->use_tracing && retval;
}
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 */

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
#if PY_VERSION_HEX >= 0x02060000
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
#endif
    result = (*call)(func, arg, kw);
#if PY_VERSION_HEX >= 0x02060000
    Py_LeaveRecursiveCall();
#endif
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        length = strlen(cstring);
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    length = stop - start;
    if (unlikely(length <= 0))
        return PyUnicode_FromUnicode(NULL, 0);
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    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);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    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;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    #if PY_VERSION_HEX < 0x02050000
    if (PyClass_Check(type)) {
    #else
    if (PyType_Check(type)) {
    #endif
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        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, PyObject *cause) {
    PyObject* owned_instance = NULL;
    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)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                if (PyObject_IsSubclass(instance_class, type)) {
                    type = instance_class;
                } else {
                    instance_class = NULL;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    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:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(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;
}

#if !CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL)
}
#endif

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CPYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        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_AsString(kw_name));
        #endif
}

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;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

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 *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";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    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);
#else
    PyErr_GetExcInfo(type, value, tb);
#endif
}
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    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);
#else
    PyErr_SetExcInfo(type, value, tb);
#endif
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    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;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    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;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    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 int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        #if CYTHON_PEP393_ENABLED
        if (unlikely(PyUnicode_READY(s1) < 0) || unlikely(PyUnicode_READY(s2) < 0))
            return -1;
        #endif
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, length * kind);
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

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;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (result) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (PyErr_ExceptionMatches(PyExc_OverflowError))
                    PyErr_Clear();
                else
                    goto bad;
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #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 void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            return NULL;
        value = default_value;
    }
    Py_INCREF(value);
#else
    if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
        value = PyDict_GetItem(d, key);
        if (unlikely(!value)) {
            value = default_value;
        }
        Py_INCREF(value);
    } else {
        if (default_value == Py_None)
            default_value = NULL;
        value = PyObject_CallMethodObjArgs(
            d, __pyx_n_s_get, key, default_value, NULL);
    }
#endif
    return value;
}

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_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

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_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
    for (i=0; i < nbases; i++) {
        PyTypeObject *tmptype;
        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
        tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
        if (tmptype == &PyClass_Type)
            continue;
#endif
        if (!metaclass) {
            metaclass = tmptype;
            continue;
        }
        if (PyType_IsSubtype(metaclass, tmptype))
            continue;
        if (PyType_IsSubtype(tmptype, metaclass)) {
            metaclass = tmptype;
            continue;
        }
        PyErr_SetString(PyExc_TypeError,
                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");
        return NULL;
    }
    if (!metaclass) {
#if PY_MAJOR_VERSION < 3
        metaclass = &PyClass_Type;
#else
        metaclass = &PyType_Type;
#endif
    }
    Py_INCREF((PyObject*) metaclass);
    return (PyObject*) metaclass;
}

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
    if (unlikely(op->func_doc == NULL)) {
        if (op->func.m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
#else
            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
#endif
            if (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
    }
    Py_INCREF(op->func_doc);
    return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp = op->func_doc;
    if (value == NULL)
        value = Py_None; /* Mark as deleted */
    Py_INCREF(value);
    op->func_doc = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
{
    if (unlikely(op->func_name == NULL)) {
#if PY_MAJOR_VERSION >= 3
        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    Py_INCREF(op->func_name);
    return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = op->func_name;
    Py_INCREF(value);
    op->func_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = op->func_qualname;
    Py_INCREF(value);
    op->func_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
{
    PyObject *self;
    self = m->func_closure;
    if (self == NULL)
        self = Py_None;
    Py_INCREF(self);
    return self;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
{
    if (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(op->func_dict == NULL))
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
    if (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
               "setting function's dictionary to a non-dict");
        return -1;
    }
    tmp = op->func_dict;
    Py_INCREF(value);
    op->func_dict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
{
    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
{
    PyObject* result = (op->func_code) ? op->func_code : Py_None;
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    Py_DECREF(res);
    return 0;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_tuple;
    op->defaults_tuple = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_tuple;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_kwdict;
    op->defaults_kwdict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_kwdict;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value || value == Py_None) {
        value = NULL;
    } else if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    tmp = op->func_annotations;
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
    PyObject* result = op->func_annotations;
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
static PyGetSetDef __pyx_CyFunction_getsets[] = {
    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {0, 0, 0, 0, 0}
};
#ifndef PY_WRITE_RESTRICTED /* < Py2.5 */
#define PY_WRITE_RESTRICTED WRITE_RESTRICTED
#endif
static PyMemberDef __pyx_CyFunction_members[] = {
    {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
    {0, 0, 0,  0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromString(m->func.m_ml->ml_name);
#else
    return PyString_FromString(m->func.m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
    {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
    if (op == NULL)
        return NULL;
    op->flags = flags;
    op->func_weakreflist = NULL;
    op->func.m_ml = ml;
    op->func.m_self = (PyObject *) op;
    Py_XINCREF(closure);
    op->func_closure = closure;
    Py_XINCREF(module);
    op->func.m_module = module;
    op->func_dict = NULL;
    op->func_name = NULL;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
    op->func_classobj = NULL;
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = NULL;
    PyObject_GC_Track(op);
    return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
    Py_CLEAR(m->func_closure);
    Py_CLEAR(m->func.m_module);
    Py_CLEAR(m->func_dict);
    Py_CLEAR(m->func_name);
    Py_CLEAR(m->func_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
    Py_CLEAR(m->func_classobj);
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyMem_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    if (m->func_weakreflist != NULL)
        PyObject_ClearWeakRefs((PyObject *) m);
    __Pyx_CyFunction_clear(m);
    PyObject_GC_Del(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
    Py_VISIT(m->func_closure);
    Py_VISIT(m->func.m_module);
    Py_VISIT(m->func_dict);
    Py_VISIT(m->func_name);
    Py_VISIT(m->func_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
    Py_VISIT(m->func_classobj);
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_VISIT(pydefaults[i]);
    }
    return 0;
}
static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
        Py_INCREF(func);
        return func;
    }
    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
        if (type == NULL)
            type = (PyObject *)(Py_TYPE(obj));
        return PyMethod_New(func,
                            type, (PyObject *)(Py_TYPE(type)));
    }
    if (obj == Py_None)
        obj = NULL;
    return PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
#if CYTHON_COMPILING_IN_PYPY
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    Py_ssize_t size;
    switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
    case METH_VARARGS:
        if (likely(kw == NULL) || PyDict_Size(kw) == 0)
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
    case METH_NOARGS:
        if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
            size = PyTuple_GET_SIZE(arg);
            if (size == 0)
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%zd given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    case METH_O:
        if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
            size = PyTuple_GET_SIZE(arg);
            if (size == 1)
                return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%zd given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
                        "longer supported!");
        return NULL;
    }
    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
                 f->m_ml->ml_name);
    return NULL;
}
#else
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
	return PyCFunction_Call(func, arg, kw);
}
#endif
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    __Pyx_NAMESTR("cython_function_or_method"), /*tp_name*/
    sizeof(__pyx_CyFunctionObject),   /*tp_basicsize*/
    0,                                  /*tp_itemsize*/
    (destructor) __Pyx_CyFunction_dealloc, /*tp_dealloc*/
    0,                                  /*tp_print*/
    0,                                  /*tp_getattr*/
    0,                                  /*tp_setattr*/
#if PY_MAJOR_VERSION < 3
    0,                                  /*tp_compare*/
#else
    0,                                  /*reserved*/
#endif
    (reprfunc) __Pyx_CyFunction_repr,   /*tp_repr*/
    0,                                  /*tp_as_number*/
    0,                                  /*tp_as_sequence*/
    0,                                  /*tp_as_mapping*/
    0,                                  /*tp_hash*/
    __Pyx_CyFunction_Call,              /*tp_call*/
    0,                                  /*tp_str*/
    0,                                  /*tp_getattro*/
    0,                                  /*tp_setattro*/
    0,                                  /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/
    0,                                  /*tp_doc*/
    (traverseproc) __Pyx_CyFunction_traverse,   /*tp_traverse*/
    (inquiry) __Pyx_CyFunction_clear,   /*tp_clear*/
    0,                                  /*tp_richcompare*/
    offsetof(__pyx_CyFunctionObject, func_weakreflist), /* tp_weaklistoffse */
    0,                                  /*tp_iter*/
    0,                                  /*tp_iternext*/
    __pyx_CyFunction_methods,           /*tp_methods*/
    __pyx_CyFunction_members,           /*tp_members*/
    __pyx_CyFunction_getsets,           /*tp_getset*/
    0,                                  /*tp_base*/
    0,                                  /*tp_dict*/
    __Pyx_CyFunction_descr_get,         /*tp_descr_get*/
    0,                                  /*tp_descr_set*/
    offsetof(__pyx_CyFunctionObject, func_dict),/*tp_dictoffset*/
    0,                                  /*tp_init*/
    0,                                  /*tp_alloc*/
    0,                                  /*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
#if PY_VERSION_HEX >= 0x030400a1
    0,                                  /*tp_finalize*/
#endif
};
static int __Pyx_CyFunction_init(void) {
#if !CYTHON_COMPILING_IN_PYPY
    __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
#endif
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    if (__pyx_CyFunctionType == NULL) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyMem_Malloc(size);
    if (!m->defaults)
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_tuple = tuple;
    Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
    PyObject *ns;
    if (metaclass) {
        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
        if (prep) {
            PyObject *pargs = PyTuple_Pack(2, name, bases);
            if (unlikely(!pargs)) {
                Py_DECREF(prep);
                return NULL;
            }
            ns = PyObject_Call(prep, pargs, mkw);
            Py_DECREF(prep);
            Py_DECREF(pargs);
        } else {
            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
                return NULL;
            PyErr_Clear();
            ns = PyDict_New();
        }
    } else {
        ns = PyDict_New();
    }
    if (unlikely(!ns))
        return NULL;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
    return ns;
bad:
    Py_DECREF(ns);
    return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
                                      PyObject *dict, PyObject *mkw,
                                      int calculate_metaclass, int allow_py2_metaclass) {
    PyObject *result, *margs;
    PyObject *owned_metaclass = NULL;
    if (allow_py2_metaclass) {
        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
        if (owned_metaclass) {
            metaclass = owned_metaclass;
        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
            PyErr_Clear();
        } else {
            return NULL;
        }
    }
    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
        Py_XDECREF(owned_metaclass);
        if (unlikely(!metaclass))
            return NULL;
        owned_metaclass = metaclass;
    }
    margs = PyTuple_Pack(3, name, bases, dict);
    if (unlikely(!margs)) {
        result = NULL;
    } else {
        result = PyObject_Call(metaclass, margs, mkw);
        Py_DECREF(margs);
    }
    Py_XDECREF(owned_metaclass);
    return result;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    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;
    #if PY_VERSION_HEX >= 0x02050000
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0; /* try absolute import on failure */
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
    #else
    if (level>0) {
        PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
        goto bad;
    }
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
    #endif
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func)             \
    {                                                                     \
        func_type value = func(x);                                        \
        if (sizeof(target_type) < sizeof(func_type)) {                    \
            if (unlikely(value != (func_type) (target_type) value)) {     \
                func_type zero = 0;                                       \
                PyErr_SetString(PyExc_OverflowError,                      \
                    (is_unsigned && unlikely(value < zero)) ?             \
                    "can't convert negative value to " #target_type :     \
                    "value too large to convert to " #target_type);       \
                return (target_type) -1;                                  \
            }                                                             \
        }                                                                 \
        return (target_type) value;                                       \
    }

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) {
    const uint64_t neg_one = (uint64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint64_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint64_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint64_t");
                return (uint64_t) -1;
            }
            return (uint64_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint64_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (uint64_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint64_t");
                return (uint64_t) -1;
            }
            if (sizeof(uint64_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(uint64_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint64_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(uint64_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(uint64_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(uint64_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, long, PyLong_AsLong)
            } else if (sizeof(uint64_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint64_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (uint64_t) -1;
        }
    } else {
        uint64_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint64_t) -1;
        val = __Pyx_PyInt_As_uint64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to int");
                return (int) -1;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(int)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (int) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to int");
                return (int) -1;
            }
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(int) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(int)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(int) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(int) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong)
            } else if (sizeof(int) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint32_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint32_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint32_t");
                return (uint32_t) -1;
            }
            return (uint32_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint32_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (uint32_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint32_t");
                return (uint32_t) -1;
            }
            if (sizeof(uint32_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(uint32_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint32_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(uint32_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(uint32_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(uint32_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, long, PyLong_AsLong)
            } else if (sizeof(uint32_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint32_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (uint32_t) -1;
        }
    } else {
        uint32_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint32_t) -1;
        val = __Pyx_PyInt_As_uint32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value) {
    const int8_t neg_one = (int8_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int8_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int8_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int8_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int8_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int8_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int8_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value) {
    const uint8_t neg_one = (uint8_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint8_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint8_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint8_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint8_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint8_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint8_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value) {
    const int16_t neg_one = (int16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int16_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int16_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int16_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int16_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int16_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int16_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint16_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint16_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint16_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
    const int32_t neg_one = (int32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int32_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int32_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint32_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
    const size_t neg_one = (size_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to size_t");
                return (size_t) -1;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(size_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (size_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to size_t");
                return (size_t) -1;
            }
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(size_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(size_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(size_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(size_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(size_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(size_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(size_t, long, PyLong_AsLong)
            } else if (sizeof(size_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(size_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            size_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(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_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG)
        } else {
            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 CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG) -1;
            }
            if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(PY_LONG_LONG)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(PY_LONG_LONG) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyLong_AsLong)
            } else if (sizeof(PY_LONG_LONG) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            PY_LONG_LONG val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (PY_LONG_LONG) -1;
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG) -1;
        val = __Pyx_PyInt_As_PY_LONG_LONG(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value) {
    const int64_t neg_one = (int64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int64_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int64_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int64_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int64_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int64_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) {
    const uint64_t neg_one = (uint64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint64_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
                                     little, !is_unsigned);
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) {
    const int64_t neg_one = (int64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int64_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int64_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to int64_t");
                return (int64_t) -1;
            }
            return (int64_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(int64_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (int64_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to int64_t");
                return (int64_t) -1;
            }
            if (sizeof(int64_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(int64_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(int64_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(int64_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(int64_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(int64_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, long, PyLong_AsLong)
            } else if (sizeof(int64_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int64_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (int64_t) -1;
        }
    } else {
        int64_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int64_t) -1;
        val = __Pyx_PyInt_As_int64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
    const char neg_one = (char) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(char) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(char) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(char) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(char),
                                     little, !is_unsigned);
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *x) {
    const uint8_t neg_one = (uint8_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint8_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint8_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint8_t");
                return (uint8_t) -1;
            }
            return (uint8_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint8_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (uint8_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint8_t");
                return (uint8_t) -1;
            }
            if (sizeof(uint8_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(uint8_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint8_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(uint8_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(uint8_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(uint8_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, long, PyLong_AsLong)
            } else if (sizeof(uint8_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint8_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (uint8_t) -1;
        }
    } else {
        uint8_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint8_t) -1;
        val = __Pyx_PyInt_As_uint8_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
    const int32_t neg_one = (int32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int32_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to int32_t");
                return (int32_t) -1;
            }
            return (int32_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(int32_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (int32_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to int32_t");
                return (int32_t) -1;
            }
            if (sizeof(int32_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(int32_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(int32_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(int32_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(int32_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(int32_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, long, PyLong_AsLong)
            } else if (sizeof(int32_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int32_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (int32_t) -1;
        }
    } else {
        int32_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyInt_As_int32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *x) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint16_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint16_t, long, PyInt_AS_LONG)
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint16_t");
                return (uint16_t) -1;
            }
            return (uint16_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint16_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (uint16_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to uint16_t");
                return (uint16_t) -1;
            }
            if (sizeof(uint16_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(uint16_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(uint16_t)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(uint16_t) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(uint16_t) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(uint16_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, long, PyLong_AsLong)
            } else if (sizeof(uint16_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint16_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (uint16_t) -1;
        }
    } else {
        uint16_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint16_t) -1;
        val = __Pyx_PyInt_As_uint16_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG)
        } else {
            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 CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return (long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long) -1;
            }
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong)
            } else if (sizeof(long) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong)
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            if (sizeof(digit) <= sizeof(long)) {
                switch (Py_SIZE(x)) {
                    case  0: return 0;
                    case  1: return +(long) ((PyLongObject*)x)->ob_digit[0];
                    case -1: return -(long) ((PyLongObject*)x)->ob_digit[0];
                }
            }
 #endif
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong)
            } else if (sizeof(long) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong)
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    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;
#else
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
#endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}

static PyObject *__Pyx_Generator_Next(PyObject *self);
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Generator_Close(PyObject *self);
static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args);
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
    PyObject *et, *ev, *tb;
    PyObject *value = NULL;
    __Pyx_ErrFetch(&et, &ev, &tb);
    if (!et) {
        Py_XDECREF(tb);
        Py_XDECREF(ev);
        Py_INCREF(Py_None);
        *pvalue = Py_None;
        return 0;
    }
    if (unlikely(et != PyExc_StopIteration) &&
            unlikely(!PyErr_GivenExceptionMatches(et, PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    if (likely(et == PyExc_StopIteration)) {
        if (likely(!ev) || !PyObject_IsInstance(ev, PyExc_StopIteration)) {
            if (!ev) {
                Py_INCREF(Py_None);
                ev = Py_None;
            }
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = ev;
            return 0;
        }
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_IsInstance(ev, PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    Py_XDECREF(tb);
    Py_DECREF(et);
#if PY_VERSION_HEX >= 0x030300A0
    value = ((PyStopIterationObject *)ev)->value;
    Py_INCREF(value);
    Py_DECREF(ev);
#else
    {
        PyObject* args = PyObject_GetAttr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PyObject_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
#endif
static CYTHON_INLINE
void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) {
    PyObject *exc_type = self->exc_type;
    PyObject *exc_value = self->exc_value;
    PyObject *exc_traceback = self->exc_traceback;
    self->exc_type = NULL;
    self->exc_value = NULL;
    self->exc_traceback = NULL;
    Py_XDECREF(exc_type);
    Py_XDECREF(exc_value);
    Py_XDECREF(exc_traceback);
}
static CYTHON_INLINE
int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) {
    if (unlikely(gen->is_running)) {
        PyErr_SetString(PyExc_ValueError,
                        "generator already executing");
        return 1;
    }
    return 0;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            PyErr_SetString(PyExc_TypeError,
                            "can't send non-None value to a "
                            "just-started generator");
            return NULL;
        }
    }
    if (unlikely(self->resume_label == -1)) {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    if (value) {
#if CYTHON_COMPILING_IN_PYPY
#else
        /* Generators always return to their most recent caller, not
         * necessarily their creator. */
        if (self->exc_traceback) {
            PyThreadState *tstate = PyThreadState_GET();
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_XINCREF(tstate->frame);
            assert(f->f_back == NULL);
            f->f_back = tstate->frame;
        }
#endif
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    self->is_running = 1;
    retval = self->body((PyObject *) self, value);
    self->is_running = 0;
    if (retval) {
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
#if CYTHON_COMPILING_IN_PYPY
#else
        /* Don't keep the reference to f_back any longer than necessary.  It
         * may keep a chain of frames alive or it could create a reference
         * cycle. */
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_CLEAR(f->f_back);
        }
#endif
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Generator_Undelegate(gen);
    __Pyx_PyGen_FetchStopIterationValue(&val);
    ret = __Pyx_Generator_SendEx(gen, val);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, Py_None);
}
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Send(yf, value);
        } else {
            if (value == Py_None)
                ret = PyIter_Next(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, value);
}
static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Generator_Close(yf);
        if (!retval)
            return -1;
    } else {
        PyObject *meth;
        gen->is_running = 1;
        meth = PyObject_GetAttr(yf, __pyx_n_s_close);
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Close(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Generator_CloseIter(gen, yf);
        __Pyx_Generator_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
#if PY_VERSION_HEX < 0x02050000
        PyErr_SetNone(PyExc_StopIteration);
#else
        PyErr_SetNone(PyExc_GeneratorExit);
#endif
    retval = __Pyx_Generator_SendEx(gen, NULL);
    if (retval) {
        Py_DECREF(retval);
        PyErr_SetString(PyExc_RuntimeError,
                        "generator ignored GeneratorExit");
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (!raised_exception
        || raised_exception == PyExc_StopIteration
#if PY_VERSION_HEX >= 0x02050000
        || raised_exception == PyExc_GeneratorExit
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
#endif
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
    {
        if (raised_exception) PyErr_Clear();      /* ignore these errors */
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *typ;
    PyObject *tb = NULL;
    PyObject *val = NULL;
    PyObject *yf = gen->yieldfrom;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
#if PY_VERSION_HEX >= 0x02050000
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
            int err = __Pyx_Generator_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Generator_Undelegate(gen);
            if (err < 0)
                return __Pyx_Generator_SendEx(gen, NULL);
            goto throw_here;
        }
#endif
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Throw(yf, args);
        } else {
            PyObject *meth = PyObject_GetAttr(yf, __pyx_n_s_throw);
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Generator_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            ret = PyObject_CallObject(meth, args);
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Generator_FinishDelegation(gen);
        }
        return ret;
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Generator_SendEx(gen, NULL);
}
static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    Py_VISIT(gen->exc_type);
    Py_VISIT(gen->exc_value);
    Py_VISIT(gen->exc_traceback);
    return 0;
}
static int __Pyx_Generator_clear(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    Py_CLEAR(gen->exc_type);
    Py_CLEAR(gen->exc_value);
    Py_CLEAR(gen->exc_traceback);
    return 0;
}
static void __Pyx_Generator_dealloc(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    if (gen->resume_label > 0) {
        PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (self->ob_refcnt > 0)
#endif
            return;                     /* resurrected.  :( */
        PyObject_GC_UnTrack(self);
    }
    __Pyx_Generator_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Generator_del(PyObject *self) {
    PyObject *res;
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    if (gen->resume_label <= 0)
        return ;
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;
#endif
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
    res = __Pyx_Generator_Close(self);
    if (res == NULL)
        PyErr_WriteUnraisable(self);
    else
        Py_DECREF(res);
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if PY_VERSION_HEX < 0x030400a1
    /* Undo the temporary resurrection; can't use DECREF here, it would
     * cause a recursive call.
     */
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0)
        return; /* this is the normal path out */
    /* close() resurrected it!  Make it look like the original Py_DECREF
     * never happened.
     */
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(self->ob_type) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
     * we need to undo that. */
    _Py_DEC_REFTOTAL;
#endif
    /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
     * chain, so no more to do there.
     * If COUNT_ALLOCS, the original decref bumped tp_frees, and
     * _Py_NewReference bumped tp_allocs:  both of those need to be
     * undone.
     */
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
#endif
}
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running",
#if PY_VERSION_HEX >= 0x02060000
     T_BOOL,
#else
     T_BYTE,
#endif
     offsetof(__pyx_GeneratorObject, is_running),
     READONLY,
     NULL},
    {0, 0, 0, 0, 0}
};
static PyMethodDef __pyx_Generator_methods[] = {
    {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0},
    {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0},
    {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0},
    {0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    __Pyx_NAMESTR("generator"),         /*tp_name*/
    sizeof(__pyx_GeneratorObject),      /*tp_basicsize*/
    0,                                  /*tp_itemsize*/
    (destructor) __Pyx_Generator_dealloc,/*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*/
    0,                                  /*tp_as_number*/
    0,                                  /*tp_as_sequence*/
    0,                                  /*tp_as_mapping*/
    0,                                  /*tp_hash*/
    0,                                  /*tp_call*/
    0,                                  /*tp_str*/
    0,                                  /*tp_getattro*/
    0,                                  /*tp_setattro*/
    0,                                  /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /* tp_flags*/
    0,                                  /*tp_doc*/
    (traverseproc) __Pyx_Generator_traverse,   /*tp_traverse*/
    0,                                  /*tp_clear*/
    0,                                  /*tp_richcompare*/
    offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */
    0,                                  /*tp_iter*/
    (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/
    __pyx_Generator_methods,            /*tp_methods*/
    __pyx_Generator_memberlist,         /*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*/
    0,                                  /*tp_new*/
    0,                                  /*tp_free*/
    0,                                  /*tp_is_gc*/
    0,                                  /*tp_bases*/
    0,                                  /*tp_mro*/
    0,                                  /*tp_cache*/
    0,                                  /*tp_subclasses*/
    0,                                  /*tp_weaklist*/
#if PY_VERSION_HEX >= 0x030400a1
    0,                                  /*tp_del*/
#else
    __Pyx_Generator_del,                /*tp_del*/
#endif
#if PY_VERSION_HEX >= 0x02060000
    0,                                  /*tp_version_tag*/
#endif
#if PY_VERSION_HEX >= 0x030400a1
    __Pyx_Generator_del,                /*tp_finalize*/
#endif
};
static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
                                                  PyObject *closure) {
    __pyx_GeneratorObject *gen =
        PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type);
    if (gen == NULL)
        return NULL;
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->exc_type = NULL;
    gen->exc_value = NULL;
    gen->exc_traceback = NULL;
    gen->gi_weakreflist = NULL;
    PyObject_GC_Track(gen);
    return gen;
}
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (__pyx_GeneratorType == NULL) {
        return -1;
    }
    return 0;
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        #if PY_VERSION_HEX < 0x02050000
        return PyErr_Warn(NULL, message);
        #else
        return PyErr_WarnEx(NULL, message, 1);
        #endif
    }
    return 0;
}

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        #if PY_VERSION_HEX < 0x02050000
        if (PyErr_Warn(NULL, warning) < 0) goto bad;
        #else
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
        #endif
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = (start + end) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #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_code = __Pyx_PyCode_New(
        0,            /*int argcount,*/
        0,            /*int kwonlyargcount,*/
        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,*/
        py_line,      /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_globals = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) 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 = py_line;
    PyTraceBack_Here(py_frame);
bad:
    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;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else /* PY_VERSION_HEX < 0x03030000 */
        if (PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_DATA_SIZE(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
        return PyUnicode_AsUTF8AndSize(o, length);
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
#endif /* PY_VERSION_HEX < 0x03030000 */
    } else
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII  || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
#if !CYTHON_COMPILING_IN_PYPY
#if PY_VERSION_HEX >= 0x02060000
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
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_MAJOR_VERSION < 3
  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_MAJOR_VERSION < 3
  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_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (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;
}
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b)))
      return PyInt_AS_LONG(b);
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
     #if CYTHON_USE_PYLONG_INTERNALS
       switch (Py_SIZE(b)) {
       case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0];
       case  0: return 0;
       case  1: return ((PyLongObject*)b)->ob_digit[0];
       }
     #endif
    #endif
  #if PY_VERSION_HEX < 0x02060000
    return PyInt_AsSsize_t(b);
  #else
    return PyLong_AsSsize_t(b);
  #endif
  }
  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
}


#endif /* Py_PYTHON_H */
