/* Generated by Cython 0.29.28 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "/Users/runner/work/pysam/pysam/htslib/htslib/bgzf.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/cram.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/faidx.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/hfile.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/hts.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/kstring.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/sam.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/tbx.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/vcf.h",
            "/Users/runner/work/pysam/pysam/htslib/htslib/vcfutils.h",
            "/Users/runner/work/pysam/pysam/pysam/htslib_util.h",
            "/Users/runner/work/pysam/pysam/pysam/pysam_stream.h"
        ],
        "extra_compile_args": [
            "-Wno-unused",
            "-Wno-strict-prototypes",
            "-Wno-sign-compare",
            "-Wno-error=declaration-after-statement"
        ],
        "include_dirs": [
            "pysam",
            "./pysam",
            "/Users/runner/work/pysam/pysam/htslib",
            "/Users/runner/work/pysam/pysam/samtools",
            "/Users/runner/work/pysam/pysam/samtools/lz4",
            "/Users/runner/work/pysam/pysam/bcftools",
            "/Users/runner/work/pysam/pysam/pysam",
            "/Users/runner/work/pysam/pysam"
        ],
        "language": "c",
        "libraries": [
            "z",
            "lzma",
            "bz2",
            "z",
            "curl",
            "chtslib.cpython-39-darwin",
            "cutils.cpython-39-darwin"
        ],
        "library_dirs": [
            "/Users/runner/work/pysam/pysam/pysam",
            "/Users/runner/work/pysam/pysam/pysam",
            "/Users/runner/work/pysam/pysam",
            "/Users/runner/work/pysam/pysam/build/lib.macosx-10.15-x86_64-3.9/pysam"
        ],
        "name": "pysam.libcalignmentfile",
        "sources": [
            "pysam/libcalignmentfile.pyx"
        ]
    },
    "module_name": "pysam.libcalignmentfile"
}
END: Cython Metadata */

#ifndef PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_29_28"
#define CYTHON_HEX_VERSION 0x001D1CF0
#define CYTHON_FUTURE_DIVISION 0
#include <stddef.h>
#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
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x02070000
    #define HAVE_LONG_LONG
  #endif
#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_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 0
  #elif !defined(CYTHON_FAST_THREAD_STATE)
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030B00A1)
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
  #ifndef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK 0
  #elif !defined(CYTHON_USE_EXC_INFO_STACK)
    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_MAJOR_VERSION < 3
    #include "longintrepr.h"
  #endif
  #undef SHIFT
  #undef BASE
  #undef MASK
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#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
#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
#ifndef CYTHON_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus) && __cplusplus >= 201103L
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #elif __has_cpp_attribute(gnu::fallthrough)
      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__ ) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif 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

#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#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_DefaultClassType PyType_Type
#if PY_VERSION_HEX >= 0x030B00A1
    static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
        PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
        PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL;
        const char *fn_cstr=NULL;
        const char *name_cstr=NULL;
        PyCodeObject* co=NULL;
        PyObject *type, *value, *traceback;
        PyErr_Fetch(&type, &value, &traceback);
        if (!(kwds=PyDict_New())) goto end;
        if (!(argcount=PyLong_FromLong(a))) goto end;
        if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end;
        if (!(posonlyargcount=PyLong_FromLong(0))) goto end;
        if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end;
        if (!(kwonlyargcount=PyLong_FromLong(k))) goto end;
        if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end;
        if (!(nlocals=PyLong_FromLong(l))) goto end;
        if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end;
        if (!(stacksize=PyLong_FromLong(s))) goto end;
        if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end;
        if (!(flags=PyLong_FromLong(f))) goto end;
        if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end;
        if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end;
        if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
        if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
        if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too;
        if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here
        if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too;
        Py_XDECREF((PyObject*)co);
        co = (PyCodeObject*)call_result;
        call_result = NULL;
        if (0) {
            cleanup_code_too:
            Py_XDECREF((PyObject*)co);
            co = NULL;
        }
        end:
        Py_XDECREF(kwds);
        Py_XDECREF(argcount);
        Py_XDECREF(posonlyargcount);
        Py_XDECREF(kwonlyargcount);
        Py_XDECREF(nlocals);
        Py_XDECREF(stacksize);
        Py_XDECREF(replace);
        Py_XDECREF(call_result);
        Py_XDECREF(empty);
        if (type) {
            PyErr_Restore(type, value, traceback);
        }
        return co;
    }
#else
  #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)
#endif
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef METH_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
  #define PyMem_RawFree(p)             PyMem_Free(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #if defined(PyUnicode_IS_READY)
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #else
  #define __Pyx_PyUnicode_READY(op)       (0)
  #endif
  #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_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #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)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  #endif
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #endif
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #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_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #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]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#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
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#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
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#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_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#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_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsHash_t
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif

#define __PYX_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

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

#define __PYX_HAVE__pysam__libcalignmentfile
#define __PYX_HAVE_API__pysam__libcalignmentfile
/* Early includes */
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "pythread.h"
#include <sys/types.h>
#include "stdarg.h"
#include "htslib/kstring.h"
#include "htslib_util.h"
#include "htslib/hfile.h"
#include "htslib/bgzf.h"
#include "htslib/hts.h"
#include "htslib/sam.h"
#include "htslib/faidx.h"
#include "htslib/tbx.h"
#include "htslib/vcf.h"
#include "htslib/vcfutils.h"
#include "htslib/cram.h"
#include "pysam_stream.h"
#include <errno.h>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

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

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#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 int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const 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(const 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_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#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_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#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
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(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;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        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) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(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_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    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;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
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[] = {
  "pysam/libcalignmentfile.pyx",
  "stringsource",
  "pysam/libcalignmentfile.pxd",
  "array.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
  "pysam/libcfaidx.pxd",
  "pysam/libcalignedsegment.pxd",
};
/* NoFastGil.proto */
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
#define __Pyx_PyGILState_Release PyGILState_Release
#define __Pyx_FastGIL_Remember()
#define __Pyx_FastGIL_Forget()
#define __Pyx_FastGilFuncInit()

/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif


/*--- Type declarations ---*/
#ifndef _ARRAYARRAY_H
struct arrayobject;
typedef struct arrayobject arrayobject;
#endif
struct __pyx_obj_5pysam_10libchtslib_HTSFile;
struct __pyx_obj_5pysam_9libcfaidx_FastaFile;
struct __pyx_obj_5pysam_9libcfaidx_FastqProxy;
struct __pyx_obj_5pysam_9libcfaidx_FastxRecord;
struct __pyx_obj_5pysam_9libcfaidx_FastxFile;
struct __pyx_obj_5pysam_9libcfaidx_FastqFile;
struct __pyx_obj_5pysam_9libcfaidx_Fastafile;
struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment;
struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn;
struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead;
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader;
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll;
struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads;
struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall;
struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array;
struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array;

/* "pysam/libcfaidx.pxd":49
 *     cdef cython.str to_string(self)
 *     cdef cython.str tostring(self)
 *     cpdef array.array get_quality_array(self, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array {
  int __pyx_n;
  int offset;
};

/* "pysam/libcfaidx.pxd":59
 *     cdef cython.str to_string(self)
 *     cdef cython.str tostring(self)
 *     cpdef array.array get_quality_array(self, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * cdef class FastxFile:
 */
struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array {
  int __pyx_n;
  int offset;
};
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag;
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag;
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring;

/* "pysam/libcalignedsegment.pxd":30
 * 
 * from pysam.libcalignmentfile cimport AlignmentFile, AlignmentHeader
 * ctypedef AlignmentFile AlignmentFile_t             # <<<<<<<<<<<<<<
 * 
 * 
 */
typedef struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t;

/* "pysam/libcalignedsegment.pxd":50
 *     # add an alignment tag with value to the AlignedSegment
 *     # an existing tag of the same name will be replaced.
 *     cpdef set_tag(self, tag, value, value_type=?, replace=?)             # <<<<<<<<<<<<<<
 * 
 *     # get an alignment tag from the AlignedSegment
 */
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag {
  int __pyx_n;
  PyObject *value_type;
  PyObject *replace;
};

/* "pysam/libcalignedsegment.pxd":53
 * 
 *     # get an alignment tag from the AlignedSegment
 *     cpdef get_tag(self, tag, with_value_type=?)             # <<<<<<<<<<<<<<
 * 
 *     # return true if tag exists
 */
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag {
  int __pyx_n;
  PyObject *with_value_type;
};

/* "pysam/libcalignedsegment.pxd":62
 * 
 *     # returns a valid sam alignment string (deprecated)
 *     cpdef tostring(self, htsfile=*)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring {
  int __pyx_n;
  PyObject *htsfile;
};
struct __pyx_opt_args_5pysam_9libcutils_parse_region;
struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array;
struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring;
struct __pyx_opt_args_5pysam_9libcutils_qualities_to_qualitystring;
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str;
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_bytes;
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str_w_len;
struct __pyx_opt_args_5pysam_9libcutils_force_str;
struct __pyx_opt_args_5pysam_9libcutils_force_bytes;
struct __pyx_opt_args_5pysam_9libcutils_decode_bytes;

/* "pysam/libcutils.pxd":7
 * from cpython cimport array as c_array
 * 
 * cpdef parse_region(contig=*, start=*, stop=*, region=*, reference=*, end=*)             # <<<<<<<<<<<<<<
 * 
 * #########################################################################
 */
struct __pyx_opt_args_5pysam_9libcutils_parse_region {
  int __pyx_n;
  PyObject *contig;
  PyObject *start;
  PyObject *stop;
  PyObject *region;
  PyObject *reference;
  PyObject *end;
};

/* "pysam/libcutils.pxd":12
 * # Utility functions for quality string conversions
 * 
 * cpdef c_array.array qualitystring_to_array(input_str, int offset=*)             # <<<<<<<<<<<<<<
 * cpdef array_to_qualitystring(c_array.array arr, int offset=*)
 * cpdef qualities_to_qualitystring(qualities, int offset=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array {
  int __pyx_n;
  int offset;
};

/* "pysam/libcutils.pxd":13
 * 
 * cpdef c_array.array qualitystring_to_array(input_str, int offset=*)
 * cpdef array_to_qualitystring(c_array.array arr, int offset=*)             # <<<<<<<<<<<<<<
 * cpdef qualities_to_qualitystring(qualities, int offset=*)
 * 
 */
struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring {
  int __pyx_n;
  int offset;
};

/* "pysam/libcutils.pxd":14
 * cpdef c_array.array qualitystring_to_array(input_str, int offset=*)
 * cpdef array_to_qualitystring(c_array.array arr, int offset=*)
 * cpdef qualities_to_qualitystring(qualities, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * ########################################################################
 */
struct __pyx_opt_args_5pysam_9libcutils_qualities_to_qualitystring {
  int __pyx_n;
  int offset;
};

/* "pysam/libcutils.pxd":26
 * ## Python 3 compatibility functions
 * ########################################################################
 * cdef charptr_to_str(const char *s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":27
 * ########################################################################
 * cdef charptr_to_str(const char *s, encoding=*, errors=*)
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 * cdef force_str(object s, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_bytes {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":28
 * cdef charptr_to_str(const char *s, encoding=*, errors=*)
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef force_str(object s, encoding=*, errors=*)
 * cdef bytes force_bytes(object s, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str_w_len {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":29
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 * cdef force_str(object s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef bytes force_bytes(object s, encoding=*, errors=*)
 * cdef decode_bytes(bytes s, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_force_str {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":30
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 * cdef force_str(object s, encoding=*, errors=*)
 * cdef bytes force_bytes(object s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef decode_bytes(bytes s, encoding=*, errors=*)
 * cdef bytes encode_filename(object filename)
 */
struct __pyx_opt_args_5pysam_9libcutils_force_bytes {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":31
 * cdef force_str(object s, encoding=*, errors=*)
 * cdef bytes force_bytes(object s, encoding=*, errors=*)
 * cdef decode_bytes(bytes s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef bytes encode_filename(object filename)
 * cdef from_string_and_size(const char *s, size_t length)
 */
struct __pyx_opt_args_5pysam_9libcutils_decode_bytes {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};
struct __pyx_t_5pysam_17libcalignmentfile___iterdata;
typedef struct __pyx_t_5pysam_17libcalignmentfile___iterdata __pyx_t_5pysam_17libcalignmentfile___iterdata;
struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator;
struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list;

/* "pysam/libcalignmentfile.pxd":24
 * # Utility types
 * 
 * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
 *     htsFile * htsfile
 *     bam_hdr_t * header
 */
struct __pyx_t_5pysam_17libcalignmentfile___iterdata {
  htsFile *htsfile;
  bam_hdr_t *header;
  hts_itr_t *iter;
  faidx_t *fastafile;
  int tid;
  char *seq;
  int seq_len;
  int min_mapping_quality;
  int flag_require;
  int flag_filter;
  int compute_baq;
  int redo_baq;
  int ignore_orphans;
  int adjust_capq_threshold;
};

/* "pysam/libcalignmentfile.pxd":120
 *     cdef int cnext(self)
 *     cdef char * get_sequence(self)
 *     cdef _setup_iterator(self,             # <<<<<<<<<<<<<<
 *                          int tid,
 *                          int start,
 */
struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator {
  int __pyx_n;
  int multiple_iterators;
};

/* "pysam/libcalignmentfile.pyx":187
 * # the following should be class-method for VariantHeader, but cdef @classmethods
 * # are not implemented in cython.
 * cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest,             # <<<<<<<<<<<<<<
 *                                         reference_names,
 *                                         reference_lengths,
 */
struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list {
  int __pyx_n;
  PyObject *add_sq_text;
  PyObject *text;
};

/* "pysam/libchtslib.pxd":2677
 * 
 * 
 * cdef class HTSFile(object):             # <<<<<<<<<<<<<<
 *     cdef          htsFile *htsfile       # pointer to htsFile structure
 *     cdef          int64_t start_offset   # BGZF offset of first record
 */
struct __pyx_obj_5pysam_10libchtslib_HTSFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtab;
  htsFile *htsfile;
  int64_t start_offset;
  PyObject *filename;
  PyObject *mode;
  PyObject *threads;
  PyObject *index_filename;
  int is_stream;
  int is_remote;
  int duplicate_filehandle;
};


/* "pysam/libcfaidx.pxd":37
 *                     int * dret)
 * 
 * cdef class FastaFile:             # <<<<<<<<<<<<<<
 *     cdef bint is_remote
 *     cdef object _filename, _references, _lengths, reference2length
 */
struct __pyx_obj_5pysam_9libcfaidx_FastaFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtab;
  int is_remote;
  PyObject *_filename;
  PyObject *_references;
  PyObject *_lengths;
  PyObject *reference2length;
  faidx_t *fastafile;
};


/* "pysam/libcfaidx.pxd":45
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 *     cdef cython.str to_string(self)
 */
struct __pyx_obj_5pysam_9libcfaidx_FastqProxy {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtab;
  kseq_t *_delegate;
};


/* "pysam/libcfaidx.pxd":52
 * 
 * 
 * cdef class FastxRecord:             # <<<<<<<<<<<<<<
 *     """
 *     Python container for pysam.libcfaidx.FastqProxy with persistence.
 */
struct __pyx_obj_5pysam_9libcfaidx_FastxRecord {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtab;
  PyObject *comment;
  PyObject *quality;
  PyObject *sequence;
  PyObject *name;
};


/* "pysam/libcfaidx.pxd":61
 *     cpdef array.array get_quality_array(self, int offset=*)
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef BGZF * fastqfile
 */
struct __pyx_obj_5pysam_9libcfaidx_FastxFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtab;
  PyObject *_filename;
  BGZF *fastqfile;
  kseq_t *entry;
  int persist;
  int is_remote;
};


/* "pysam/libcfaidx.pxd":73
 * 
 * # Compatibility Layer for pysam 0.8.1
 * cdef class FastqFile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_9libcfaidx_FastqFile {
  struct __pyx_obj_5pysam_9libcfaidx_FastxFile __pyx_base;
};


/* "pysam/libcfaidx.pxd":78
 * 
 * # Compatibility Layer for pysam < 0.8
 * cdef class Fastafile(FastaFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_9libcfaidx_Fastafile {
  struct __pyx_obj_5pysam_9libcfaidx_FastaFile __pyx_base;
};


/* "pysam/libcalignedsegment.pxd":34
 * 
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedSegment represents
 */
struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtab;
  bam1_t *_delegate;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  PyObject *cache_query_qualities;
  PyObject *cache_query_alignment_qualities;
  PyObject *cache_query_sequence;
  PyObject *cache_query_alignment_sequence;
};


/* "pysam/libcalignedsegment.pxd":65
 * 
 * 
 * cdef class PileupColumn:             # <<<<<<<<<<<<<<
 *     cdef const bam_pileup1_t ** plp
 *     cdef int tid
 */
struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn {
  PyObject_HEAD
  bam_pileup1_t const **plp;
  int tid;
  int pos;
  int n_pu;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  uint32_t min_base_quality;
  kstring_t buf;
  char *reference_sequence;
};


/* "pysam/libcalignedsegment.pxd":75
 *     cdef char * reference_sequence
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef int32_t  _qpos
 *     cdef AlignedSegment _alignment
 */
struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead {
  PyObject_HEAD
  int32_t _qpos;
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
  uint32_t _is_refskip;
};


/* "pysam/libcalignmentfile.pxd":41
 * 
 * 
 * cdef class AlignmentHeader(object):             # <<<<<<<<<<<<<<
 *     cdef bam_hdr_t *ptr
 * 
 */
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader {
  PyObject_HEAD
  bam_hdr_t *ptr;
};


/* "pysam/libcalignmentfile.pxd":44
 *     cdef bam_hdr_t *ptr
 * 
 * cdef class AlignmentFile(HTSFile):             # <<<<<<<<<<<<<<
 *     cdef readonly object reference_filename
 *     cdef readonly AlignmentHeader header
 */
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile {
  struct __pyx_obj_5pysam_10libchtslib_HTSFile __pyx_base;
  PyObject *reference_filename;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  hts_idx_t *index;
  bam1_t *b;
};


/* "pysam/libcalignmentfile.pxd":61
 * 
 * 
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     cdef int retval
 *     cdef bam1_t * b
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow {
  PyObject_HEAD
  int retval;
  bam1_t *b;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  hts_idx_t *index;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  int owns_samfile;
};


/* "pysam/libcalignmentfile.pxd":71
 * 
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent(self)
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtab;
  hts_itr_t *iter;
};


/* "pysam/libcalignmentfile.pxd":77
 * 
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtab;
  int max_rows;
  int current_row;
};


/* "pysam/libcalignmentfile.pxd":84
 * 
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent(self)
 *     cdef int cnext(self)
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtab;
};


/* "pysam/libcalignmentfile.pxd":89
 * 
 * 
 * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int         tid
 *     cdef IteratorRowRegion rowiter
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  int tid;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *rowiter;
};


/* "pysam/libcalignmentfile.pxd":94
 * 
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtab;
  int current_pos;
  PyObject *positions;
};


/* "pysam/libcalignmentfile.pxd":101
 * 
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *iter;
  int tid;
  int pos;
  int n_plp;
  uint32_t min_base_quality;
  bam_pileup1_t const *plp;
  bam_mplp_t pileup_iter;
  __pyx_t_5pysam_17libcalignmentfile___iterdata iterdata;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile;
  struct __pyx_obj_5pysam_9libcfaidx_FastaFile *fastafile;
  PyObject *stepper;
  int max_depth;
  int ignore_overlaps;
};


/* "pysam/libcalignmentfile.pxd":133
 * 
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int stop
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
  int start;
  int stop;
  int truncate;
};


/* "pysam/libcalignmentfile.pxd":139
 * 
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};


/* "pysam/libcalignmentfile.pxd":143
 * 
 * 
 * cdef class IteratorColumnAll(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};


/* "pysam/libcalignmentfile.pxd":147
 * 
 * 
 * cdef class IndexedReads:             # <<<<<<<<<<<<<<
 *     cdef AlignmentFile samfile
 *     cdef htsFile * htsfile
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads {
  PyObject_HEAD
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  PyObject *index;
  int owns_samfile;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
};


/* "pysam/libcalignmentfile.pyx":2823
 * 
 * 
 * cdef class SNPCall:             # <<<<<<<<<<<<<<
 *     '''the results of a SNP call.'''
 *     cdef int _tid
 */
struct __pyx_obj_5pysam_17libcalignmentfile_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/libchtslib.pxd":2677
 * 
 * 
 * cdef class HTSFile(object):             # <<<<<<<<<<<<<<
 *     cdef          htsFile *htsfile       # pointer to htsFile structure
 *     cdef          int64_t start_offset   # BGZF offset of first record
 */

struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile {
  htsFile *(*_open_htsfile)(struct __pyx_obj_5pysam_10libchtslib_HTSFile *);
};
static struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtabptr_5pysam_10libchtslib_HTSFile;


/* "pysam/libcfaidx.pxd":37
 *                     int * dret)
 * 
 * cdef class FastaFile:             # <<<<<<<<<<<<<<
 *     cdef bint is_remote
 *     cdef object _filename, _references, _lengths, reference2length
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile {
  char *(*_fetch)(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *, char *, int, int, int *);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam_9libcfaidx_FastaFile;


/* "pysam/libcfaidx.pxd":45
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 *     cdef cython.str to_string(self)
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy {
  PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *);
  arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy;


/* "pysam/libcfaidx.pxd":52
 * 
 * 
 * cdef class FastxRecord:             # <<<<<<<<<<<<<<
 *     """
 *     Python container for pysam.libcfaidx.FastqProxy with persistence.
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord {
  PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *);
  arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord;


/* "pysam/libcfaidx.pxd":61
 *     cpdef array.array get_quality_array(self, int offset=*)
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef BGZF * fastqfile
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile {
  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *);
  int (*cnext)(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile;


/* "pysam/libcfaidx.pxd":73
 * 
 * # Compatibility Layer for pysam 0.8.1
 * cdef class FastqFile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile {
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile *__pyx_vtabptr_5pysam_9libcfaidx_FastqFile;


/* "pysam/libcfaidx.pxd":78
 * 
 * # Compatibility Layer for pysam < 0.8
 * cdef class Fastafile(FastaFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile {
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile *__pyx_vtabptr_5pysam_9libcfaidx_Fastafile;


/* "pysam/libcalignedsegment.pxd":34
 * 
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedSegment represents
 */

struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment {
  PyObject *(*set_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args);
  PyObject *(*get_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args);
  PyObject *(*has_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*to_string)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment;


/* "pysam/libcalignmentfile.pyx":582
 * 
 * 
 * cdef class AlignmentFile(HTSFile):             # <<<<<<<<<<<<<<
 *     """AlignmentFile(filepath_or_object, mode=None, template=None,
 *     reference_names=None, reference_lengths=None, text=NULL,
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile {
  struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile __pyx_base;
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *);
  int (*write)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile;


/* "pysam/libcalignmentfile.pyx":2054
 * 
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile, int tid, int beg, int stop,
 *     int multiple_iterators=False)*
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion;


/* "pysam/libcalignmentfile.pyx":2116
 * 
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile, n, int multiple_iterators=False)*
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead;


/* "pysam/libcalignmentfile.pyx":2169
 * 
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile, int multiple_iterators=False)*
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll;


/* "pysam/libcalignmentfile.pyx":2279
 * 
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile)*
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection;


/* "pysam/libcalignmentfile.pyx":2452
 * 
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 *     '''abstract base class for iterators over columns.
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn {
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  char *(*get_sequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  PyObject *(*_setup_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args);
  PyObject *(*_setup_raw_rest_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  PyObject *(*reset)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *);
  PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;


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

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion {
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion;


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

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs {
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs;


/* "pysam/libcalignmentfile.pyx":2794
 * 
 * 
 * cdef class IteratorColumnAll(IteratorColumn):             # <<<<<<<<<<<<<<
 *     """iterates over all columns, without using an index
 *     """
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll {
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll;

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#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);
  #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
#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)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

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

/* RaiseArgTupleInvalid.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);

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

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

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* Profile.proto */
#ifndef CYTHON_PROFILE
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
  #define CYTHON_PROFILE 0
#else
  #define CYTHON_PROFILE 1
#endif
#endif
#ifndef CYTHON_TRACE_NOGIL
  #define CYTHON_TRACE_NOGIL 0
#else
  #if CYTHON_TRACE_NOGIL && !defined(CYTHON_TRACE)
    #define CYTHON_TRACE 1
  #endif
#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(frame)
  #else
    #define CYTHON_FRAME_MODIFIER
    #define CYTHON_FRAME_DEL(frame) Py_CLEAR(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_TraceFrameInit(codeobj)\
      if (codeobj) __pyx_frame_code = (PyCodeObject*) codeobj;
#if PY_VERSION_HEX >= 0x030b00a2
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->cframe->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate) PyThreadState_EnterTracing(tstate)
  #define __Pyx_LeaveTracing(tstate) PyThreadState_LeaveTracing(tstate)
#elif PY_VERSION_HEX >= 0x030a00b1
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->cframe->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate)\
      do { tstate->tracing++; tstate->cframe->use_tracing = 0; } while (0)
  #define __Pyx_LeaveTracing(tstate)\
      do {\
          tstate->tracing--;\
          tstate->cframe->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL)\
                                 || tstate->c_profilefunc != NULL);\
      } while (0)
#else
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate)\
      do { tstate->tracing++; tstate->use_tracing = 0; } while (0)
  #define __Pyx_LeaveTracing(tstate)\
      do {\
          tstate->tracing--;\
          tstate->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL)\
                                         || tstate->c_profilefunc != NULL);\
      } while (0)
#endif
  #ifdef WITH_THREAD
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  if (nogil) {\
      if (CYTHON_TRACE_NOGIL) {\
          PyThreadState *tstate;\
          PyGILState_STATE state = PyGILState_Ensure();\
          tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 1, 1)) {\
              __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          }\
          PyGILState_Release(state);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  } else {\
      PyThreadState* tstate = PyThreadState_GET();\
      if (__Pyx_IsTracing(tstate, 1, 1)) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #else
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  {   PyThreadState* tstate = PyThreadState_GET();\
      if (__Pyx_IsTracing(tstate, 1, 1)) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #endif
  #define __Pyx_TraceException()\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 1)) {\
          __Pyx_EnterTracing(tstate);\
          PyObject *exc_info = __Pyx_GetExceptionTuple(tstate);\
          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);\
          }\
          __Pyx_LeaveTracing(tstate);\
      }\
  }
  static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      __Pyx_EnterTracing(tstate);
      if (CYTHON_TRACE && tstate->c_tracefunc)
          tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result);
      if (tstate->c_profilefunc)
          tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result);
      CYTHON_FRAME_DEL(frame);
      __Pyx_LeaveTracing(tstate);
      __Pyx_ErrRestoreInState(tstate, type, value, traceback);
  }
  #ifdef WITH_THREAD
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      if (nogil) {\
          if (CYTHON_TRACE_NOGIL) {\
              PyThreadState *tstate;\
              PyGILState_STATE state = PyGILState_Ensure();\
              tstate = __Pyx_PyThreadState_Current;\
              if (__Pyx_IsTracing(tstate, 0, 0)) {\
                  __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
              }\
              PyGILState_Release(state);\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 0, 0)) {\
              __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
          }\
      }\
  }
  #else
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 0)) {\
          __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
      }\
  }
  #endif
  static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno);
  static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno);
#else
  #define __Pyx_TraceDeclarations
  #define __Pyx_TraceFrameInit(codeobj)
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)   if ((1)); else goto_error;
  #define __Pyx_TraceException()
  #define __Pyx_TraceReturn(result, nogil)
#endif
#if CYTHON_TRACE
  static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) {
      int ret;
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      __Pyx_PyFrame_SetLineNumber(frame, lineno);
      __Pyx_EnterTracing(tstate);
      ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
      __Pyx_LeaveTracing(tstate);
      if (likely(!ret)) {
          __Pyx_ErrRestoreInState(tstate, type, value, traceback);
      } else {
          Py_XDECREF(type);
          Py_XDECREF(value);
          Py_XDECREF(traceback);
      }
      return ret;
  }
  #ifdef WITH_THREAD
  #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  if (likely(!__Pyx_use_tracing)); else {\
      if (nogil) {\
          if (CYTHON_TRACE_NOGIL) {\
              int ret = 0;\
              PyThreadState *tstate;\
              PyGILState_STATE state = PyGILState_Ensure();\
              tstate = __Pyx_PyThreadState_Current;\
              if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
                  ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              }\
              PyGILState_Release(state);\
              if (unlikely(ret)) goto_error;\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
              int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              if (unlikely(ret)) goto_error;\
          }\
      }\
  }
  #else
  #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
          int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
          if (unlikely(ret)) goto_error;\
      }\
  }
  #endif
#else
  #define __Pyx_TraceLine(lineno, nogil, goto_error)   if ((1)); else goto_error;
#endif

/* IncludeStringH.proto */
#include <string.h>

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

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

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
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);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
#if CYTHON_FAST_PYCALL
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#endif // CYTHON_FAST_PYCALL
#endif

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

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* GetItemInt.proto */
#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 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);

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
#define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

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

/* StringJoin.proto */
#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);
#endif

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

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* PyObjectCall2Args.proto */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

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

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
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);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* SliceObject.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);

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
#define __Pyx_PyObject_Dict_GetItem(obj, name)\
    (likely(PyDict_CheckExact(obj)) ?\
     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
#endif

/* GetTopmostException.proto */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

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

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

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

/* PyObjectGetMethod.proto */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);

/* PyObjectCallMethod1.proto */
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

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

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

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

/* ArgTypeTest.proto */
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
    ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
        __Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* HasAttr.proto */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);

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

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* PyObjectCallMethod0.proto */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

/* UnpackTupleError.proto */
static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index);

/* UnpackTuple2.proto */
#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\
    (likely(is_tuple || PyTuple_Check(tuple)) ?\
        (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\
            __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\
            (__Pyx_UnpackTupleError(tuple, 2), -1)) :\
        __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple))
static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
    PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple);
static int __Pyx_unpack_tuple2_generic(
    PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple);

/* dict_iter.proto */
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_is_dict);
static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
                                              PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);

/* MergeKeywords.proto */
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AndObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAnd(op1, op2) : PyNumber_And(op1, op2))
#endif

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* pyfrozenset_new.proto */
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it);

/* PySetContains.proto */
static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq);

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

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod1.proto */
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#else
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg)  __Pyx__CallUnboundCMethod1(cfunc, self, arg)
#endif

/* CallUnboundCMethod2.proto */
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2);
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2);
#else
#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2)  __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
#endif

/* GetAttr3.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);

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

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* CallNextTpDealloc.proto */
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);

/* CallNextTpTraverse.proto */
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse);

/* CallNextTpClear.proto */
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc);

/* PyObject_GenericGetAttrNoDict.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
#endif

/* PyObject_GenericGetAttr.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
#endif

/* PyObjectGetAttrStrNoError.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);

/* SetupReduce.proto */
static int __Pyx_setup_reduce(PyObject* type_obj);

/* TypeImport.proto */
#ifndef __PYX_HAVE_RT_ImportType_proto
#define __PYX_HAVE_RT_ImportType_proto
enum __Pyx_ImportType_CheckSize {
   __Pyx_ImportType_CheckSize_Error = 0,
   __Pyx_ImportType_CheckSize_Warn = 1,
   __Pyx_ImportType_CheckSize_Ignore = 2
};
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
#endif

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

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

/* ClassMethod.proto */
#include "descrobject.h"
static CYTHON_UNUSED PyObject* __Pyx_Method_ClassMethod(PyObject *method);

/* GetNameInClass.proto */
#define __Pyx_GetNameInClass(var, nmspace, name)  (var) = __Pyx__GetNameInClass(nmspace, name)
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __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);

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

/* ArrayAPI.proto */
#ifndef _ARRAYARRAY_H
#define _ARRAYARRAY_H
typedef struct arraydescr {
    int typecode;
    int itemsize;
    PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
    int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
#if PY_MAJOR_VERSION >= 3
    char *formats;
#endif
} arraydescr;
struct arrayobject {
    PyObject_HEAD
    Py_ssize_t ob_size;
    union {
        char *ob_item;
        float *as_floats;
        double *as_doubles;
        int *as_ints;
        unsigned int *as_uints;
        unsigned char *as_uchars;
        signed char *as_schars;
        char *as_chars;
        unsigned long *as_ulongs;
        long *as_longs;
#if PY_MAJOR_VERSION >= 3
        unsigned long long *as_ulonglongs;
        long long *as_longlongs;
#endif
        short *as_shorts;
        unsigned short *as_ushorts;
        Py_UNICODE *as_pyunicodes;
        void *as_voidptr;
    } data;
    Py_ssize_t allocated;
    struct arraydescr *ob_descr;
    PyObject *weakreflist;
#if PY_MAJOR_VERSION >= 3
        int ob_exports;
#endif
};
#ifndef NO_NEWARRAY_INLINE
static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t size,
    struct arraydescr *descr) {
    arrayobject *op;
    size_t nbytes;
    if (size < 0) {
        PyErr_BadInternalCall();
        return NULL;
    }
    nbytes = size * descr->itemsize;
    if (nbytes / descr->itemsize != (size_t)size) {
        return PyErr_NoMemory();
    }
    op = (arrayobject *) type->tp_alloc(type, 0);
    if (op == NULL) {
        return NULL;
    }
    op->ob_descr = descr;
    op->allocated = size;
    op->weakreflist = NULL;
    __Pyx_SET_SIZE(op, size);
    if (size <= 0) {
        op->data.ob_item = NULL;
    }
    else {
        op->data.ob_item = PyMem_NEW(char, nbytes);
        if (op->data.ob_item == NULL) {
            Py_DECREF(op);
            return PyErr_NoMemory();
        }
    }
    return (PyObject *) op;
}
#else
PyObject* newarrayobject(PyTypeObject *type, Py_ssize_t size,
    struct arraydescr *descr);
#endif
static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
    void *items = (void*) self->data.ob_item;
    PyMem_Resize(items, char, (size_t)(n * self->ob_descr->itemsize));
    if (items == NULL) {
        PyErr_NoMemory();
        return -1;
    }
    self->data.ob_item = (char*) items;
    __Pyx_SET_SIZE(self, n);
    self->allocated = n;
    return 0;
}
static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
    void *items = (void*) self->data.ob_item;
    Py_ssize_t newsize;
    if (n < self->allocated && n*4 > self->allocated) {
        __Pyx_SET_SIZE(self, n);
        return 0;
    }
    newsize = n + (n / 2) + 1;
    if (newsize <= n) {
        PyErr_NoMemory();
        return -1;
    }
    PyMem_Resize(items, char, (size_t)(newsize * self->ob_descr->itemsize));
    if (items == NULL) {
        PyErr_NoMemory();
        return -1;
    }
    self->data.ob_item = (char*) items;
    __Pyx_SET_SIZE(self, n);
    self->allocated = newsize;
    return 0;
}
#endif

/* GCCDiagnostics.proto */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define __Pyx_HAS_GCC_DIAGNOSTIC
#endif

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);

/* CIntFromPy.proto */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntFromPy.proto */
static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);

/* CIntFromPy.proto */
static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value);

/* CIntFromPy.proto */
static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *);

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* FunctionImport.proto */
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

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

static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_raw_rest_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_stop); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/

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

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

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

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

/* Module declarations from 'cython' */

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

/* Module declarations from '__builtin__' */

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

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

/* 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.sequence' */

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

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

/* 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 'array' */

/* Module declarations from 'cpython.array' */
static PyTypeObject *__pyx_ptype_7cpython_5array_array = 0;
static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *, Py_ssize_t, int); /*proto*/
static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, char *, Py_ssize_t); /*proto*/

/* Module declarations from 'posix.types' */

/* Module declarations from 'pysam.libchtslib' */
static PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HTSFile = 0;

/* Module declarations from 'pysam.libcfaidx' */
static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastaFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxRecord = 0;
static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile = 0;

/* Module declarations from 'pysam.libcalignedsegment' */
static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = 0;
static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupRead = 0;
static struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(*__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment)(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/
static struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(*__pyx_f_5pysam_18libcalignedsegment_makePileupColumn)(bam_pileup1_t const **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/

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

/* Module declarations from 'pysam.libcutils' */
static PyObject *(*__pyx_f_5pysam_9libcutils_charptr_to_str)(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_force_str)(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_force_bytes)(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_encode_filename)(PyObject *); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_from_string_and_size)(char const *, size_t); /*proto*/

/* Module declarations from 'pysam.libcalignmentfile' */
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = 0;
static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_SNPCall = 0;
static int __pyx_v_5pysam_17libcalignmentfile_MAX_POS;
static struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_nofilter(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_all(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_samtools(void *, bam1_t *); /*proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *, PyObject *); /*proto*/
#define __Pyx_MODULE_NAME "pysam.libcalignmentfile"
extern int __pyx_module_is_main_pysam__libcalignmentfile;
int __pyx_module_is_main_pysam__libcalignmentfile = 0;

/* Implementation of 'pysam.libcalignmentfile' */
static PyObject *__pyx_builtin_ImportError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_sum;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_OSError;
static const char __pyx_k_A[] = "A";
static const char __pyx_k_C[] = "C";
static const char __pyx_k_G[] = "G";
static const char __pyx_k_L[] = "L";
static const char __pyx_k_N[] = "N";
static const char __pyx_k_T[] = "T";
static const char __pyx_k_b[] = "b";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_h[] = "h";
static const char __pyx_k_n[] = "n";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_s[] = "@%s";
static const char __pyx_k_w[] = "w";
static const char __pyx_k_AH[] = "AH";
static const char __pyx_k_AS[] = "AS";
static const char __pyx_k_CL[] = "CL";
static const char __pyx_k_CN[] = "CN";
static const char __pyx_k_CO[] = "CO";
static const char __pyx_k_DS[] = "DS";
static const char __pyx_k_DT[] = "DT";
static const char __pyx_k_FO[] = "FO";
static const char __pyx_k_GO[] = "GO";
static const char __pyx_k_HD[] = "HD";
static const char __pyx_k_ID[] = "ID";
static const char __pyx_k_KS[] = "KS";
static const char __pyx_k_LB[] = "LB";
static const char __pyx_k_LN[] = "LN";
static const char __pyx_k_M5[] = "M5";
static const char __pyx_k_PG[] = "PG";
static const char __pyx_k_PI[] = "PI";
static const char __pyx_k_PL[] = "PL";
static const char __pyx_k_PM[] = "PM";
static const char __pyx_k_PN[] = "PN";
static const char __pyx_k_PP[] = "PP";
static const char __pyx_k_PU[] = "PU";
static const char __pyx_k_RG[] = "RG";
static const char __pyx_k_SM[] = "SM";
static const char __pyx_k_SN[] = "SN";
static const char __pyx_k_SO[] = "SO";
static const char __pyx_k_SP[] = "SP";
static const char __pyx_k_SQ[] = "@SQ";
static const char __pyx_k_UR[] = "UR";
static const char __pyx_k_VN[] = "VN";
static const char __pyx_k__2[] = "\t";
static const char __pyx_k__7[] = ":";
static const char __pyx_k__9[] = "\n";
static const char __pyx_k_io[] = "io";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_rU[] = "rU";
static const char __pyx_k_rb[] = "rb";
static const char __pyx_k_rc[] = "rc";
static const char __pyx_k_re[] = "re";
static const char __pyx_k_wb[] = "wb";
static const char __pyx_k_wc[] = "wc";
static const char __pyx_k_wh[] = "wh";
static const char __pyx_k__11[] = "";
static const char __pyx_k__12[] = " \000";
static const char __pyx_k__13[] = "@";
static const char __pyx_k__24[] = "-";
static const char __pyx_k_all[] = "all";
static const char __pyx_k_beg[] = "beg";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_key[] = "key";
static const char __pyx_k_len[] = "__len__";
static const char __pyx_k_map[] = "map";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_pos[] = "pos";
static const char __pyx_k_s_s[] = "%s:%s";
static const char __pyx_k_seq[] = "seq";
static const char __pyx_k_str[] = "__str__";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_tid[] = "tid";
static const char __pyx_k_wb0[] = "wb0";
static const char __pyx_k_wbu[] = "wbu";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_SQ_2[] = "SQ";
static const char __pyx_k_code[] = "code";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_dict[] = "__dict__";
static const char __pyx_k_flag[] = "flag";
static const char __pyx_k_init[] = "__init__";
static const char __pyx_k_join[] = "join";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_line[] = "line";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_make[] = "_make";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_name[] = "name";
static const char __pyx_k_open[] = "_open";
static const char __pyx_k_port[] = "port";
static const char __pyx_k_stop[] = "stop";
static const char __pyx_k_tell[] = "tell";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_text[] = "text";
static const char __pyx_k_warn[] = "warn";
static const char __pyx_k_all_2[] = "__all__";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_fetch[] = "fetch";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_strip[] = "strip";
static const char __pyx_k_total[] = "total";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_closed[] = "closed";
static const char __pyx_k_contig[] = "contig";
static const char __pyx_k_fields[] = "fields";
static const char __pyx_k_fileno[] = "fileno";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_header[] = "header";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_is_bam[] = "is_bam";
static const char __pyx_k_mapped[] = "mapped";
static const char __pyx_k_name_2[] = "__name__";
static const char __pyx_k_pickle[] = "pickle";
static const char __pyx_k_record[] = "record";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_region[] = "region";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_Counter[] = "Counter";
static const char __pyx_k_IOError[] = "IOError";
static const char __pyx_k_Mapping[] = "Mapping";
static const char __pyx_k_OSError[] = "OSError";
static const char __pyx_k_SNPCall[] = "SNPCall";
static const char __pyx_k_get_tid[] = "get_tid";
static const char __pyx_k_getitem[] = "__getitem__";
static const char __pyx_k_is_cram[] = "is_cram";
static const char __pyx_k_is_open[] = "is_open";
static const char __pyx_k_islower[] = "islower";
static const char __pyx_k_isupper[] = "isupper";
static const char __pyx_k_lengths[] = "lengths";
static const char __pyx_k_samfile[] = "samfile";
static const char __pyx_k_stepper[] = "stepper";
static const char __pyx_k_threads[] = "threads";
static const char __pyx_k_to_dict[] = "to_dict";
static const char __pyx_k_KeyError[] = "KeyError";
static const char __pyx_k_SQ_SN_LN[] = "@SQ\tSN:{}\tLN:{}\n";
static const char __pyx_k_Sequence[] = "Sequence";
static const char __pyx_k_StringIO[] = "StringIO";
static const char __pyx_k_check_sq[] = "check_sq";
static const char __pyx_k_contains[] = "__contains__";
static const char __pyx_k_coverage[] = "coverage";
static const char __pyx_k_exc_type[] = "exc_type";
static const char __pyx_k_filename[] = "filename";
static const char __pyx_k_genotype[] = "genotype";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_nextiter[] = "nextiter";
static const char __pyx_k_nofilter[] = "nofilter";
static const char __pyx_k_pyx_type[] = "__pyx_type";
static const char __pyx_k_redo_baq[] = "redo_baq";
static const char __pyx_k_samtools[] = "samtools";
static const char __pyx_k_setstate[] = "__setstate__";
static const char __pyx_k_template[] = "template";
static const char __pyx_k_truncate[] = "truncate";
static const char __pyx_k_unmapped[] = "unmapped";
static const char __pyx_k_warnings[] = "warnings";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_exc_value[] = "exc_value";
static const char __pyx_k_fastafile[] = "fastafile";
static const char __pyx_k_from_dict[] = "from_dict";
static const char __pyx_k_from_text[] = "from_text";
static const char __pyx_k_has_index[] = "has_index";
static const char __pyx_k_max_depth[] = "max_depth";
static const char __pyx_k_positions[] = "positions";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_reference[] = "reference";
static const char __pyx_k_traceback[] = "traceback";
static const char __pyx_k_until_eof[] = "until_eof";
static const char __pyx_k_IndexStats[] = "IndexStats";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_namedtuple[] = "namedtuple";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_query_name[] = "query_name";
static const char __pyx_k_references[] = "references";
static const char __pyx_k_splitlines[] = "splitlines";
static const char __pyx_k_startswith[] = "startswith";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_IteratorRow[] = "IteratorRow";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_OrderedDict[] = "OrderedDict";
static const char __pyx_k_PickleError[] = "PickleError";
static const char __pyx_k_add_sq_text[] = "add_sq_text";
static const char __pyx_k_check_index[] = "check_index";
static const char __pyx_k_cigarstring[] = "cigarstring";
static const char __pyx_k_cigartuples[] = "cigartuples";
static const char __pyx_k_collections[] = "collections";
static const char __pyx_k_compute_baq[] = "compute_baq";
static const char __pyx_k_defaultdict[] = "defaultdict";
static const char __pyx_k_flag_filter[] = "flag_filter";
static const char __pyx_k_nreferences[] = "nreferences";
static const char __pyx_k_snp_quality[] = "snp_quality";
static const char __pyx_k_IndexedReads[] = "IndexedReads";
static const char __pyx_k_check_header[] = "check_header";
static const char __pyx_k_flag_require[] = "flag_require";
static const char __pyx_k_is_valid_tid[] = "is_valid_tid";
static const char __pyx_k_parse_region[] = "parse_region";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_stringsource[] = "stringsource";
static const char __pyx_k_AlignmentFile[] = "AlignmentFile";
static const char __pyx_k_StopIteration[] = "StopIteration";
static const char __pyx_k_VALID_HEADERS[] = "VALID_HEADERS";
static const char __pyx_k_add_reference[] = "add_reference";
static const char __pyx_k_has_reference[] = "has_reference";
static const char __pyx_k_read_callback[] = "read_callback";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_require_index[] = "require_index";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_IteratorColumn[] = "IteratorColumn";
static const char __pyx_k_IteratorRowAll[] = "IteratorRowAll";
static const char __pyx_k_add_sam_header[] = "add_sam_header";
static const char __pyx_k_filepath_index[] = "filepath_index";
static const char __pyx_k_format_options[] = "format_options";
static const char __pyx_k_ignore_orphans[] = "ignore_orphans";
static const char __pyx_k_index_filename[] = "index_filename";
static const char __pyx_k_mate_not_found[] = "mate not found";
static const char __pyx_k_reference_base[] = "reference_base";
static const char __pyx_k_referencenames[] = "referencenames";
static const char __pyx_k_truncated_file[] = "truncated file";
static const char __pyx_k_AlignmentHeader[] = "AlignmentHeader";
static const char __pyx_k_IteratorRowHead[] = "IteratorRowHead";
static const char __pyx_k_add_hts_options[] = "add_hts_options";
static const char __pyx_k_collections_abc[] = "collections.abc";
static const char __pyx_k_from_references[] = "from_references";
static const char __pyx_k_ignore_overlaps[] = "ignore_overlaps";
static const char __pyx_k_mapping_quality[] = "mapping_quality";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
static const char __pyx_k_query_qualities[] = "query_qualities";
static const char __pyx_k_reference_names[] = "reference_names";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_check_truncation[] = "check_truncation";
static const char __pyx_k_min_base_quality[] = "min_base_quality";
static const char __pyx_k_read_s_not_found[] = "read %s not found";
static const char __pyx_k_referencelengths[] = "referencelengths";
static const char __pyx_k_IteratorColumnAll[] = "IteratorColumnAll";
static const char __pyx_k_IteratorRowRegion[] = "IteratorRowRegion";
static const char __pyx_k_build_header_line[] = "build_header_line";
static const char __pyx_k_consensus_quality[] = "consensus_quality";
static const char __pyx_k_get_aligned_pairs[] = "get_aligned_pairs";
static const char __pyx_k_ignore_truncation[] = "ignore_truncation";
static const char __pyx_k_quality_threshold[] = "quality_threshold";
static const char __pyx_k_reference_lengths[] = "reference_lengths";
static const char __pyx_k_unknown_reference[] = "unknown reference {}";
static const char __pyx_k_IteratorRowAllRefs[] = "IteratorRowAllRefs";
static const char __pyx_k_VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
static const char __pyx_k_VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_filepath_or_object[] = "filepath_or_object";
static const char __pyx_k_get_reference_name[] = "get_reference_name";
static const char __pyx_k_interval_of_size_0[] = "interval of size 0";
static const char __pyx_k_mate_s_is_unmapped[] = "mate %s: is unmapped";
static const char __pyx_k_multiple_iterators[] = "multiple_iterators";
static const char __pyx_k_read_s_is_unpaired[] = "read %s: is unpaired";
static const char __pyx_k_reference_filename[] = "reference_filename";
static const char __pyx_k_KNOWN_HEADER_FIELDS[] = "KNOWN_HEADER_FIELDS";
static const char __pyx_k_NotImplementedError[] = "NotImplementedError";
static const char __pyx_k_min_mapping_quality[] = "min_mapping_quality";
static const char __pyx_k_read_failure_reason[] = "read_failure_reason";
static const char __pyx_k_IteratorColumnRegion[] = "IteratorColumnRegion";
static const char __pyx_k_IteratorRowSelection[] = "IteratorRowSelection";
static const char __pyx_k_duplicate_filehandle[] = "duplicate_filehandle";
static const char __pyx_k_get_reference_length[] = "get_reference_length";
static const char __pyx_k_pyx_unpickle_SNPCall[] = "__pyx_unpickle_SNPCall";
static const char __pyx_k_IteratorColumnAllRefs[] = "IteratorColumnAllRefs";
static const char __pyx_k_adjust_capq_threshold[] = "adjust_capq_threshold";
static const char __pyx_k_from_text_and_lengths[] = "_from_text_and_lengths";
static const char __pyx_k_header_line_without_s[] = "header line without '@': '%s'";
static const char __pyx_k_build_sequence_section[] = "_build_sequence_section";
static const char __pyx_k_could_not_parse_header[] = "could not parse header";
static const char __pyx_k_error_during_iteration[] = "error during iteration";
static const char __pyx_k_could_not_create_header[] = "could not create header";
static const char __pyx_k_pysam_libcalignmentfile[] = "pysam.libcalignmentfile";
static const char __pyx_k_could_not_allocate_bytes[] = "could not allocate {} bytes";
static const char __pyx_k_error_while_reading_file[] = "error {} while reading file";
static const char __pyx_k_unable_to_reopen_htsfile[] = "unable to reopen htsfile";
static const char __pyx_k_unable_to_open_index_file[] = "unable to open index file";
static const char __pyx_k_error_while_reading_file_2[] = "error while reading file {}: {}";
static const char __pyx_k_invalid_file_opening_mode_s[] = "invalid file opening mode `%s`";
static const char __pyx_k_pysam_libcalignmentfile_pyx[] = "pysam/libcalignmentfile.pyx";
static const char __pyx_k_unable_to_open_index_file_s[] = "unable to open index file `%s`";
static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file";
static const char __pyx_k_interval_of_size_less_than_0[] = "interval of size less than 0";
static const char __pyx_k_no_index_available_for_fetch[] = "no index available for fetch";
static const char __pyx_k_could_not_open_alignment_file[] = "could not open alignment file `{}`: {}";
static const char __pyx_k_no_index_available_for_pileup[] = "no index available for pileup";
static const char __pyx_k_could_not_open_alignment_file_2[] = "could not open alignment file `{}`";
static const char __pyx_k_fetch_called_on_bamfile_without[] = "fetch called on bamfile without index";
static const char __pyx_k_file_does_not_contain_alignment[] = "file does not contain alignment data";
static const char __pyx_k_header_line_with_invalid_type_s[] = "header line with invalid type '%s': '%s'";
static const char __pyx_k_incomplete_sequence_information[] = "incomplete sequence information in '%s'";
static const char __pyx_k_malformatted_header_no_in_field[] = "malformatted header: no ':' in field";
static const char __pyx_k_wrong_sequence_information_in_s[] = "wrong sequence information in '%s'";
static const char __pyx_k_AlignedSegment_refers_to_referen[] = "AlignedSegment refers to reference number {} that is larger than the number of references ({}) in the header";
static const char __pyx_k_AlignmentFile_mapped_only_availa[] = "AlignmentFile.mapped only available in bam files";
static const char __pyx_k_AlignmentHeader_does_not_support[] = "AlignmentHeader does not support item assignment (use header.to_dict()";
static const char __pyx_k_Cannot_add_extra_threads_when_ig[] = "Cannot add extra threads when \"ignore_truncation\" is True";
static const char __pyx_k_Incompatible_checksums_s_vs_0x50[] = "Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))";
static const char __pyx_k_Raw_iterator_set_up_without_regi[] = "Raw iterator set up without region cannot be reset";
static const char __pyx_k_SAM_file_does_not_have_a_valid_h[] = "SAM? file does not have a valid header (mode='%s'), please provide reference_names and reference_lengths";
static const char __pyx_k_access_from_StringIO_objects_not[] = "access from StringIO objects not supported";
static const char __pyx_k_can_not_iterate_over_samfile_wit[] = "can not iterate over samfile without header";
static const char __pyx_k_can_only_apply_IndexReads_on_bam[] = "can only apply IndexReads on bam files";
static const char __pyx_k_cannot_create_AlignmentHeader_re[] = "cannot create AlignmentHeader, received NULL pointer";
static const char __pyx_k_could_not_allocate_memory_of_siz[] = "could not allocate memory of size {}";
static const char __pyx_k_either_supply_options_template_h[] = "either supply options `template`, `header`, `text` or  both `reference_names` and `reference_lengths` for writing";
static const char __pyx_k_failure_when_setting_reference_f[] = "failure when setting reference filename";
static const char __pyx_k_fetching_by_region_is_not_availa[] = "fetching by region is not available for SAM files";
static const char __pyx_k_file_does_not_have_a_valid_heade[] = "file does not have a valid header (mode='%s') - is it BAM/CRAM format?";
static const char __pyx_k_file_has_no_sequences_defined_mo[] = "file has no sequences defined (mode='%s') - is it SAM/BAM format? Consider opening with check_sq=False";
static const char __pyx_k_header_not_available_in_closed_f[] = "header not available in closed files";
static const char __pyx_k_invalid_type_for_record_s_s_expe[] = "invalid type for record %s: %s, expected %s";
static const char __pyx_k_mapping_information_not_recorded[] = "mapping information not recorded in index or index not available";
static const char __pyx_k_multiple_iterators_not_implement[] = "multiple iterators not implemented for SAM files";
static const char __pyx_k_multiple_s_lines_are_not_permitt[] = "multiple '%s' lines are not permitted";
static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
static const char __pyx_k_no_index_available_for_iteration[] = "no index available for iteration";
static const char __pyx_k_not_enough_information_to_constr[] = "not enough information to construct header. Please provide template, header, text or reference_names/reference_lengths";
static const char __pyx_k_number_of_reference_names_and_le[] = "number of reference names and lengths do not match";
static const char __pyx_k_reference_id_i_out_of_range_0_ti[] = "reference_id %i out of range 0<=tid<%i";
static const char __pyx_k_reference_sequence_for_tid_not_f[] = "reference sequence for '{}' (tid={}) not found";
static const char __pyx_k_sam_write1_failed_with_error_cod[] = "sam_write1 failed with error code {}";
static const char __pyx_k_self_b_self_htsfile_self_index_c[] = "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling";
static const char __pyx_k_self_b_self_htsfile_self_index_s[] = "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling";
static const char __pyx_k_self_htsfile_cannot_be_converted[] = "self.htsfile cannot be converted to a Python object for pickling";
static const char __pyx_k_unable_to_read_header_informatio[] = "unable to read header information";
static const char __pyx_k_unknown_stepper_option_s_in_Iter[] = "unknown stepper option `%s` in IteratorColumn";
static const char __pyx_k_multiple_iterators_not_implement_2[] = "multiple_iterators not implemented for CRAM";
static PyObject *__pyx_n_s_A;
static PyObject *__pyx_n_s_AH;
static PyObject *__pyx_n_s_AS;
static PyObject *__pyx_kp_s_AlignedSegment_refers_to_referen;
static PyObject *__pyx_n_s_AlignmentFile;
static PyObject *__pyx_kp_s_AlignmentFile_mapped_only_availa;
static PyObject *__pyx_n_s_AlignmentHeader;
static PyObject *__pyx_kp_s_AlignmentHeader_does_not_support;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_n_s_C;
static PyObject *__pyx_n_s_CL;
static PyObject *__pyx_n_s_CN;
static PyObject *__pyx_n_s_CO;
static PyObject *__pyx_kp_s_Cannot_add_extra_threads_when_ig;
static PyObject *__pyx_n_s_Counter;
static PyObject *__pyx_n_s_DS;
static PyObject *__pyx_n_s_DT;
static PyObject *__pyx_n_s_FO;
static PyObject *__pyx_n_s_G;
static PyObject *__pyx_n_s_GO;
static PyObject *__pyx_n_s_HD;
static PyObject *__pyx_n_s_ID;
static PyObject *__pyx_n_s_IOError;
static PyObject *__pyx_kp_s_I_O_operation_on_closed_file;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x50;
static PyObject *__pyx_n_s_IndexStats;
static PyObject *__pyx_n_s_IndexedReads;
static PyObject *__pyx_n_s_IteratorColumn;
static PyObject *__pyx_n_s_IteratorColumnAll;
static PyObject *__pyx_n_s_IteratorColumnAllRefs;
static PyObject *__pyx_n_s_IteratorColumnRegion;
static PyObject *__pyx_n_s_IteratorRow;
static PyObject *__pyx_n_s_IteratorRowAll;
static PyObject *__pyx_n_s_IteratorRowAllRefs;
static PyObject *__pyx_n_s_IteratorRowHead;
static PyObject *__pyx_n_s_IteratorRowRegion;
static PyObject *__pyx_n_s_IteratorRowSelection;
static PyObject *__pyx_n_s_KNOWN_HEADER_FIELDS;
static PyObject *__pyx_n_s_KS;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_n_s_L;
static PyObject *__pyx_n_s_LB;
static PyObject *__pyx_n_s_LN;
static PyObject *__pyx_n_s_M5;
static PyObject *__pyx_n_s_Mapping;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_n_s_N;
static PyObject *__pyx_n_s_NotImplementedError;
static PyObject *__pyx_n_s_OSError;
static PyObject *__pyx_n_s_OrderedDict;
static PyObject *__pyx_n_s_PG;
static PyObject *__pyx_n_s_PI;
static PyObject *__pyx_n_s_PL;
static PyObject *__pyx_n_s_PM;
static PyObject *__pyx_n_s_PN;
static PyObject *__pyx_n_s_PP;
static PyObject *__pyx_n_s_PU;
static PyObject *__pyx_n_s_PickleError;
static PyObject *__pyx_n_s_RG;
static PyObject *__pyx_kp_s_Raw_iterator_set_up_without_regi;
static PyObject *__pyx_kp_s_SAM_file_does_not_have_a_valid_h;
static PyObject *__pyx_n_s_SM;
static PyObject *__pyx_n_s_SN;
static PyObject *__pyx_n_s_SNPCall;
static PyObject *__pyx_n_s_SO;
static PyObject *__pyx_n_s_SP;
static PyObject *__pyx_kp_s_SQ;
static PyObject *__pyx_n_s_SQ_2;
static PyObject *__pyx_kp_s_SQ_SN_LN;
static PyObject *__pyx_n_s_Sequence;
static PyObject *__pyx_n_s_StopIteration;
static PyObject *__pyx_n_s_StringIO;
static PyObject *__pyx_n_s_T;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_UR;
static PyObject *__pyx_n_s_VALID_HEADERS;
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_kp_s__11;
static PyObject *__pyx_kp_s__12;
static PyObject *__pyx_kp_s__13;
static PyObject *__pyx_kp_s__2;
static PyObject *__pyx_kp_b__24;
static PyObject *__pyx_kp_s__7;
static PyObject *__pyx_kp_s__9;
static PyObject *__pyx_kp_s_access_from_StringIO_objects_not;
static PyObject *__pyx_n_s_add_hts_options;
static PyObject *__pyx_n_s_add_reference;
static PyObject *__pyx_n_s_add_sam_header;
static PyObject *__pyx_n_s_add_sq_text;
static PyObject *__pyx_n_s_adjust_capq_threshold;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_all_2;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_beg;
static PyObject *__pyx_n_s_build_header_line;
static PyObject *__pyx_n_s_build_sequence_section;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_kp_s_can_not_iterate_over_samfile_wit;
static PyObject *__pyx_kp_s_can_only_apply_IndexReads_on_bam;
static PyObject *__pyx_kp_s_cannot_create_AlignmentHeader_re;
static PyObject *__pyx_n_s_check_header;
static PyObject *__pyx_n_s_check_index;
static PyObject *__pyx_n_s_check_sq;
static PyObject *__pyx_n_s_check_truncation;
static PyObject *__pyx_n_s_cigarstring;
static PyObject *__pyx_n_s_cigartuples;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_closed;
static PyObject *__pyx_n_s_code;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_collections_abc;
static PyObject *__pyx_n_s_compute_baq;
static PyObject *__pyx_n_s_consensus_quality;
static PyObject *__pyx_n_s_contains;
static PyObject *__pyx_n_s_contig;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_kp_s_could_not_allocate_bytes;
static PyObject *__pyx_kp_s_could_not_allocate_memory_of_siz;
static PyObject *__pyx_kp_s_could_not_create_header;
static PyObject *__pyx_kp_s_could_not_open_alignment_file;
static PyObject *__pyx_kp_s_could_not_open_alignment_file_2;
static PyObject *__pyx_kp_s_could_not_parse_header;
static PyObject *__pyx_n_s_coverage;
static PyObject *__pyx_n_s_defaultdict;
static PyObject *__pyx_n_s_dict;
static PyObject *__pyx_n_s_duplicate_filehandle;
static PyObject *__pyx_kp_s_either_supply_options_template_h;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_kp_s_error_during_iteration;
static PyObject *__pyx_kp_s_error_while_reading_file;
static PyObject *__pyx_kp_s_error_while_reading_file_2;
static PyObject *__pyx_n_s_exc_type;
static PyObject *__pyx_n_s_exc_value;
static PyObject *__pyx_kp_s_failure_when_setting_reference_f;
static PyObject *__pyx_n_s_fastafile;
static PyObject *__pyx_n_s_fetch;
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_contain_alignment;
static PyObject *__pyx_kp_s_file_does_not_have_a_valid_heade;
static PyObject *__pyx_kp_s_file_has_no_sequences_defined_mo;
static PyObject *__pyx_n_s_filename;
static PyObject *__pyx_n_s_fileno;
static PyObject *__pyx_n_s_filepath_index;
static PyObject *__pyx_n_s_filepath_or_object;
static PyObject *__pyx_n_s_flag;
static PyObject *__pyx_n_s_flag_filter;
static PyObject *__pyx_n_s_flag_require;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_format_options;
static PyObject *__pyx_n_s_from_dict;
static PyObject *__pyx_n_s_from_references;
static PyObject *__pyx_n_s_from_text;
static PyObject *__pyx_n_s_from_text_and_lengths;
static PyObject *__pyx_n_s_genotype;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_get_aligned_pairs;
static PyObject *__pyx_n_s_get_reference_length;
static PyObject *__pyx_n_s_get_reference_name;
static PyObject *__pyx_n_s_get_tid;
static PyObject *__pyx_n_s_getitem;
static PyObject *__pyx_n_s_getstate;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_has_index;
static PyObject *__pyx_n_s_has_reference;
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_header_not_available_in_closed_f;
static PyObject *__pyx_n_s_ignore_orphans;
static PyObject *__pyx_n_s_ignore_overlaps;
static PyObject *__pyx_n_s_ignore_truncation;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_kp_s_incomplete_sequence_information;
static PyObject *__pyx_n_s_index_filename;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_kp_s_interval_of_size_0;
static PyObject *__pyx_kp_s_interval_of_size_less_than_0;
static PyObject *__pyx_kp_s_invalid_file_opening_mode_s;
static PyObject *__pyx_kp_s_invalid_type_for_record_s_s_expe;
static PyObject *__pyx_n_s_io;
static PyObject *__pyx_n_s_is_bam;
static PyObject *__pyx_n_s_is_cram;
static PyObject *__pyx_n_s_is_open;
static PyObject *__pyx_n_s_is_valid_tid;
static PyObject *__pyx_n_s_islower;
static PyObject *__pyx_n_s_isupper;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_key;
static PyObject *__pyx_n_s_keys;
static PyObject *__pyx_n_s_len;
static PyObject *__pyx_n_s_lengths;
static PyObject *__pyx_n_s_line;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_make;
static PyObject *__pyx_kp_s_malformatted_header_no_in_field;
static PyObject *__pyx_n_s_map;
static PyObject *__pyx_n_s_mapped;
static PyObject *__pyx_kp_s_mapping_information_not_recorded;
static PyObject *__pyx_n_s_mapping_quality;
static PyObject *__pyx_kp_s_mate_not_found;
static PyObject *__pyx_kp_s_mate_s_is_unmapped;
static PyObject *__pyx_n_s_max_depth;
static PyObject *__pyx_n_s_min_base_quality;
static PyObject *__pyx_n_s_min_mapping_quality;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_multiple_iterators;
static PyObject *__pyx_kp_s_multiple_iterators_not_implement;
static PyObject *__pyx_kp_s_multiple_iterators_not_implement_2;
static PyObject *__pyx_kp_s_multiple_s_lines_are_not_permitt;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_name_2;
static PyObject *__pyx_n_s_namedtuple;
static PyObject *__pyx_n_s_new;
static PyObject *__pyx_n_s_nextiter;
static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
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_nofilter;
static PyObject *__pyx_kp_s_not_enough_information_to_constr;
static PyObject *__pyx_n_s_nreferences;
static PyObject *__pyx_kp_s_number_of_reference_names_and_le;
static PyObject *__pyx_n_s_open;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_parse_region;
static PyObject *__pyx_n_s_pickle;
static PyObject *__pyx_n_s_port;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_positions;
static PyObject *__pyx_n_s_pysam_libcalignmentfile;
static PyObject *__pyx_kp_s_pysam_libcalignmentfile_pyx;
static PyObject *__pyx_n_s_pyx_PickleError;
static PyObject *__pyx_n_s_pyx_checksum;
static PyObject *__pyx_n_s_pyx_result;
static PyObject *__pyx_n_s_pyx_state;
static PyObject *__pyx_n_s_pyx_type;
static PyObject *__pyx_n_s_pyx_unpickle_SNPCall;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_quality_threshold;
static PyObject *__pyx_n_s_query_name;
static PyObject *__pyx_n_s_query_qualities;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_rU;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rb;
static PyObject *__pyx_n_s_rc;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_n_s_read_callback;
static PyObject *__pyx_n_s_read_failure_reason;
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_redo_baq;
static PyObject *__pyx_n_s_reduce;
static PyObject *__pyx_n_s_reduce_cython;
static PyObject *__pyx_n_s_reduce_ex;
static PyObject *__pyx_n_s_reference;
static PyObject *__pyx_n_s_reference_base;
static PyObject *__pyx_n_s_reference_filename;
static PyObject *__pyx_kp_s_reference_id_i_out_of_range_0_ti;
static PyObject *__pyx_n_s_reference_lengths;
static PyObject *__pyx_n_s_reference_names;
static PyObject *__pyx_kp_s_reference_sequence_for_tid_not_f;
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_require_index;
static PyObject *__pyx_kp_s_s;
static PyObject *__pyx_kp_s_s_s;
static PyObject *__pyx_kp_s_sam_write1_failed_with_error_cod;
static PyObject *__pyx_n_s_samfile;
static PyObject *__pyx_n_s_samtools;
static PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_c;
static PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_s;
static PyObject *__pyx_kp_s_self_htsfile_cannot_be_converted;
static PyObject *__pyx_n_s_seq;
static PyObject *__pyx_n_s_setstate;
static PyObject *__pyx_n_s_setstate_cython;
static PyObject *__pyx_n_s_snp_quality;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_splitlines;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_startswith;
static PyObject *__pyx_n_s_stepper;
static PyObject *__pyx_n_s_stop;
static PyObject *__pyx_n_s_str;
static PyObject *__pyx_kp_s_stringsource;
static PyObject *__pyx_n_s_strip;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_tell;
static PyObject *__pyx_n_s_template;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_text;
static PyObject *__pyx_n_s_threads;
static PyObject *__pyx_n_s_tid;
static PyObject *__pyx_n_s_to_dict;
static PyObject *__pyx_n_s_total;
static PyObject *__pyx_n_s_traceback;
static PyObject *__pyx_n_s_truncate;
static PyObject *__pyx_kp_s_truncated_file;
static PyObject *__pyx_kp_s_unable_to_open_index_file;
static PyObject *__pyx_kp_s_unable_to_open_index_file_s;
static PyObject *__pyx_kp_s_unable_to_read_header_informatio;
static PyObject *__pyx_kp_s_unable_to_reopen_htsfile;
static PyObject *__pyx_kp_s_unknown_reference;
static PyObject *__pyx_kp_s_unknown_stepper_option_s_in_Iter;
static PyObject *__pyx_n_s_unmapped;
static PyObject *__pyx_n_s_until_eof;
static PyObject *__pyx_n_s_update;
static PyObject *__pyx_n_s_values;
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_wb0;
static PyObject *__pyx_n_s_wbu;
static PyObject *__pyx_n_s_wc;
static PyObject *__pyx_n_s_wh;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_kp_s_wrong_sequence_information_in_s;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_2read_failure_reason(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_code); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_header_dict); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_text, PyObject *__pyx_v_add_sq_text); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, int __pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_key, CYTHON_UNUSED PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_args); /* proto */
static Py_ssize_t __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_add_sam_header, CYTHON_UNUSED PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_index_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_require_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_format_options, PyObject *__pyx_v_threads); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reference, PyObject *__pyx_v_end, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_stop, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, int __pyx_v_truncate, int __pyx_v_multiple_iterators, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_query_name); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */
static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAll(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_SNPCall(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, &__pyx_n_s_get, 0, 0, 0};
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_7;
static PyObject *__pyx_int_8;
static PyObject *__pyx_int_13;
static PyObject *__pyx_int_15;
static PyObject *__pyx_int_1796;
static PyObject *__pyx_int_8000;
static PyObject *__pyx_int_84615809;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_neg_2;
static int __pyx_k__61;
static PyObject *__pyx_codeobj_;
static PyObject *__pyx_slice__6;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__14;
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__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__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__47;
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__57;
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__65;
static PyObject *__pyx_tuple__66;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__68;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__70;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__74;
static PyObject *__pyx_tuple__75;
static PyObject *__pyx_tuple__76;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__78;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_tuple__80;
static PyObject *__pyx_tuple__81;
static PyObject *__pyx_tuple__82;
static PyObject *__pyx_codeobj__4;
static PyObject *__pyx_codeobj__72;
/* Late includes */

/* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_1build_header_line(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_build_header_line[] = "build_header_line(fields, record)\nbuild a header line from `fields` dictionary for `record`";
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_1build_header_line = {"build_header_line", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_1build_header_line, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_build_header_line};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_1build_header_line(PyObject *__pyx_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("build_header_line (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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_fields)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_record)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, 1); __PYX_ERR(0, 142, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_header_line") < 0)) __PYX_ERR(0, 142, __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("build_header_line", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 142, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.build_header_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_build_header_line(__pyx_self, __pyx_v_fields, __pyx_v_record);

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record) {
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj_)
  __Pyx_RefNannySetupContext("build_header_line", 0);
  __Pyx_TraceCall("build_header_line", __pyx_f[0], 142, 0, __PYX_ERR(0, 142, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":146
 * 
 *     # TODO: add checking for field and sort order
 *     line = ["@%s" % record]             # <<<<<<<<<<<<<<
 *         # comment
 *     if record == "CO":
 */
  __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_s, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_line = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":148
 *     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_ERR(0, 148, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":149
 *         # 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 == ((int)-1))) __PYX_ERR(0, 149, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":148
 *     line = ["@%s" % record]
 *         # comment
 *     if record == "CO":             # <<<<<<<<<<<<<<
 *         line.append(fields)
 *     # user tags
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":151
 *         line.append(fields)
 *     # user tags
 *     elif record.islower():             # <<<<<<<<<<<<<<
 *         for key in sorted(fields):
 *             line.append("%s:%s" % (key, str(fields[key])))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_record, __pyx_n_s_islower); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 151, __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_ERR(0, 151, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":152
 *     # user tags
 *     elif record.islower():
 *         for key in sorted(fields):             # <<<<<<<<<<<<<<
 *             line.append("%s:%s" % (key, str(fields[key])))
 *     # defined tags
 */
    __pyx_t_1 = PySequence_List(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_4 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 152, __pyx_L1_error)
    if (unlikely(__pyx_t_2 == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 152, __pyx_L1_error)
    }
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 152, __pyx_L1_error)
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":153
 *     elif record.islower():
 *         for key in sorted(fields):
 *             line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *     # defined tags
 *     else:
 */
      __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_key);
      __Pyx_GIVEREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":152
 *     # user tags
 *     elif record.islower():
 *         for key in sorted(fields):             # <<<<<<<<<<<<<<
 *             line.append("%s:%s" % (key, str(fields[key])))
 *     # defined tags
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":151
 *         line.append(fields)
 *     # user tags
 *     elif record.islower():             # <<<<<<<<<<<<<<
 *         for key in sorted(fields):
 *             line.append("%s:%s" % (key, str(fields[key])))
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":157
 *     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])))
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(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_ERR(0, 157, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 157, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __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_ERR(0, 157, __pyx_L1_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __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_ERR(0, 157, __pyx_L1_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #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(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 157, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":158
 *         # 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_ContainsTF(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 158, __pyx_L1_error)
      __pyx_t_8 = (__pyx_t_3 != 0);
      if (__pyx_t_8) {

        /* "pysam/libcalignmentfile.pyx":159
 *         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_5 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":158
 *         # 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
 */
      }

      /* "pysam/libcalignmentfile.pyx":157
 *     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_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":161
 *                 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 (likely(PyList_CheckExact(__pyx_v_fields)) || PyTuple_CheckExact(__pyx_v_fields)) {
      __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 161, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 161, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 161, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 161, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 161, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_7(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 161, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":162
 *         # write user fields
 *         for key in fields:
 *             if not key.isupper():             # <<<<<<<<<<<<<<
 *                 line.append("%s:%s" % (key, str(fields[key])))
 * 
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = ((!__pyx_t_8) != 0);
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":163
 *         for key in fields:
 *             if not key.isupper():
 *                 line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 * 
 *     return "\t".join(line)
 */
        __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
        __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pysam/libcalignmentfile.pyx":162
 *         # write user fields
 *         for key in fields:
 *             if not key.isupper():             # <<<<<<<<<<<<<<
 *                 line.append("%s:%s" % (key, str(fields[key])))
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":161
 *                 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])))
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":165
 *                 line.append("%s:%s" % (key, str(fields[key])))
 * 
 *     return "\t".join(line)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(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_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.build_header_line", __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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":168
 * 
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):             # <<<<<<<<<<<<<<
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 */

static struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_t *__pyx_v_hdr) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header = 0;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("makeAlignmentHeader", 0);
  __Pyx_TraceCall("makeAlignmentHeader", __pyx_f[0], 168, 0, __PYX_ERR(0, 168, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":169
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:             # <<<<<<<<<<<<<<
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_hdr != 0)) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":170
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')             # <<<<<<<<<<<<<<
 * 
 *     # check: is AlignmetHeader.__cinit__ called?
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __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_ERR(0, 170, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":169
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:             # <<<<<<<<<<<<<<
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":173
 * 
 *     # check: is AlignmetHeader.__cinit__ called?
 *     cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader)             # <<<<<<<<<<<<<<
 *     header.ptr = hdr
 * 
 */
  __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(((PyTypeObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L1_error)
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_v_header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":174
 *     # check: is AlignmetHeader.__cinit__ called?
 *     cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader)
 *     header.ptr = hdr             # <<<<<<<<<<<<<<
 * 
 *     return header
 */
  __pyx_v_header->ptr = __pyx_v_hdr;

  /* "pysam/libcalignmentfile.pyx":176
 *     header.ptr = hdr
 * 
 *     return header             # <<<<<<<<<<<<<<
 * 
 * def read_failure_reason(code):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_header));
  __pyx_r = __pyx_v_header;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":168
 * 
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):             # <<<<<<<<<<<<<<
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 */

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

/* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_3read_failure_reason(PyObject *__pyx_self, PyObject *__pyx_v_code); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_2read_failure_reason[] = "read_failure_reason(code)";
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_3read_failure_reason = {"read_failure_reason", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_3read_failure_reason, METH_O, __pyx_doc_5pysam_17libcalignmentfile_2read_failure_reason};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_3read_failure_reason(PyObject *__pyx_self, PyObject *__pyx_v_code) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("read_failure_reason (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_2read_failure_reason(__pyx_self, ((PyObject *)__pyx_v_code));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_2read_failure_reason(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_code) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  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_TraceFrameInit(__pyx_codeobj__4)
  __Pyx_RefNannySetupContext("read_failure_reason", 0);
  __Pyx_TraceCall("read_failure_reason", __pyx_f[0], 178, 0, __PYX_ERR(0, 178, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":179
 * 
 * def read_failure_reason(code):
 *     if code == -2:             # <<<<<<<<<<<<<<
 *         return 'truncated file'
 *     else:
 */
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_code, __pyx_int_neg_2, -2L, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 179, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":180
 * def read_failure_reason(code):
 *     if code == -2:
 *         return 'truncated file'             # <<<<<<<<<<<<<<
 *     else:
 *         return "error {} while reading file".format(code)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_s_truncated_file);
    __pyx_r = __pyx_kp_s_truncated_file;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":179
 * 
 * def read_failure_reason(code):
 *     if code == -2:             # <<<<<<<<<<<<<<
 *         return 'truncated file'
 *     else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":182
 *         return 'truncated file'
 *     else:
 *         return "error {} while reading file".format(code)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_error_while_reading_file, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_code) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_code);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */

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

/* "pysam/libcalignmentfile.pyx":187
 * # the following should be class-method for VariantHeader, but cdef @classmethods
 * # are not implemented in cython.
 * cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest,             # <<<<<<<<<<<<<<
 *                                         reference_names,
 *                                         reference_lengths,
 */

static int __pyx_f_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list(CYTHON_UNUSED bam_hdr_t *__pyx_v_dest, CYTHON_UNUSED PyObject *__pyx_v_reference_names, CYTHON_UNUSED PyObject *__pyx_v_reference_lengths, struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list *__pyx_optional_args) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("fill_AlignmentHeader_from_list", 0);
  __Pyx_TraceCall("fill_AlignmentHeader_from_list", __pyx_f[0], 187, 0, __PYX_ERR(0, 187, __pyx_L1_error));
  if (__pyx_optional_args) {
  }

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.fill_AlignmentHeader_from_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":228
 * 
 *     # See makeVariantHeader for C constructor
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = NULL
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 228, 0, __PYX_ERR(0, 228, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":229
 *     # See makeVariantHeader for C constructor
 *     def __cinit__(self):
 *         self.ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # Python constructor
 */
  __pyx_v_self->ptr = NULL;

  /* "pysam/libcalignmentfile.pyx":228
 * 
 *     # See makeVariantHeader for C constructor
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = NULL
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":232
 * 
 *     # Python constructor
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__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_17libcalignmentfile_15AlignmentHeader_2__init__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 232, 0, __PYX_ERR(0, 232, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":233
 *     # Python constructor
 *     def __init__(self):
 *         self.ptr = bam_hdr_init()             # <<<<<<<<<<<<<<
 *         if self.ptr is NULL:
 *             raise MemoryError("could not create header")
 */
  __pyx_v_self->ptr = bam_hdr_init();

  /* "pysam/libcalignmentfile.pyx":234
 *     def __init__(self):
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not create header")
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->ptr == NULL) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":235
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 *             raise MemoryError("could not create header")             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __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_ERR(0, 235, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":234
 *     def __init__(self):
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not create header")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":232
 * 
 *     # Python constructor
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":238
 * 
 *     @classmethod
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):             # <<<<<<<<<<<<<<
 * 
 *         cdef AlignmentHeader self = AlignmentHeader()
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths[] = "AlignmentHeader._from_text_and_lengths(type cls, text, reference_names, reference_lengths)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_reference_names = 0;
  PyObject *__pyx_v_reference_lengths = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_from_text_and_lengths (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_text,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, 1); __PYX_ERR(0, 238, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, 2); __PYX_ERR(0, 238, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_from_text_and_lengths") < 0)) __PYX_ERR(0, 238, __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_text = values[0];
    __pyx_v_reference_names = values[1];
    __pyx_v_reference_lengths = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 238, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._from_text_and_lengths", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(((PyTypeObject*)__pyx_v_cls), __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths);

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self = 0;
  char *__pyx_v_ctext;
  int __pyx_v_l_text;
  int __pyx_v_n;
  int __pyx_v_x;
  PyObject *__pyx_v_btext = NULL;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_ref = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  char *__pyx_t_4;
  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 *);
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int32_t __pyx_t_13;
  uint32_t __pyx_t_14;
  char const *__pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_from_text_and_lengths", 0);
  __Pyx_TraceCall("_from_text_and_lengths", __pyx_f[0], 238, 0, __PYX_ERR(0, 238, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_reference_names);

  /* "pysam/libcalignmentfile.pyx":240
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 *         cdef AlignmentHeader self = AlignmentHeader()             # <<<<<<<<<<<<<<
 *         cdef char *ctext
 *         cdef int l_text
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_self = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":244
 *         cdef int l_text
 *         cdef int n, x
 *         if text is not None:             # <<<<<<<<<<<<<<
 *             btext = force_bytes(text)
 *             ctext = btext
 */
  __pyx_t_2 = (__pyx_v_text != Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":245
 *         cdef int n, x
 *         if text is not None:
 *             btext = force_bytes(text)             # <<<<<<<<<<<<<<
 *             ctext = btext
 *             l_text = len(btext)
 */
    __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_text, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_btext = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":246
 *         if text is not None:
 *             btext = force_bytes(text)
 *             ctext = btext             # <<<<<<<<<<<<<<
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 */
    if (unlikely(__pyx_v_btext == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
      __PYX_ERR(0, 246, __pyx_L1_error)
    }
    __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_btext); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 246, __pyx_L1_error)
    __pyx_v_ctext = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":247
 *             btext = force_bytes(text)
 *             ctext = btext
 *             l_text = len(btext)             # <<<<<<<<<<<<<<
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:
 */
    if (unlikely(__pyx_v_btext == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 247, __pyx_L1_error)
    }
    __pyx_t_5 = PyBytes_GET_SIZE(__pyx_v_btext); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 247, __pyx_L1_error)
    __pyx_v_l_text = __pyx_t_5;

    /* "pysam/libcalignmentfile.pyx":248
 *             ctext = btext
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *             if self.ptr.text == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 */
    __pyx_v_self->ptr->text = ((char *)calloc((__pyx_v_l_text + 1), (sizeof(char))));

    /* "pysam/libcalignmentfile.pyx":249
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text
 */
    __pyx_t_3 = ((__pyx_v_self->ptr->text == NULL) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":250
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))             # <<<<<<<<<<<<<<
 *             self.ptr.l_text = l_text
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyInt_From_long((__pyx_v_l_text + 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyInt_FromSize_t((sizeof(char))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
      __pyx_t_1 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __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_ERR(0, 250, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":249
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text
 */
    }

    /* "pysam/libcalignmentfile.pyx":251
 *             if self.ptr.text == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text             # <<<<<<<<<<<<<<
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 * 
 */
    __pyx_v_self->ptr->l_text = __pyx_v_l_text;

    /* "pysam/libcalignmentfile.pyx":252
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text
 *             memcpy(self.ptr.text, ctext, l_text + 1)             # <<<<<<<<<<<<<<
 * 
 *         if reference_names and reference_lengths:
 */
    (void)(memcpy(__pyx_v_self->ptr->text, __pyx_v_ctext, (__pyx_v_l_text + 1)));

    /* "pysam/libcalignmentfile.pyx":244
 *         cdef int l_text
 *         cdef int n, x
 *         if text is not None:             # <<<<<<<<<<<<<<
 *             btext = force_bytes(text)
 *             ctext = btext
 */
  }

  /* "pysam/libcalignmentfile.pyx":254
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 * 
 *         if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *             reference_names = [force_bytes(ref) for ref in reference_names]
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 254, __pyx_L1_error)
  if (__pyx_t_2) {
  } else {
    __pyx_t_3 = __pyx_t_2;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 254, __pyx_L1_error)
  __pyx_t_3 = __pyx_t_2;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":255
 * 
 *         if reference_names and reference_lengths:
 *             reference_names = [force_bytes(ref) for ref in reference_names]             # <<<<<<<<<<<<<<
 * 
 *             self.ptr.n_targets = len(reference_names)
 */
    __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 255, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (likely(PyList_CheckExact(__pyx_v_reference_names)) || PyTuple_CheckExact(__pyx_v_reference_names)) {
      __pyx_t_7 = __pyx_v_reference_names; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_reference_names); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 255, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 255, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_9)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 255, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 255, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_9(__pyx_t_7);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 255, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_ref, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_6, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 255, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysam/libcalignmentfile.pyx":257
 *             reference_names = [force_bytes(ref) for ref in reference_names]
 * 
 *             self.ptr.n_targets = len(reference_names)             # <<<<<<<<<<<<<<
 * 
 *             n = sum([len(reference_names) + 1])
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 257, __pyx_L1_error)
    __pyx_v_self->ptr->n_targets = __pyx_t_5;

    /* "pysam/libcalignmentfile.pyx":259
 *             self.ptr.n_targets = len(reference_names)
 * 
 *             n = sum([len(reference_names) + 1])             # <<<<<<<<<<<<<<
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 259, __pyx_L1_error)
    __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_n = __pyx_t_10;

    /* "pysam/libcalignmentfile.pyx":260
 * 
 *             n = sum([len(reference_names) + 1])
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
 *             if self.ptr.target_name == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 */
    __pyx_v_self->ptr->target_name = ((char **)calloc(__pyx_v_n, (sizeof(char *))));

    /* "pysam/libcalignmentfile.pyx":261
 *             n = sum([len(reference_names) + 1])
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 * 
 */
    __pyx_t_3 = ((__pyx_v_self->ptr->target_name == NULL) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":262
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))             # <<<<<<<<<<<<<<
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyInt_FromSize_t((sizeof(char *))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_11 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_1, __pyx_t_8};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_1, __pyx_t_8};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_11) {
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_10, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_1 = 0;
        __pyx_t_8 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 262, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":261
 *             n = sum([len(reference_names) + 1])
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":264
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
 *             if self.ptr.target_len == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 */
    __pyx_v_self->ptr->target_len = ((uint32_t *)calloc(__pyx_v_n, (sizeof(uint32_t))));

    /* "pysam/libcalignmentfile.pyx":265
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *             if self.ptr.target_len == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 * 
 */
    __pyx_t_3 = ((__pyx_v_self->ptr->target_len == NULL) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":266
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *             if self.ptr.target_len == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))             # <<<<<<<<<<<<<<
 * 
 *             for x from 0 <= x < self.ptr.n_targets:
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_8 = __Pyx_PyInt_FromSize_t((sizeof(uint32_t))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_1 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_12, __pyx_t_8};
        __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 266, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_12, __pyx_t_8};
        __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 266, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 266, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_12);
        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
        __pyx_t_12 = 0;
        __pyx_t_8 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 266, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 266, __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_ERR(0, 266, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":265
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *             if self.ptr.target_len == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":268
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 * 
 *             for x from 0 <= x < self.ptr.n_targets:             # <<<<<<<<<<<<<<
 *                 self.ptr.target_len[x] = reference_lengths[x]
 *                 name = reference_names[x]
 */
    __pyx_t_13 = __pyx_v_self->ptr->n_targets;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_13; __pyx_v_x++) {

      /* "pysam/libcalignmentfile.pyx":269
 * 
 *             for x from 0 <= x < self.ptr.n_targets:
 *                 self.ptr.target_len[x] = reference_lengths[x]             # <<<<<<<<<<<<<<
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 */
      __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_reference_lengths, __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_14 = __Pyx_PyInt_As_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_14 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      (__pyx_v_self->ptr->target_len[__pyx_v_x]) = __pyx_t_14;

      /* "pysam/libcalignmentfile.pyx":270
 *             for x from 0 <= x < self.ptr.n_targets:
 *                 self.ptr.target_len[x] = reference_lengths[x]
 *                 name = reference_names[x]             # <<<<<<<<<<<<<<
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:
 */
      __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_reference_names, __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "pysam/libcalignmentfile.pyx":271
 *                 self.ptr.target_len[x] = reference_lengths[x]
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *                 if self.ptr.target_name[x] == NULL:
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 271, __pyx_L1_error)
      (__pyx_v_self->ptr->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_5 + 1), (sizeof(char))));

      /* "pysam/libcalignmentfile.pyx":272
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:             # <<<<<<<<<<<<<<
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 */
      __pyx_t_3 = (((__pyx_v_self->ptr->target_name[__pyx_v_x]) == NULL) != 0);
      if (unlikely(__pyx_t_3)) {

        /* "pysam/libcalignmentfile.pyx":273
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))             # <<<<<<<<<<<<<<
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 * 
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_5 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 273, __pyx_L1_error)
        __pyx_t_11 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_8 = __Pyx_PyInt_FromSize_t((sizeof(char))); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_12 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_12)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_12);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_7)) {
          PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_t_11, __pyx_t_8};
          __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 273, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
          PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_t_11, __pyx_t_8};
          __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 273, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        {
          __pyx_t_1 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 273, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (__pyx_t_12) {
            __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); __pyx_t_12 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_11);
          PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_t_8);
          __pyx_t_11 = 0;
          __pyx_t_8 = 0;
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 273, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __PYX_ERR(0, 273, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":272
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:             # <<<<<<<<<<<<<<
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 */
      }

      /* "pysam/libcalignmentfile.pyx":274
 *                 if self.ptr.target_name[x] == NULL:
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 *                 strncpy(self.ptr.target_name[x], name, len(name))             # <<<<<<<<<<<<<<
 * 
 *         return self
 */
      __pyx_t_15 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) __PYX_ERR(0, 274, __pyx_L1_error)
      __pyx_t_5 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 274, __pyx_L1_error)
      (void)(strncpy((__pyx_v_self->ptr->target_name[__pyx_v_x]), __pyx_t_15, __pyx_t_5));
    }

    /* "pysam/libcalignmentfile.pyx":254
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 * 
 *         if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *             reference_names = [force_bytes(ref) for ref in reference_names]
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":276
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 * 
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":238
 * 
 *     @classmethod
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):             # <<<<<<<<<<<<<<
 * 
 *         cdef AlignmentHeader self = AlignmentHeader()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._from_text_and_lengths", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_self);
  __Pyx_XDECREF(__pyx_v_btext);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_ref);
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":279
 * 
 *     @classmethod
 *     def from_text(cls, text):             # <<<<<<<<<<<<<<
 * 
 *         reference_names, reference_lengths = [], []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text(PyObject *__pyx_v_cls, PyObject *__pyx_v_text); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text[] = "AlignmentHeader.from_text(type cls, text)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text(PyObject *__pyx_v_cls, PyObject *__pyx_v_text) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_text (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_text));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text) {
  PyObject *__pyx_v_reference_names = NULL;
  PyObject *__pyx_v_reference_lengths = NULL;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  int __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_text", 0);
  __Pyx_TraceCall("from_text", __pyx_f[0], 279, 0, __PYX_ERR(0, 279, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":281
 *     def from_text(cls, text):
 * 
 *         reference_names, reference_lengths = [], []             # <<<<<<<<<<<<<<
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_reference_names = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_reference_lengths = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":282
 * 
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():             # <<<<<<<<<<<<<<
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_text, __pyx_n_s_splitlines); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 282, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 282, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 282, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_5(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 282, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":283
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):             # <<<<<<<<<<<<<<
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 283, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_kp_s_SQ) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_s_SQ);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 283, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 283, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_7) {

      /* "pysam/libcalignmentfile.pyx":284
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
      __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_kp_s__2) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_kp_s__2);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_t_3, 1, 0, NULL, NULL, &__pyx_slice__6, 1, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
        __pyx_t_3 = __pyx_t_6; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 284, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 284, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          } else {
            if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 284, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          }
        } else {
          __pyx_t_6 = __pyx_t_10(__pyx_t_3);
          if (unlikely(!__pyx_t_6)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 284, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_6);
        }
        __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "pysam/libcalignmentfile.pyx":285
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
        __Pyx_XGOTREF(__pyx_t_11);
        __Pyx_XGOTREF(__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_13);
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":286
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:
 *                     reference_names.append(fields["SN"])             # <<<<<<<<<<<<<<
 *                     reference_lengths.append(int(fields["LN"]))
 *                 except KeyError:
 */
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_reference_names, __pyx_t_3); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 286, __pyx_L8_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pysam/libcalignmentfile.pyx":287
 *                 try:
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 */
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_reference_lengths, __pyx_t_2); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 287, __pyx_L8_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "pysam/libcalignmentfile.pyx":285
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 */
        }
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        goto __pyx_L15_try_end;
        __pyx_L8_error:;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pysam/libcalignmentfile.pyx":288
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 *                 except ValueError:
 */
        __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_15) {
          __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_8) < 0) __PYX_ERR(0, 288, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_8);

          /* "pysam/libcalignmentfile.pyx":289
 *                     reference_lengths.append(int(fields["LN"]))
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 *                 except ValueError:
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))
 */
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 289, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_16 = __Pyx_PyString_FormatSafe(__pyx_kp_s_incomplete_sequence_information, __pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 289, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 289, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_Raise(__pyx_t_6, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __PYX_ERR(0, 289, __pyx_L10_except_error)
        }

        /* "pysam/libcalignmentfile.pyx":290
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 *                 except ValueError:             # <<<<<<<<<<<<<<
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
        if (__pyx_t_15) {
          __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_3, &__pyx_t_2) < 0) __PYX_ERR(0, 290, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_2);

          /* "pysam/libcalignmentfile.pyx":291
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 *                 except ValueError:
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 */
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 291, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_16 = __Pyx_PyString_FormatSafe(__pyx_kp_s_wrong_sequence_information_in_s, __pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 291, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 291, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_Raise(__pyx_t_6, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __PYX_ERR(0, 291, __pyx_L10_except_error)
        }
        goto __pyx_L10_except_error;
        __pyx_L10_except_error:;

        /* "pysam/libcalignmentfile.pyx":285
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 */
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
        goto __pyx_L1_error;
        __pyx_L15_try_end:;
      }

      /* "pysam/libcalignmentfile.pyx":283
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):             # <<<<<<<<<<<<<<
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:
 */
    }

    /* "pysam/libcalignmentfile.pyx":282
 * 
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():             # <<<<<<<<<<<<<<
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":293
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_15 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_15 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_8 = PyTuple_New(3+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_text);
    __Pyx_GIVEREF(__pyx_v_text);
    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_15, __pyx_v_text);
    __Pyx_INCREF(__pyx_v_reference_names);
    __Pyx_GIVEREF(__pyx_v_reference_names);
    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_15, __pyx_v_reference_names);
    __Pyx_INCREF(__pyx_v_reference_lengths);
    __Pyx_GIVEREF(__pyx_v_reference_lengths);
    PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_15, __pyx_v_reference_lengths);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":279
 * 
 *     @classmethod
 *     def from_text(cls, text):             # <<<<<<<<<<<<<<
 * 
 *         reference_names, reference_lengths = [], []
 */

  /* 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_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XDECREF(__pyx_v_reference_lengths);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":296
 * 
 *     @classmethod
 *     def from_dict(cls, header_dict):             # <<<<<<<<<<<<<<
 * 
 *         cdef list lines = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict(PyObject *__pyx_v_cls, PyObject *__pyx_v_header_dict); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict[] = "AlignmentHeader.from_dict(type cls, header_dict)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict(PyObject *__pyx_v_cls, PyObject *__pyx_v_header_dict) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_dict (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_header_dict));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_header_dict) {
  PyObject *__pyx_v_lines = 0;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_v_reference_names = NULL;
  PyObject *__pyx_v_reference_lengths = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_dict", 0);
  __Pyx_TraceCall("from_dict", __pyx_f[0], 296, 0, __PYX_ERR(0, 296, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":298
 *     def from_dict(cls, header_dict):
 * 
 *         cdef list lines = []             # <<<<<<<<<<<<<<
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 298, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_lines = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":300
 *         cdef list lines = []
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in header_dict:
 *                 data = header_dict[record]
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(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_ERR(0, 300, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 300, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __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_ERR(0, 300, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __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_ERR(0, 300, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #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(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 300, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":301
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 *             if record in header_dict:             # <<<<<<<<<<<<<<
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 */
    __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_header_dict, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 301, __pyx_L1_error)
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "pysam/libcalignmentfile.pyx":302
 *         for record in VALID_HEADERS:
 *             if record in header_dict:
 *                 data = header_dict[record]             # <<<<<<<<<<<<<<
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 *                     raise ValueError(
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":303
 *             if record in header_dict:
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_6 = PyObject_IsInstance(__pyx_v_data, __pyx_t_7); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_5 = ((!(__pyx_t_6 != 0)) != 0);
      if (unlikely(__pyx_t_5)) {

        /* "pysam/libcalignmentfile.pyx":305
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(             # <<<<<<<<<<<<<<
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 305, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);

        /* "pysam/libcalignmentfile.pyx":306
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))             # <<<<<<<<<<<<<<
 *                 if isinstance(data, Mapping):
 *                     lines.append(build_header_line(data, record))
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 306, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 306, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_1)) {
          PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_record, ((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_9};
          __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
          PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_record, ((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_9};
          __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (__pyx_t_8) {
            __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL;
          }
          __Pyx_INCREF(__pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_record);
          __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data)));
          __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data)));
          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, ((PyObject *)Py_TYPE(__pyx_v_data)));
          __Pyx_GIVEREF(__pyx_t_9);
          PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_t_9);
          __pyx_t_9 = 0;
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pysam/libcalignmentfile.pyx":304
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 */
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __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_ERR(0, 304, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":303
 *             if record in header_dict:
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(
 */
      }

      /* "pysam/libcalignmentfile.pyx":307
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(data, record))
 *                 else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyObject_IsInstance(__pyx_v_data, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 307, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_6 = (__pyx_t_5 != 0);
      if (__pyx_t_6) {

        /* "pysam/libcalignmentfile.pyx":308
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):
 *                     lines.append(build_header_line(data, record))             # <<<<<<<<<<<<<<
 *                 else:
 *                     for fields in header_dict[record]:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_11)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_11);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_7)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_data, __pyx_v_record};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_1);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_data, __pyx_v_record};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_1);
        } else
        #endif
        {
          __pyx_t_9 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 308, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (__pyx_t_11) {
            __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11); __pyx_t_11 = NULL;
          }
          __Pyx_INCREF(__pyx_v_data);
          __Pyx_GIVEREF(__pyx_v_data);
          PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_v_data);
          __Pyx_INCREF(__pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_v_record);
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pysam/libcalignmentfile.pyx":307
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(data, record))
 *                 else:
 */
        goto __pyx_L7;
      }

      /* "pysam/libcalignmentfile.pyx":310
 *                     lines.append(build_header_line(data, record))
 *                 else:
 *                     for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(build_header_line(fields, record))
 * 
 */
      /*else*/ {
        __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
          __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __pyx_t_13 = 0;
          __pyx_t_14 = NULL;
        } else {
          __pyx_t_13 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 310, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_14 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 310, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        for (;;) {
          if (likely(!__pyx_t_14)) {
            if (likely(PyList_CheckExact(__pyx_t_7))) {
              if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_7)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 310, __pyx_L1_error)
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            } else {
              if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 310, __pyx_L1_error)
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            }
          } else {
            __pyx_t_1 = __pyx_t_14(__pyx_t_7);
            if (unlikely(!__pyx_t_1)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 310, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":311
 *                 else:
 *                     for fields in header_dict[record]:
 *                         lines.append(build_header_line(fields, record))             # <<<<<<<<<<<<<<
 * 
 *         # then: user tags (lower case), sorted alphabetically
 */
          __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 311, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_11 = NULL;
          __pyx_t_10 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
            __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9);
            if (likely(__pyx_t_11)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_9, function);
              __pyx_t_10 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_9)) {
            PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_fields, __pyx_v_record};
            __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
            PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_fields, __pyx_v_record};
            __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          {
            __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 311, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            if (__pyx_t_11) {
              __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11); __pyx_t_11 = NULL;
            }
            __Pyx_INCREF(__pyx_v_fields);
            __Pyx_GIVEREF(__pyx_v_fields);
            PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_v_fields);
            __Pyx_INCREF(__pyx_v_record);
            __Pyx_GIVEREF(__pyx_v_record);
            PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_v_record);
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 311, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":310
 *                     lines.append(build_header_line(data, record))
 *                 else:
 *                     for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(build_header_line(fields, record))
 * 
 */
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_L7:;

      /* "pysam/libcalignmentfile.pyx":301
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 *             if record in header_dict:             # <<<<<<<<<<<<<<
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 */
    }

    /* "pysam/libcalignmentfile.pyx":300
 *         cdef list lines = []
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in header_dict:
 *                 data = header_dict[record]
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":314
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS:
 *                 continue
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_header_dict, __pyx_n_s_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_7 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PySequence_List(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_2 = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_12 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 314, __pyx_L1_error)
  if (unlikely(__pyx_t_2 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 314, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __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_ERR(0, 314, __pyx_L1_error)
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 314, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext;
      index = 0; __pyx_t_7 = __pyx_t_15(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L12_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      index = 1; __pyx_t_9 = __pyx_t_15(__pyx_t_8); if (unlikely(!__pyx_t_9)) goto __pyx_L12_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_8), 2) < 0) __PYX_ERR(0, 314, __pyx_L1_error)
      __pyx_t_15 = 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_15 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 314, __pyx_L1_error)
      __pyx_L13_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pysam/libcalignmentfile.pyx":315
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):
 *             if record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *                 continue
 *             if isinstance(data, Mapping):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 315, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (__pyx_t_5) {

      /* "pysam/libcalignmentfile.pyx":316
 *         for record, data in sorted(header_dict.items()):
 *             if record in VALID_HEADERS:
 *                 continue             # <<<<<<<<<<<<<<
 *             if isinstance(data, Mapping):
 *                 lines.append(build_header_line(data, record))
 */
      goto __pyx_L10_continue;

      /* "pysam/libcalignmentfile.pyx":315
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):
 *             if record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *                 continue
 *             if isinstance(data, Mapping):
 */
    }

    /* "pysam/libcalignmentfile.pyx":317
 *             if record in VALID_HEADERS:
 *                 continue
 *             if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                 lines.append(build_header_line(data, record))
 *             else:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyObject_IsInstance(__pyx_v_data, __pyx_t_2); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "pysam/libcalignmentfile.pyx":318
 *                 continue
 *             if isinstance(data, Mapping):
 *                 lines.append(build_header_line(data, record))             # <<<<<<<<<<<<<<
 *             else:
 *                 for fields in header_dict[record]:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_data, __pyx_v_record};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_data, __pyx_v_record};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_INCREF(__pyx_v_data);
        __Pyx_GIVEREF(__pyx_v_data);
        PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_v_data);
        __Pyx_INCREF(__pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_v_record);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":317
 *             if record in VALID_HEADERS:
 *                 continue
 *             if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                 lines.append(build_header_line(data, record))
 *             else:
 */
      goto __pyx_L15;
    }

    /* "pysam/libcalignmentfile.pyx":320
 *                 lines.append(build_header_line(data, record))
 *             else:
 *                 for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(fields, record))
 * 
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
        __pyx_t_9 = __pyx_t_2; __Pyx_INCREF(__pyx_t_9); __pyx_t_13 = 0;
        __pyx_t_4 = NULL;
      } else {
        __pyx_t_13 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 320, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 320, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (;;) {
        if (likely(!__pyx_t_4)) {
          if (likely(PyList_CheckExact(__pyx_t_9))) {
            if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_9)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 320, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          } else {
            if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 320, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_4(__pyx_t_9);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 320, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":321
 *             else:
 *                 for fields in header_dict[record]:
 *                     lines.append(build_header_line(fields, record))             # <<<<<<<<<<<<<<
 * 
 *         text = "\n".join(lines) + "\n"
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 321, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_fields, __pyx_v_record};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_fields, __pyx_v_record};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 321, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (__pyx_t_7) {
            __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_7); __pyx_t_7 = NULL;
          }
          __Pyx_INCREF(__pyx_v_fields);
          __Pyx_GIVEREF(__pyx_v_fields);
          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_fields);
          __Pyx_INCREF(__pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_record);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 321, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":320
 *                 lines.append(build_header_line(data, record))
 *             else:
 *                 for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(fields, record))
 * 
 */
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __pyx_L15:;

    /* "pysam/libcalignmentfile.pyx":314
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS:
 *                 continue
 */
    __pyx_L10_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":323
 *                     lines.append(build_header_line(fields, record))
 * 
 *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
 * 
 *         reference_names, reference_lengths = [], []
 */
  __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_v_lines); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_kp_s__9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 323, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_text = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "pysam/libcalignmentfile.pyx":325
 *         text = "\n".join(lines) + "\n"
 * 
 *         reference_names, reference_lengths = [], []             # <<<<<<<<<<<<<<
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 */
  __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_reference_names = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_v_reference_lengths = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":326
 * 
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:             # <<<<<<<<<<<<<<
 *             for fields in header_dict["SQ"]:
 *                 try:
 */
  __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_SQ_2, __pyx_v_header_dict, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 326, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_6 != 0);
  if (__pyx_t_5) {

    /* "pysam/libcalignmentfile.pyx":327
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_header_dict, __pyx_n_s_SQ_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_3 = 0;
      __pyx_t_4 = NULL;
    } else {
      __pyx_t_3 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 327, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 327, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_4)) {
        if (likely(PyList_CheckExact(__pyx_t_9))) {
          if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_9)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 327, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 327, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_4(__pyx_t_9);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 327, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":328
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
        __Pyx_XGOTREF(__pyx_t_16);
        __Pyx_XGOTREF(__pyx_t_17);
        __Pyx_XGOTREF(__pyx_t_18);
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":329
 *             for fields in header_dict["SQ"]:
 *                 try:
 *                     reference_names.append(fields["SN"])             # <<<<<<<<<<<<<<
 *                     reference_lengths.append(fields["LN"])
 *                 except KeyError:
 */
          __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L21_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_reference_names, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 329, __pyx_L21_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":330
 *                 try:
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 */
          __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 330, __pyx_L21_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_reference_lengths, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 330, __pyx_L21_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":328
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 */
        }
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
        goto __pyx_L28_try_end;
        __pyx_L21_error:;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pysam/libcalignmentfile.pyx":331
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_10) {
          __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_8) < 0) __PYX_ERR(0, 331, __pyx_L23_except_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_t_8);

          /* "pysam/libcalignmentfile.pyx":332
 *                     reference_lengths.append(fields["LN"])
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 */
          __pyx_t_11 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 332, __pyx_L23_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_incomplete_sequence_information, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 332, __pyx_L23_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 332, __pyx_L23_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_Raise(__pyx_t_11, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __PYX_ERR(0, 332, __pyx_L23_except_error)
        }
        goto __pyx_L23_except_error;
        __pyx_L23_except_error:;

        /* "pysam/libcalignmentfile.pyx":328
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 */
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_17);
        __Pyx_XGIVEREF(__pyx_t_18);
        __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
        goto __pyx_L1_error;
        __pyx_L28_try_end:;
      }

      /* "pysam/libcalignmentfile.pyx":327
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pysam/libcalignmentfile.pyx":326
 * 
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:             # <<<<<<<<<<<<<<
 *             for fields in header_dict["SQ"]:
 *                 try:
 */
  }

  /* "pysam/libcalignmentfile.pyx":334
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = NULL;
  __pyx_t_10 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
      __pyx_t_10 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_9);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
    PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_9);
  } else
  #endif
  {
    __pyx_t_1 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_INCREF(__pyx_v_text);
    __Pyx_GIVEREF(__pyx_v_text);
    PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_v_text);
    __Pyx_INCREF(__pyx_v_reference_names);
    __Pyx_GIVEREF(__pyx_v_reference_names);
    PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_v_reference_names);
    __Pyx_INCREF(__pyx_v_reference_lengths);
    __Pyx_GIVEREF(__pyx_v_reference_lengths);
    PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_10, __pyx_v_reference_lengths);
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":296
 * 
 *     @classmethod
 *     def from_dict(cls, header_dict):             # <<<<<<<<<<<<<<
 * 
 *         cdef list lines = []
 */

  /* 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_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_lines);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XDECREF(__pyx_v_reference_lengths);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":337
 * 
 *     @classmethod
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):             # <<<<<<<<<<<<<<
 * 
 *         if len(reference_names) != len(reference_lengths):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references[] = "AlignmentHeader.from_references(type cls, reference_names, reference_lengths, text=None, add_sq_text=True)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference_names = 0;
  PyObject *__pyx_v_reference_lengths = 0;
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_add_sq_text = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_references (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_text,&__pyx_n_s_add_sq_text,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    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);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("from_references", 0, 2, 4, 1); __PYX_ERR(0, 337, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sq_text);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_references") < 0)) __PYX_ERR(0, 337, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        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_reference_names = values[0];
    __pyx_v_reference_lengths = values[1];
    __pyx_v_text = values[2];
    __pyx_v_add_sq_text = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_references", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 337, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_references", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(((PyTypeObject*)__pyx_v_cls), __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_text, __pyx_v_add_sq_text);

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_text, PyObject *__pyx_v_add_sq_text) {
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_references", 0);
  __Pyx_TraceCall("from_references", __pyx_f[0], 337, 0, __PYX_ERR(0, 337, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_text);

  /* "pysam/libcalignmentfile.pyx":339
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 *         if len(reference_names) != len(reference_lengths):             # <<<<<<<<<<<<<<
 *             raise ValueError("number of reference names and lengths do not match")
 * 
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 339, __pyx_L1_error)
  __pyx_t_2 = PyObject_Length(__pyx_v_reference_lengths); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 339, __pyx_L1_error)
  __pyx_t_3 = ((__pyx_t_1 != __pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":340
 * 
 *         if len(reference_names) != len(reference_lengths):
 *             raise ValueError("number of reference names and lengths do not match")             # <<<<<<<<<<<<<<
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 340, __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_ERR(0, 340, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":339
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 *         if len(reference_names) != len(reference_lengths):             # <<<<<<<<<<<<<<
 *             raise ValueError("number of reference names and lengths do not match")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":343
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:             # <<<<<<<<<<<<<<
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(
 *                 reference_names, reference_lengths)])
 */
  __pyx_t_5 = (__pyx_v_text == Py_None);
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {
  } else {
    __pyx_t_3 = __pyx_t_6;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 343, __pyx_L1_error)
  __pyx_t_3 = __pyx_t_6;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":344
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(             # <<<<<<<<<<<<<<
 *                 reference_names, reference_lengths)])
 * 
 */
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/libcalignmentfile.pyx":345
 *         if text is None and add_sq_text:
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(
 *                 reference_names, reference_lengths)])             # <<<<<<<<<<<<<<
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 */
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_reference_names);
    __Pyx_GIVEREF(__pyx_v_reference_names);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_reference_names);
    __Pyx_INCREF(__pyx_v_reference_lengths);
    __Pyx_GIVEREF(__pyx_v_reference_lengths);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_reference_lengths);

    /* "pysam/libcalignmentfile.pyx":344
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(             # <<<<<<<<<<<<<<
 *                 reference_names, reference_lengths)])
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
      __pyx_t_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7); __pyx_t_2 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_2 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 344, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    for (;;) {
      if (likely(!__pyx_t_9)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_2); __Pyx_INCREF(__pyx_t_8); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 344, __pyx_L1_error)
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        } else {
          if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_2); __Pyx_INCREF(__pyx_t_8); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 344, __pyx_L1_error)
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        }
      } else {
        __pyx_t_8 = __pyx_t_9(__pyx_t_7);
        if (unlikely(!__pyx_t_8)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 344, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_8);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
        PyObject* sequence = __pyx_t_8;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 344, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_11 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_11);
        #else
        __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        #endif
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_12 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext;
        index = 0; __pyx_t_10 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_11);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) __PYX_ERR(0, 344, __pyx_L1_error)
        __pyx_t_13 = NULL;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_13 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 344, __pyx_L1_error)
        __pyx_L10_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_10);
      __pyx_t_10 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_SQ_SN_LN, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_10 = NULL;
      __pyx_t_14 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
          __pyx_t_14 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_x, __pyx_v_y};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_x, __pyx_v_y};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_10) {
          __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL;
        }
        __Pyx_INCREF(__pyx_v_x);
        __Pyx_GIVEREF(__pyx_v_x);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_v_x);
        __Pyx_INCREF(__pyx_v_y);
        __Pyx_GIVEREF(__pyx_v_y);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, __pyx_v_y);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyString_Join(__pyx_kp_s__11, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "pysam/libcalignmentfile.pyx":343
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:             # <<<<<<<<<<<<<<
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(
 *                 reference_names, reference_lengths)])
 */
  }

  /* "pysam/libcalignmentfile.pyx":347
 *                 reference_names, reference_lengths)])
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = NULL;
  __pyx_t_14 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_14 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_7);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_7);
  } else
  #endif
  {
    __pyx_t_11 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (__pyx_t_8) {
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_INCREF(__pyx_v_text);
    __Pyx_GIVEREF(__pyx_v_text);
    PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_14, __pyx_v_text);
    __Pyx_INCREF(__pyx_v_reference_names);
    __Pyx_GIVEREF(__pyx_v_reference_names);
    PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_14, __pyx_v_reference_names);
    __Pyx_INCREF(__pyx_v_reference_lengths);
    __Pyx_GIVEREF(__pyx_v_reference_lengths);
    PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_14, __pyx_v_reference_lengths);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":337
 * 
 *     @classmethod
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):             # <<<<<<<<<<<<<<
 * 
 *         if len(reference_names) != len(reference_lengths):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_references", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":349
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_hdr_destroy(self.ptr)
 *         self.ptr = NULL
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static void __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 349, 0, __PYX_ERR(0, 349, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":350
 * 
 *     def __dealloc__(self):
 *         bam_hdr_destroy(self.ptr)             # <<<<<<<<<<<<<<
 *         self.ptr = NULL
 * 
 */
  bam_hdr_destroy(__pyx_v_self->ptr);

  /* "pysam/libcalignmentfile.pyx":351
 *     def __dealloc__(self):
 *         bam_hdr_destroy(self.ptr)
 *         self.ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __bool__(self):
 */
  __pyx_v_self->ptr = NULL;

  /* "pysam/libcalignmentfile.pyx":349
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_hdr_destroy(self.ptr)
 *         self.ptr = NULL
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentHeader.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/libcalignmentfile.pyx":353
 *         self.ptr = NULL
 * 
 *     def __bool__(self):             # <<<<<<<<<<<<<<
 *         return self.ptr != NULL
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__(PyObject *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__bool__", 0);
  __Pyx_TraceCall("__bool__", __pyx_f[0], 353, 0, __PYX_ERR(0, 353, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":354
 * 
 *     def __bool__(self):
 *         return self.ptr != NULL             # <<<<<<<<<<<<<<
 * 
 *     def copy(self):
 */
  __pyx_r = (__pyx_v_self->ptr != NULL);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":353
 *         self.ptr = NULL
 * 
 *     def __bool__(self):             # <<<<<<<<<<<<<<
 *         return self.ptr != NULL
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":356
 *         return self.ptr != NULL
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy[] = "AlignmentHeader.copy(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("copy (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy", 0);
  __Pyx_TraceCall("copy", __pyx_f[0], 356, 0, __PYX_ERR(0, 356, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":357
 * 
 *     def copy(self):
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":356
 *         return self.ptr != NULL
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":363
 * 
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.ptr.n_targets
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 363, 0, __PYX_ERR(0, 363, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":364
 *         This is a read-only attribute."""
 *         def __get__(self):
 *             return self.ptr.n_targets             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":363
 * 
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.ptr.n_targets
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":369
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  int __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int32_t __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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 369, 0, __PYX_ERR(0, 369, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":370
 *         read-only attribute"""
 *         def __get__(self):
 *             t = []             # <<<<<<<<<<<<<<
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_t = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":372
 *             t = []
 *             cdef int x
 *             for x in range(self.ptr.n_targets):             # <<<<<<<<<<<<<<
 *                 t.append(charptr_to_str(self.ptr.target_name[x]))
 *             return tuple(t)
 */
  __pyx_t_2 = __pyx_v_self->ptr->n_targets;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_x = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":373
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 *                 t.append(charptr_to_str(self.ptr.target_name[x]))             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->ptr->target_name[__pyx_v_x]), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":374
 *             for x in range(self.ptr.n_targets):
 *                 t.append(charptr_to_str(self.ptr.target_name[x]))
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":369
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":381
 *         :attr:`pysam.AlignmentFile.references`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  int __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int32_t __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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 381, 0, __PYX_ERR(0, 381, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":382
 *         """
 *         def __get__(self):
 *             t = []             # <<<<<<<<<<<<<<
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_t = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":384
 *             t = []
 *             cdef int x
 *             for x in range(self.ptr.n_targets):             # <<<<<<<<<<<<<<
 *                 t.append(self.ptr.target_len[x])
 *             return tuple(t)
 */
  __pyx_t_2 = __pyx_v_self->ptr->n_targets;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_x = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":385
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 *                 t.append(self.ptr.target_len[x])             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 385, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":386
 *             for x in range(self.ptr.n_targets):
 *                 t.append(self.ptr.target_len[x])
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     def _build_sequence_section(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":381
 *         :attr:`pysam.AlignmentFile.references`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":388
 *             return tuple(t)
 * 
 *     def _build_sequence_section(self):             # <<<<<<<<<<<<<<
 *         """return sequence section of header.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section[] = "AlignmentHeader._build_sequence_section(self)\nreturn sequence section of header.\n\n        The sequence section is built from the list of reference names and\n        lengths stored in the BAM-file and not from any @SQ entries that\n        are part of the header's text section.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_build_sequence_section (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_v_x;
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int32_t __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;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_build_sequence_section", 0);
  __Pyx_TraceCall("_build_sequence_section", __pyx_f[0], 388, 0, __PYX_ERR(0, 388, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":397
 * 
 *         cdef int x
 *         text = []             # <<<<<<<<<<<<<<
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_text = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":398
 *         cdef int x
 *         text = []
 *         for x in range(self.ptr.n_targets):             # <<<<<<<<<<<<<<
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 *                 force_str(self.ptr.target_name[x]),
 */
  __pyx_t_2 = __pyx_v_self->ptr->n_targets;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_x = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":399
 *         text = []
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(             # <<<<<<<<<<<<<<
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_SQ_SN_LN, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 399, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "pysam/libcalignmentfile.pyx":400
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 *                 force_str(self.ptr.target_name[x]),             # <<<<<<<<<<<<<<
 *                 self.ptr.target_len[x]))
 *         return "".join(text)
 */
    __pyx_t_6 = __Pyx_PyBytes_FromString((__pyx_v_self->ptr->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 400, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/libcalignmentfile.pyx":401
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))             # <<<<<<<<<<<<<<
 *         return "".join(text)
 * 
 */
    __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 401, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (__pyx_t_8) {
        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6);
      __pyx_t_7 = 0;
      __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":399
 *         text = []
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(             # <<<<<<<<<<<<<<
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))
 */
    __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_text, __pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 399, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":402
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))
 *         return "".join(text)             # <<<<<<<<<<<<<<
 * 
 *     def to_dict(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__11, __pyx_v_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":388
 *             return tuple(t)
 * 
 *     def _build_sequence_section(self):             # <<<<<<<<<<<<<<
 *         """return sequence section of header.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._build_sequence_section", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":404
 *         return "".join(text)
 * 
 *     def to_dict(self):             # <<<<<<<<<<<<<<
 *         """return two-level dictionary with header information from the file.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict[] = "AlignmentHeader.to_dict(self)\nreturn two-level dictionary with header information from the file.\n\n        The first level contains the record (``HD``, ``SQ``, etc) and\n        the second level contains the fields (``VN``, ``LN``, etc).\n\n        The parser is validating and will raise an AssertionError if\n        if encounters any record or field tags that are not part of\n        the SAM specification. Use the\n        :attr:`pysam.AlignmentFile.text` attribute to get the unparsed\n        header.\n\n        The parsing follows the SAM format specification with the\n        exception of the ``CL`` field. This option will consume the\n        rest of a header line irrespective of any additional fields.\n        This behaviour has been added to accommodate command line\n        options that contain characters that are not valid field\n        separators.\n\n        If no @SQ entries are within the text section of the header,\n        this will be automatically added from the reference names and\n        lengths stored in the binary part of the header.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("to_dict (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__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_idx = 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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  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 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  int __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("to_dict", 0);
  __Pyx_TraceCall("to_dict", __pyx_f[0], 404, 0, __PYX_ERR(0, 404, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":427
 *         lengths stored in the binary part of the header.
 *         """
 *         result = collections.OrderedDict()             # <<<<<<<<<<<<<<
 * 
 *         # convert to python string
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":430
 * 
 *         # convert to python string
 *         t = self.__str__()             # <<<<<<<<<<<<<<
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 430, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 430, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":431
 *         # convert to python string
 *         t = self.__str__()
 *         for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *             line = line.strip(' \0')
 *             if not line:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_s__9) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_s__9);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 431, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 431, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 431, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 431, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":432
 *         t = self.__str__()
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')             # <<<<<<<<<<<<<<
 *             if not line:
 *                 continue
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, __pyx_kp_s__12) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_s__12);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_line, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":433
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')
 *             if not line:             # <<<<<<<<<<<<<<
 *                 continue
 *             assert line.startswith("@"), \
 */
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 433, __pyx_L1_error)
    __pyx_t_8 = ((!__pyx_t_7) != 0);
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":434
 *             line = line.strip(' \0')
 *             if not line:
 *                 continue             # <<<<<<<<<<<<<<
 *             assert line.startswith("@"), \
 *                 "header line without '@': '%s'" % line
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":433
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')
 *             if not line:             # <<<<<<<<<<<<<<
 *                 continue
 *             assert line.startswith("@"), \
 */
    }

    /* "pysam/libcalignmentfile.pyx":435
 *             if not line:
 *                 continue
 *             assert line.startswith("@"), \             # <<<<<<<<<<<<<<
 *                 "header line without '@': '%s'" % line
 *             fields = line[1:].split("\t")
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, __pyx_kp_s__13) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_s__13);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_8)) {

        /* "pysam/libcalignmentfile.pyx":436
 *                 continue
 *             assert line.startswith("@"), \
 *                 "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
 *             fields = line[1:].split("\t")
 *             record = fields[0]
 */
        __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_header_line_without_s, __pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __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_ERR(0, 435, __pyx_L1_error)
      }
    }
    #endif

    /* "pysam/libcalignmentfile.pyx":437
 *             assert line.startswith("@"), \
 *                 "header line without '@': '%s'" % line
 *             fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
 *             record = fields[0]
 *             assert record in VALID_HEADER_TYPES, \
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_line, 1, 0, NULL, NULL, &__pyx_slice__6, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 437, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 437, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_2, __pyx_kp_s__2) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_kp_s__2);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":438
 *                 "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)) __PYX_ERR(0, 438, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":439
 *             fields = line[1:].split("\t")
 *             record = fields[0]
 *             assert record in VALID_HEADER_TYPES, \             # <<<<<<<<<<<<<<
 *                 "header line with invalid type '%s': '%s'" % (record, line)
 * 
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!(__pyx_t_8 != 0))) {

        /* "pysam/libcalignmentfile.pyx":440
 *             record = fields[0]
 *             assert record in VALID_HEADER_TYPES, \
 *                 "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
 * 
 *             # treat comments
 */
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 440, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_record);
        __Pyx_INCREF(__pyx_v_line);
        __Pyx_GIVEREF(__pyx_v_line);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_line);
        __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_header_line_with_invalid_type_s, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 440, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        PyErr_SetObject(PyExc_AssertionError, __pyx_t_6);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __PYX_ERR(0, 439, __pyx_L1_error)
      }
    }
    #endif

    /* "pysam/libcalignmentfile.pyx":443
 * 
 *             # treat comments
 *             if record == "CO":             # <<<<<<<<<<<<<<
 *                 if record not in result:
 *                     result[record] = []
 */
    __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 443, __pyx_L1_error)
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":444
 *             # treat comments
 *             if record == "CO":
 *                 if record not in result:             # <<<<<<<<<<<<<<
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))
 */
      __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 444, __pyx_L1_error)
      __pyx_t_7 = (__pyx_t_8 != 0);
      if (__pyx_t_7) {

        /* "pysam/libcalignmentfile.pyx":445
 *             if record == "CO":
 *                 if record not in result:
 *                     result[record] = []             # <<<<<<<<<<<<<<
 *                 result[record].append("\t".join( fields[1:]))
 *                 continue
 */
        __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 445, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_6) < 0)) __PYX_ERR(0, 445, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "pysam/libcalignmentfile.pyx":444
 *             # treat comments
 *             if record == "CO":
 *                 if record not in result:             # <<<<<<<<<<<<<<
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))
 */
      }

      /* "pysam/libcalignmentfile.pyx":446
 *                 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_6 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__6, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_6, __pyx_t_2); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":447
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))
 *                 continue             # <<<<<<<<<<<<<<
 *             # the following is clumsy as generators do not work?
 *             x = {}
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":443
 * 
 *             # treat comments
 *             if record == "CO":             # <<<<<<<<<<<<<<
 *                 if record not in result:
 *                     result[record] = []
 */
    }

    /* "pysam/libcalignmentfile.pyx":449
 *                 continue
 *             # the following is clumsy as generators do not work?
 *             x = {}             # <<<<<<<<<<<<<<
 * 
 *             for idx, field in enumerate(fields[1:]):
 */
    __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_x, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":451
 *             x = {}
 * 
 *             for idx, field in enumerate(fields[1:]):             # <<<<<<<<<<<<<<
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_2 = __pyx_int_0;
    __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__6, 1, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
      __pyx_t_1 = __pyx_t_6; __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_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 451, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    for (;;) {
      if (likely(!__pyx_t_11)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 451, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 451, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_11(__pyx_t_1);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 451, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_2);
      __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2);
      __pyx_t_2 = __pyx_t_6;
      __pyx_t_6 = 0;

      /* "pysam/libcalignmentfile.pyx":452
 * 
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:             # <<<<<<<<<<<<<<
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 */
      __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s__7, __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 452, __pyx_L1_error)
      __pyx_t_8 = (__pyx_t_7 != 0);
      if (unlikely(__pyx_t_8)) {

        /* "pysam/libcalignmentfile.pyx":453
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):
 */
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 453, __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_ERR(0, 453, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":452
 * 
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:             # <<<<<<<<<<<<<<
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 */
      }

      /* "pysam/libcalignmentfile.pyx":454
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)             # <<<<<<<<<<<<<<
 *                 if key in ("CL",):
 *                     # special treatment for command line
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_field, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 454, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 454, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
        PyObject* sequence = __pyx_t_12;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 454, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_13 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_13);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        #endif
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_6)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_13);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 454, __pyx_L1_error)
        __pyx_t_15 = NULL;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L12_unpacking_done;
        __pyx_L11_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_15 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 454, __pyx_L1_error)
        __pyx_L12_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_13);
      __pyx_t_13 = 0;

      /* "pysam/libcalignmentfile.pyx":455
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):             # <<<<<<<<<<<<<<
 *                     # special treatment for command line
 *                     # statements (CL). These might contain
 */
      __Pyx_INCREF(__pyx_v_key);
      __pyx_t_12 = __pyx_v_key;
      __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_12, __pyx_n_s_CL, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 455, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_7 = (__pyx_t_8 != 0);
      if (__pyx_t_7) {

        /* "pysam/libcalignmentfile.pyx":462
 *                     # header. Thus, in contravention to the
 *                     # SAM API, consume the rest of the line.
 *                     key, value = "\t".join(fields[idx+1:]).split(":", 1)             # <<<<<<<<<<<<<<
 *                     x[key] = KNOWN_HEADER_FIELDS[record][key](value)
 *                     break
 */
        __pyx_t_12 = __Pyx_PyInt_AddObjC(__pyx_v_idx, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_13 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 0, 0, &__pyx_t_12, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_split); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
          PyObject* sequence = __pyx_t_12;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 462, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_13 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_6);
          #else
          __pyx_t_13 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 462, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 462, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 462, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
          index = 0; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L14_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_13);
          index = 1; __pyx_t_6 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_6)) goto __pyx_L14_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_6);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 462, __pyx_L1_error)
          __pyx_t_15 = NULL;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          goto __pyx_L15_unpacking_done;
          __pyx_L14_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_15 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 462, __pyx_L1_error)
          __pyx_L15_unpacking_done:;
        }
        __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_13);
        __pyx_t_13 = 0;
        __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "pysam/libcalignmentfile.pyx":463
 *                     # SAM API, consume the rest of the line.
 *                     key, value = "\t".join(fields[idx+1:]).split(":", 1)
 *                     x[key] = KNOWN_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
 *                     break
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_13 = __Pyx_PyObject_GetItem(__pyx_t_6, __pyx_v_record); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_13, __pyx_v_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_12 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_13, __pyx_v_value) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_value);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

        /* "pysam/libcalignmentfile.pyx":464
 *                     key, value = "\t".join(fields[idx+1:]).split(":", 1)
 *                     x[key] = KNOWN_HEADER_FIELDS[record][key](value)
 *                     break             # <<<<<<<<<<<<<<
 * 
 *                 # interpret type of known header record tags, default to str
 */
        goto __pyx_L9_break;

        /* "pysam/libcalignmentfile.pyx":455
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):             # <<<<<<<<<<<<<<
 *                     # special treatment for command line
 *                     # statements (CL). These might contain
 */
      }

      /* "pysam/libcalignmentfile.pyx":467
 * 
 *                 # interpret type of known header record tags, default to str
 *                 x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value)             # <<<<<<<<<<<<<<
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_14 = __Pyx_PyObject_GetItem(__pyx_t_13, __pyx_v_record); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_get); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = NULL;
      __pyx_t_16 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
          __pyx_t_16 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_13)) {
        PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_v_key, ((PyObject *)(&PyString_Type))};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 467, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
        PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_v_key, ((PyObject *)(&PyString_Type))};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 467, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      {
        __pyx_t_17 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 467, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (__pyx_t_14) {
          __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_14); __pyx_t_14 = NULL;
        }
        __Pyx_INCREF(__pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_16, __pyx_v_key);
        __Pyx_INCREF(((PyObject *)(&PyString_Type)));
        __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
        PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_16, ((PyObject *)(&PyString_Type)));
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 467, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_12 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_13, __pyx_v_value) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_value);
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

      /* "pysam/libcalignmentfile.pyx":451
 *             x = {}
 * 
 *             for idx, field in enumerate(fields[1:]):             # <<<<<<<<<<<<<<
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )
 */
    }
    __pyx_L9_break:;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":469
 *                 x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value)
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:             # <<<<<<<<<<<<<<
 *                 if record in result:
 *                     raise ValueError(
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_12 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (__pyx_t_7) {

      /* "pysam/libcalignmentfile.pyx":470
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:
 *                 if record in result:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "multiple '%s' lines are not permitted" % record)
 */
      __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 470, __pyx_L1_error)
      __pyx_t_8 = (__pyx_t_7 != 0);
      if (unlikely(__pyx_t_8)) {

        /* "pysam/libcalignmentfile.pyx":472
 *                 if record in result:
 *                     raise ValueError(
 *                         "multiple '%s' lines are not permitted" % record)             # <<<<<<<<<<<<<<
 * 
 *                 result[record] = x
 */
        __pyx_t_12 = __Pyx_PyString_FormatSafe(__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_v_record); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 472, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);

        /* "pysam/libcalignmentfile.pyx":471
 *             if VALID_HEADER_TYPES[record] == Mapping:
 *                 if record in result:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "multiple '%s' lines are not permitted" % record)
 * 
 */
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 471, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 471, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":470
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:
 *                 if record in result:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "multiple '%s' lines are not permitted" % record)
 */
      }

      /* "pysam/libcalignmentfile.pyx":474
 *                         "multiple '%s' lines are not permitted" % record)
 * 
 *                 result[record] = x             # <<<<<<<<<<<<<<
 *             elif VALID_HEADER_TYPES[record] == Sequence:
 *                 if record not in result: result[record] = []
 */
      if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_v_x) < 0)) __PYX_ERR(0, 474, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":469
 *                 x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value)
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:             # <<<<<<<<<<<<<<
 *                 if record in result:
 *                     raise ValueError(
 */
      goto __pyx_L16;
    }

    /* "pysam/libcalignmentfile.pyx":475
 * 
 *                 result[record] = x
 *             elif VALID_HEADER_TYPES[record] == Sequence:             # <<<<<<<<<<<<<<
 *                 if record not in result: result[record] = []
 *                 result[record].append(x)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_12, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":476
 *                 result[record] = x
 *             elif VALID_HEADER_TYPES[record] == Sequence:
 *                 if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                 result[record].append(x)
 * 
 */
      __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 476, __pyx_L1_error)
      __pyx_t_7 = (__pyx_t_8 != 0);
      if (__pyx_t_7) {
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 476, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_1) < 0)) __PYX_ERR(0, 476, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }

      /* "pysam/libcalignmentfile.pyx":477
 *             elif VALID_HEADER_TYPES[record] == Sequence:
 *                 if record not in result: result[record] = []
 *                 result[record].append(x)             # <<<<<<<<<<<<<<
 * 
 *         # if there are no SQ lines in the header, add the
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 477, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_x); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 477, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":475
 * 
 *                 result[record] = x
 *             elif VALID_HEADER_TYPES[record] == Sequence:             # <<<<<<<<<<<<<<
 *                 if record not in result: result[record] = []
 *                 result[record].append(x)
 */
    }
    __pyx_L16:;

    /* "pysam/libcalignmentfile.pyx":431
 *         # convert to python string
 *         t = self.__str__()
 *         for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *             line = line.strip(' \0')
 *             if not line:
 */
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/libcalignmentfile.pyx":488
 *         # 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_7 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_SQ_2, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 488, __pyx_L1_error)
  __pyx_t_8 = (__pyx_t_7 != 0);
  if (__pyx_t_8) {

    /* "pysam/libcalignmentfile.pyx":489
 *         # 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):
 *                 sq.append({'LN': length, 'SN': ref })
 */
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 489, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_sq = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":490
 *         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_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_lengths); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 490, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 490, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 490, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_5(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 490, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 490, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_12);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 490, __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_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_15 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_15(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L22_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_12 = __pyx_t_15(__pyx_t_6); if (unlikely(!__pyx_t_12)) goto __pyx_L22_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_12);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_6), 2) < 0) __PYX_ERR(0, 490, __pyx_L1_error)
        __pyx_t_15 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L23_unpacking_done;
        __pyx_L22_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_15 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 490, __pyx_L1_error)
        __pyx_L23_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_12);
      __pyx_t_12 = 0;

      /* "pysam/libcalignmentfile.pyx":491
 *             sq = []
 *             for ref, length in zip(self.references, self.lengths):
 *                 sq.append({'LN': length, 'SN': ref })             # <<<<<<<<<<<<<<
 *             result["SQ"] = sq
 * 
 */
      __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_LN, __pyx_v_length) < 0) __PYX_ERR(0, 491, __pyx_L1_error)
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SN, __pyx_v_ref) < 0) __PYX_ERR(0, 491, __pyx_L1_error)
      __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_sq, __pyx_t_1); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 491, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":490
 *         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_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":492
 *             for ref, length in zip(self.references, self.lengths):
 *                 sq.append({'LN': length, 'SN': ref })
 *             result["SQ"] = sq             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
    if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_n_s_SQ_2, __pyx_v_sq) < 0)) __PYX_ERR(0, 492, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":488
 *         # 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):
 */
  }

  /* "pysam/libcalignmentfile.pyx":494
 *             result["SQ"] = sq
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def as_dict(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":404
 *         return "".join(text)
 * 
 *     def to_dict(self):             # <<<<<<<<<<<<<<
 *         """return two-level dictionary with header information from the file.
 * 
 */

  /* 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_6);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.to_dict", __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_idx);
  __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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":496
 *         return result
 * 
 *     def as_dict(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict[] = "AlignmentHeader.as_dict(self)\ndeprecated, use :meth:`to_dict()` instead";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_dict (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("as_dict", 0);
  __Pyx_TraceCall("as_dict", __pyx_f[0], 496, 0, __PYX_ERR(0, 496, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":498
 *     def as_dict(self):
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_name(self, tid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 498, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 498, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":496
 *         return result
 * 
 *     def as_dict(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()
 */

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

/* "pysam/libcalignmentfile.pyx":500
 *         return self.to_dict()
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         if tid == -1:
 *             return None
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name[] = "AlignmentHeader.get_reference_name(self, tid)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_reference_name", 0);
  __Pyx_TraceCall("get_reference_name", __pyx_f[0], 500, 0, __PYX_ERR(0, 500, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":501
 * 
 *     def get_reference_name(self, tid):
 *         if tid == -1:             # <<<<<<<<<<<<<<
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:
 */
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_tid, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":502
 *     def get_reference_name(self, tid):
 *         if tid == -1:
 *             return None             # <<<<<<<<<<<<<<
 *         if not 0 <= tid < self.ptr.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":501
 * 
 *     def get_reference_name(self, tid):
 *         if tid == -1:             # <<<<<<<<<<<<<<
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:
 */
  }

  /* "pysam/libcalignmentfile.pyx":503
 *         if tid == -1:
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error)
  if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_4)) {

    /* "pysam/libcalignmentfile.pyx":505
 *         if not 0 <= tid < self.ptr.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))             # <<<<<<<<<<<<<<
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 505, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_tid);
    __Pyx_GIVEREF(__pyx_v_tid);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_tid);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":504
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %             # <<<<<<<<<<<<<<
 *                              (tid, self.ptr.n_targets))
 *         return charptr_to_str(self.ptr.target_name[tid])
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_reference_id_i_out_of_range_0_ti, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 504, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 504, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 504, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":503
 *         if tid == -1:
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))
 */
  }

  /* "pysam/libcalignmentfile.pyx":506
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))
 *         return charptr_to_str(self.ptr.target_name[tid])             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_length(self, reference):
 */
  __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_ERR(0, 506, __pyx_L1_error)
  __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->ptr->target_name[__pyx_t_5]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":500
 *         return self.to_dict()
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         if tid == -1:
 *             return None
 */

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

/* "pysam/libcalignmentfile.pyx":508
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length[] = "AlignmentHeader.get_reference_length(self, reference)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference) {
  int __pyx_v_tid;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("get_reference_length", 0);
  __Pyx_TraceCall("get_reference_length", __pyx_f[0], 508, 0, __PYX_ERR(0, 508, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":509
 * 
 *     def get_reference_length(self, reference):
 *         cdef int tid = self.get_tid(reference)             # <<<<<<<<<<<<<<
 *         if tid < 0:
 *             raise KeyError("unknown reference {}".format(reference))
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_reference) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 509, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_tid = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":510
 *     def get_reference_length(self, reference):
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:             # <<<<<<<<<<<<<<
 *             raise KeyError("unknown reference {}".format(reference))
 *         else:
 */
  __pyx_t_5 = ((__pyx_v_tid < 0) != 0);
  if (unlikely(__pyx_t_5)) {

    /* "pysam/libcalignmentfile.pyx":511
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 *             raise KeyError("unknown reference {}".format(reference))             # <<<<<<<<<<<<<<
 *         else:
 *             return self.ptr.target_len[tid]
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_reference, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_reference) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __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_ERR(0, 511, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":510
 *     def get_reference_length(self, reference):
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:             # <<<<<<<<<<<<<<
 *             raise KeyError("unknown reference {}".format(reference))
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":513
 *             raise KeyError("unknown reference {}".format(reference))
 *         else:
 *             return self.ptr.target_len[tid]             # <<<<<<<<<<<<<<
 * 
 *     def is_valid_tid(self, int tid):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_tid])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 513, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":508
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 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.libcalignmentfile.AlignmentHeader.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":515
 *             return self.ptr.target_len[tid]
 * 
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid[] = "AlignmentHeader.is_valid_tid(self, int tid)\n\n        return True if the numerical :term:`tid` is valid; False otherwise.\n\n        Note that the unmapped tid code (-1) counts as an invalid.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid) {
  int __pyx_v_tid;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0);
  assert(__pyx_arg_tid); {
    __pyx_v_tid = __Pyx_PyInt_As_int(__pyx_arg_tid); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 515, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((int)__pyx_v_tid));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, int __pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("is_valid_tid", 0);
  __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 515, 0, __PYX_ERR(0, 515, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":521
 *         Note that the unmapped tid code (-1) counts as an invalid.
 *         """
 *         return 0 <= tid < self.ptr.n_targets             # <<<<<<<<<<<<<<
 * 
 *     def get_tid(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = (0 <= __pyx_v_tid);
  if (__pyx_t_1) {
    __pyx_t_1 = (__pyx_v_tid < __pyx_v_self->ptr->n_targets);
  }
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 521, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":515
 *             return self.ptr.target_len[tid]
 * 
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

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

/* "pysam/libcalignmentfile.pyx":523
 *         return 0 <= tid < self.ptr.n_targets
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid[] = "AlignmentHeader.get_tid(self, reference)\n\n        return the numerical :term:`tid` corresponding to\n        :term:`reference`\n\n        returns -1 if reference is not known.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tid (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference) {
  int __pyx_v_tid;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char const *__pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_tid", 0);
  __Pyx_TraceCall("get_tid", __pyx_f[0], 523, 0, __PYX_ERR(0, 523, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_reference);

  /* "pysam/libcalignmentfile.pyx":530
 *         returns -1 if reference is not known.
 *         """
 *         reference = force_bytes(reference)             # <<<<<<<<<<<<<<
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:
 */
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":531
 *         """
 *         reference = force_bytes(reference)
 *         tid = bam_name2id(self.ptr, reference)             # <<<<<<<<<<<<<<
 *         if tid < -1:
 *             raise ValueError('could not parse header')
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 531, __pyx_L1_error)
  __pyx_v_tid = bam_name2id(__pyx_v_self->ptr, __pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":532
 *         reference = force_bytes(reference)
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:             # <<<<<<<<<<<<<<
 *             raise ValueError('could not parse header')
 *         return tid
 */
  __pyx_t_3 = ((__pyx_v_tid < -1L) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":533
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:
 *             raise ValueError('could not parse header')             # <<<<<<<<<<<<<<
 *         return tid
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 533, __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_ERR(0, 533, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":532
 *         reference = force_bytes(reference)
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:             # <<<<<<<<<<<<<<
 *             raise ValueError('could not parse header')
 *         return tid
 */
  }

  /* "pysam/libcalignmentfile.pyx":534
 *         if tid < -1:
 *             raise ValueError('could not parse header')
 *         return tid             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":523
 *         return 0 <= tid < self.ptr.n_targets
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

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

/* "pysam/libcalignmentfile.pyx":536
 *         return tid
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         '''string with the full contents of the :term:`sam file` header as a
 *         string.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__[] = "string with the full contents of the :term:`sam file` header as a\n        string.\n\n        If no @SQ entries are within the text section of the header,\n        this will be automatically added from the reference names and\n        lengths stored in the binary part of the header.\n\n        See :attr:`pysam.AlignmentFile.header.to_dict()` to get a parsed\n        representation of the header.\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__;
#endif
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __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_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 536, 0, __PYX_ERR(0, 536, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":547
 *         representation of the header.
 *         '''
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)             # <<<<<<<<<<<<<<
 *         if "@SQ" not in text:
 *             text += "\n" + self._build_sequence_section()
 */
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size(__pyx_v_self->ptr->text, __pyx_v_self->ptr->l_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_text = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":548
 *         '''
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)
 *         if "@SQ" not in text:             # <<<<<<<<<<<<<<
 *             text += "\n" + self._build_sequence_section()
 *         return text
 */
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s_SQ, __pyx_v_text, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 548, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":549
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)
 *         if "@SQ" not in text:
 *             text += "\n" + self._build_sequence_section()             # <<<<<<<<<<<<<<
 *         return text
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_build_sequence_section); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Add(__pyx_kp_s__9, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_text, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":548
 *         '''
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)
 *         if "@SQ" not in text:             # <<<<<<<<<<<<<<
 *             text += "\n" + self._build_sequence_section()
 *         return text
 */
  }

  /* "pysam/libcalignmentfile.pyx":550
 *         if "@SQ" not in text:
 *             text += "\n" + self._build_sequence_section()
 *         return text             # <<<<<<<<<<<<<<
 * 
 *     # dictionary access methods, for backwards compatibility.
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_text);
  __pyx_r = __pyx_v_text;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":536
 *         return tid
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         '''string with the full contents of the :term:`sam file` header as a
 *         string.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":553
 * 
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):             # <<<<<<<<<<<<<<
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value));

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

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_key, CYTHON_UNUSED PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setitem__", 0);
  __Pyx_TraceCall("__setitem__", __pyx_f[0], 553, 0, __PYX_ERR(0, 553, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":554
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, key):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 554, __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_ERR(0, 554, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":553
 * 
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):             # <<<<<<<<<<<<<<
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":556
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__getitem__(key)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__getitem__", 0);
  __Pyx_TraceCall("__getitem__", __pyx_f[0], 556, 0, __PYX_ERR(0, 556, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":557
 * 
 *     def __getitem__(self, key):
 *         return self.to_dict().__getitem__(key)             # <<<<<<<<<<<<<<
 * 
 *     def items(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getitem); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_key) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":556
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__getitem__(key)
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":559
 *         return self.to_dict().__getitem__(key)
 * 
 *     def items(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items[] = "AlignmentHeader.items(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("items (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("items", 0);
  __Pyx_TraceCall("items", __pyx_f[0], 559, 0, __PYX_ERR(0, 559, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":560
 * 
 *     def items(self):
 *         return self.to_dict().items()             # <<<<<<<<<<<<<<
 * 
 *     # PY2 compatibility
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":559
 *         return self.to_dict().__getitem__(key)
 * 
 *     def items(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.items", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":563
 * 
 *     # PY2 compatibility
 *     def iteritems(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems[] = "AlignmentHeader.iteritems(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("iteritems (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("iteritems", 0);
  __Pyx_TraceCall("iteritems", __pyx_f[0], 563, 0, __PYX_ERR(0, 563, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":564
 *     # PY2 compatibility
 *     def iteritems(self):
 *         return self.to_dict().items()             # <<<<<<<<<<<<<<
 * 
 *     def keys(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":563
 * 
 *     # PY2 compatibility
 *     def iteritems(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":566
 *         return self.to_dict().items()
 * 
 *     def keys(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().keys()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys[] = "AlignmentHeader.keys(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("keys (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("keys", 0);
  __Pyx_TraceCall("keys", __pyx_f[0], 566, 0, __PYX_ERR(0, 566, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":567
 * 
 *     def keys(self):
 *         return self.to_dict().keys()             # <<<<<<<<<<<<<<
 * 
 *     def values(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_keys); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":566
 *         return self.to_dict().items()
 * 
 *     def keys(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().keys()
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.keys", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":569
 *         return self.to_dict().keys()
 * 
 *     def values(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().values()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values[] = "AlignmentHeader.values(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("values (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("values", 0);
  __Pyx_TraceCall("values", __pyx_f[0], 569, 0, __PYX_ERR(0, 569, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":570
 * 
 *     def values(self):
 *         return self.to_dict().values()             # <<<<<<<<<<<<<<
 * 
 *     def get(self, *args):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":569
 *         return self.to_dict().keys()
 * 
 *     def values(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().values()
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.values", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":572
 *         return self.to_dict().values()
 * 
 *     def get(self, *args):             # <<<<<<<<<<<<<<
 *         return self.to_dict().get(*args)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get[] = "AlignmentHeader.get(self, *args)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_args);

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_args) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("get", 0);
  __Pyx_TraceCall("get", __pyx_f[0], 572, 0, __PYX_ERR(0, 572, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":573
 * 
 *     def get(self, *args):
 *         return self.to_dict().get(*args)             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __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_v_args, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":572
 *         return self.to_dict().values()
 * 
 *     def get(self, *args):             # <<<<<<<<<<<<<<
 *         return self.to_dict().get(*args)
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":575
 *         return self.to_dict().get(*args)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__len__()
 * 
 */

/* Python wrapper */
static Py_ssize_t __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static Py_ssize_t __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__len__", 0);
  __Pyx_TraceCall("__len__", __pyx_f[0], 575, 0, __PYX_ERR(0, 575, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":576
 * 
 *     def __len__(self):
 *         return self.to_dict().__len__()             # <<<<<<<<<<<<<<
 * 
 *     def __contains__(self, key):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":575
 *         return self.to_dict().get(*args)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__len__()
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":578
 *         return self.to_dict().__len__()
 * 
 *     def __contains__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__contains__(key)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key));

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

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__contains__", 0);
  __Pyx_TraceCall("__contains__", __pyx_f[0], 578, 0, __PYX_ERR(0, 578, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":579
 * 
 *     def __contains__(self, key):
 *         return self.to_dict().__contains__(key)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_contains); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_key) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_5;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":578
 *         return self.to_dict().__len__()
 * 
 *     def __contains__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__contains__(key)
 * 
 */

  /* 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.libcalignmentfile.AlignmentHeader.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__[] = "AlignmentHeader.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__[] = "AlignmentHeader.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

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

/* "pysam/libcalignmentfile.pyx":738
 *     """
 * 
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 *         self.filename = None
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_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_17libcalignmentfile_13AlignmentFile___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__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_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 738, 0, __PYX_ERR(0, 738, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_args);

  /* "pysam/libcalignmentfile.pyx":739
 * 
 *     def __cinit__(self, *args, **kwargs):
 *         self.htsfile = NULL             # <<<<<<<<<<<<<<
 *         self.filename = None
 *         self.mode = None
 */
  __pyx_v_self->__pyx_base.htsfile = NULL;

  /* "pysam/libcalignmentfile.pyx":740
 *     def __cinit__(self, *args, **kwargs):
 *         self.htsfile = NULL
 *         self.filename = None             # <<<<<<<<<<<<<<
 *         self.mode = None
 *         self.threads = 1
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
  __pyx_v_self->__pyx_base.filename = Py_None;

  /* "pysam/libcalignmentfile.pyx":741
 *         self.htsfile = NULL
 *         self.filename = None
 *         self.mode = None             # <<<<<<<<<<<<<<
 *         self.threads = 1
 *         self.is_stream = False
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.mode);
  __pyx_v_self->__pyx_base.mode = Py_None;

  /* "pysam/libcalignmentfile.pyx":742
 *         self.filename = None
 *         self.mode = None
 *         self.threads = 1             # <<<<<<<<<<<<<<
 *         self.is_stream = False
 *         self.is_remote = False
 */
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.threads);
  __pyx_v_self->__pyx_base.threads = __pyx_int_1;

  /* "pysam/libcalignmentfile.pyx":743
 *         self.mode = None
 *         self.threads = 1
 *         self.is_stream = False             # <<<<<<<<<<<<<<
 *         self.is_remote = False
 *         self.index = NULL
 */
  __pyx_v_self->__pyx_base.is_stream = 0;

  /* "pysam/libcalignmentfile.pyx":744
 *         self.threads = 1
 *         self.is_stream = False
 *         self.is_remote = False             # <<<<<<<<<<<<<<
 *         self.index = NULL
 * 
 */
  __pyx_v_self->__pyx_base.is_remote = 0;

  /* "pysam/libcalignmentfile.pyx":745
 *         self.is_stream = False
 *         self.is_remote = False
 *         self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *         if "filename" in kwargs:
 */
  __pyx_v_self->index = NULL;

  /* "pysam/libcalignmentfile.pyx":747
 *         self.index = NULL
 * 
 *         if "filename" in kwargs:             # <<<<<<<<<<<<<<
 *             args = [kwargs["filename"]]
 *             del kwargs["filename"]
 */
  __pyx_t_1 = (__Pyx_PyDict_ContainsTF(__pyx_n_s_filename, __pyx_v_kwargs, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 747, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":748
 * 
 *         if "filename" in kwargs:
 *             args = [kwargs["filename"]]             # <<<<<<<<<<<<<<
 *             del kwargs["filename"]
 * 
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_kwargs, __pyx_n_s_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3);
    PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":749
 *         if "filename" in kwargs:
 *             args = [kwargs["filename"]]
 *             del kwargs["filename"]             # <<<<<<<<<<<<<<
 * 
 *         self._open(*args, **kwargs)
 */
    if (unlikely(PyDict_DelItem(__pyx_v_kwargs, __pyx_n_s_filename) < 0)) __PYX_ERR(0, 749, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":747
 *         self.index = NULL
 * 
 *         if "filename" in kwargs:             # <<<<<<<<<<<<<<
 *             args = [kwargs["filename"]]
 *             del kwargs["filename"]
 */
  }

  /* "pysam/libcalignmentfile.pyx":751
 *             del kwargs["filename"]
 * 
 *         self._open(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *         # allocate memory for iterator
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/libcalignmentfile.pyx":754
 * 
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 *         if self.b == NULL:
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 */
  __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/libcalignmentfile.pyx":755
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 *         if self.b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 */
  __pyx_t_2 = ((__pyx_v_self->b == NULL) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":756
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 *         if self.b == NULL:
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))             # <<<<<<<<<<<<<<
 * 
 *     def has_index(self):
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_memory_of_siz, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 756, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":755
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 *         if self.b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":738
 *     """
 * 
 *     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_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":758
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 *     def has_index(self):             # <<<<<<<<<<<<<<
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index[] = "AlignmentFile.has_index(self)\nreturn true if htsfile has an existing (and opened) index.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("has_index (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("has_index", 0);
  __Pyx_TraceCall("has_index", __pyx_f[0], 758, 0, __PYX_ERR(0, 758, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":761
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 *         return self.index != NULL             # <<<<<<<<<<<<<<
 * 
 *     def check_index(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":758
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 *     def has_index(self):             # <<<<<<<<<<<<<<
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 */

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

/* "pysam/libcalignmentfile.pyx":763
 *         return self.index != NULL
 * 
 *     def check_index(self):             # <<<<<<<<<<<<<<
 *         """return True if index is present.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index[] = "AlignmentFile.check_index(self)\nreturn True if index is present.\n\n        Raises\n        ------\n\n        AttributeError\n            if htsfile is :term:`SAM` formatted and thus has no index.\n\n        ValueError\n            if htsfile is closed or index could not be opened.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("check_index (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("check_index", 0);
  __Pyx_TraceCall("check_index", __pyx_f[0], 763, 0, __PYX_ERR(0, 763, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":776
 *         """
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":777
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 777, __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_ERR(0, 777, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":776
 *         """
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 */
  }

  /* "pysam/libcalignmentfile.pyx":778
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:             # <<<<<<<<<<<<<<
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = ((!__pyx_t_2) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = ((!__pyx_t_4) != 0);
  __pyx_t_3 = __pyx_t_2;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":779
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(             # <<<<<<<<<<<<<<
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 779, __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_ERR(0, 779, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":778
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:             # <<<<<<<<<<<<<<
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 */
  }

  /* "pysam/libcalignmentfile.pyx":781
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "mapping information not recorded in index "
 */
  __pyx_t_3 = ((__pyx_v_self->index == NULL) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":782
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "mapping information not recorded in index "
 *                 "or index not available")
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __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_ERR(0, 782, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":781
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "mapping information not recorded in index "
 */
  }

  /* "pysam/libcalignmentfile.pyx":785
 *                 "mapping information not recorded in index "
 *                 "or index not available")
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     def _open(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_True);
  __pyx_r = Py_True;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":763
 *         return self.index != NULL
 * 
 *     def check_index(self):             # <<<<<<<<<<<<<<
 *         """return True if index is present.
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open[] = "AlignmentFile._open(self, filepath_or_object, mode=None, AlignmentFile template=None, reference_names=None, reference_lengths=None, reference_filename=None, text=None, header=None, port=None, add_sq_text=True, add_sam_header=True, check_header=True, check_sq=True, index_filename=None, filepath_index=None, require_index=False, referencenames=None, referencelengths=None, duplicate_filehandle=True, ignore_truncation=False, format_options=None, threads=1)\nopen a sam, bam or cram formatted file.\n\n        If _open is called on an existing file, the current file\n        will be closed and a new file will be opened.\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_filepath_or_object = 0;
  PyObject *__pyx_v_mode = 0;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template = 0;
  PyObject *__pyx_v_reference_names = 0;
  PyObject *__pyx_v_reference_lengths = 0;
  PyObject *__pyx_v_reference_filename = 0;
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_header = 0;
  CYTHON_UNUSED PyObject *__pyx_v_port = 0;
  PyObject *__pyx_v_add_sq_text = 0;
  PyObject *__pyx_v_add_sam_header = 0;
  CYTHON_UNUSED PyObject *__pyx_v_check_header = 0;
  PyObject *__pyx_v_check_sq = 0;
  PyObject *__pyx_v_index_filename = 0;
  PyObject *__pyx_v_filepath_index = 0;
  PyObject *__pyx_v_require_index = 0;
  PyObject *__pyx_v_referencenames = 0;
  PyObject *__pyx_v_referencelengths = 0;
  PyObject *__pyx_v_duplicate_filehandle = 0;
  PyObject *__pyx_v_ignore_truncation = 0;
  PyObject *__pyx_v_format_options = 0;
  PyObject *__pyx_v_threads = 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_filepath_or_object,&__pyx_n_s_mode,&__pyx_n_s_template,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_reference_filename,&__pyx_n_s_text,&__pyx_n_s_header,&__pyx_n_s_port,&__pyx_n_s_add_sq_text,&__pyx_n_s_add_sam_header,&__pyx_n_s_check_header,&__pyx_n_s_check_sq,&__pyx_n_s_index_filename,&__pyx_n_s_filepath_index,&__pyx_n_s_require_index,&__pyx_n_s_referencenames,&__pyx_n_s_referencelengths,&__pyx_n_s_duplicate_filehandle,&__pyx_n_s_ignore_truncation,&__pyx_n_s_format_options,&__pyx_n_s_threads,0};
    PyObject* values[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

    /* "pysam/libcalignmentfile.pyx":789
 *     def _open(self,
 *               filepath_or_object,
 *               mode=None,             # <<<<<<<<<<<<<<
 *               AlignmentFile template=None,
 *               reference_names=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":790
 *               filepath_or_object,
 *               mode=None,
 *               AlignmentFile template=None,             # <<<<<<<<<<<<<<
 *               reference_names=None,
 *               reference_lengths=None,
 */
    values[2] = (PyObject *)((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None);

    /* "pysam/libcalignmentfile.pyx":791
 *               mode=None,
 *               AlignmentFile template=None,
 *               reference_names=None,             # <<<<<<<<<<<<<<
 *               reference_lengths=None,
 *               reference_filename=None,
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":792
 *               AlignmentFile template=None,
 *               reference_names=None,
 *               reference_lengths=None,             # <<<<<<<<<<<<<<
 *               reference_filename=None,
 *               text=None,
 */
    values[4] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":793
 *               reference_names=None,
 *               reference_lengths=None,
 *               reference_filename=None,             # <<<<<<<<<<<<<<
 *               text=None,
 *               header=None,
 */
    values[5] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":794
 *               reference_lengths=None,
 *               reference_filename=None,
 *               text=None,             # <<<<<<<<<<<<<<
 *               header=None,
 *               port=None,
 */
    values[6] = ((PyObject *)Py_None);

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

    /* "pysam/libcalignmentfile.pyx":796
 *               text=None,
 *               header=None,
 *               port=None,             # <<<<<<<<<<<<<<
 *               add_sq_text=True,
 *               add_sam_header=True,
 */
    values[8] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":797
 *               header=None,
 *               port=None,
 *               add_sq_text=True,             # <<<<<<<<<<<<<<
 *               add_sam_header=True,
 *               check_header=True,
 */
    values[9] = ((PyObject *)Py_True);

    /* "pysam/libcalignmentfile.pyx":798
 *               port=None,
 *               add_sq_text=True,
 *               add_sam_header=True,             # <<<<<<<<<<<<<<
 *               check_header=True,
 *               check_sq=True,
 */
    values[10] = ((PyObject *)Py_True);

    /* "pysam/libcalignmentfile.pyx":799
 *               add_sq_text=True,
 *               add_sam_header=True,
 *               check_header=True,             # <<<<<<<<<<<<<<
 *               check_sq=True,
 *               index_filename=None,
 */
    values[11] = ((PyObject *)Py_True);

    /* "pysam/libcalignmentfile.pyx":800
 *               add_sam_header=True,
 *               check_header=True,
 *               check_sq=True,             # <<<<<<<<<<<<<<
 *               index_filename=None,
 *               filepath_index=None,
 */
    values[12] = ((PyObject *)Py_True);

    /* "pysam/libcalignmentfile.pyx":801
 *               check_header=True,
 *               check_sq=True,
 *               index_filename=None,             # <<<<<<<<<<<<<<
 *               filepath_index=None,
 *               require_index=False,
 */
    values[13] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":802
 *               check_sq=True,
 *               index_filename=None,
 *               filepath_index=None,             # <<<<<<<<<<<<<<
 *               require_index=False,
 *               referencenames=None,
 */
    values[14] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":803
 *               index_filename=None,
 *               filepath_index=None,
 *               require_index=False,             # <<<<<<<<<<<<<<
 *               referencenames=None,
 *               referencelengths=None,
 */
    values[15] = ((PyObject *)Py_False);

    /* "pysam/libcalignmentfile.pyx":804
 *               filepath_index=None,
 *               require_index=False,
 *               referencenames=None,             # <<<<<<<<<<<<<<
 *               referencelengths=None,
 *               duplicate_filehandle=True,
 */
    values[16] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":805
 *               require_index=False,
 *               referencenames=None,
 *               referencelengths=None,             # <<<<<<<<<<<<<<
 *               duplicate_filehandle=True,
 *               ignore_truncation=False,
 */
    values[17] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":806
 *               referencenames=None,
 *               referencelengths=None,
 *               duplicate_filehandle=True,             # <<<<<<<<<<<<<<
 *               ignore_truncation=False,
 *               format_options=None,
 */
    values[18] = ((PyObject *)Py_True);

    /* "pysam/libcalignmentfile.pyx":807
 *               referencelengths=None,
 *               duplicate_filehandle=True,
 *               ignore_truncation=False,             # <<<<<<<<<<<<<<
 *               format_options=None,
 *               threads=1):
 */
    values[19] = ((PyObject *)Py_False);

    /* "pysam/libcalignmentfile.pyx":808
 *               duplicate_filehandle=True,
 *               ignore_truncation=False,
 *               format_options=None,             # <<<<<<<<<<<<<<
 *               threads=1):
 *         '''open a sam, bam or cram formatted file.
 */
    values[20] = ((PyObject *)Py_None);
    values[21] = ((PyObject *)__pyx_int_1);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 22: values[21] = PyTuple_GET_ITEM(__pyx_args, 21);
        CYTHON_FALLTHROUGH;
        case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20);
        CYTHON_FALLTHROUGH;
        case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19);
        CYTHON_FALLTHROUGH;
        case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18);
        CYTHON_FALLTHROUGH;
        case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17);
        CYTHON_FALLTHROUGH;
        case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16);
        CYTHON_FALLTHROUGH;
        case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15);
        CYTHON_FALLTHROUGH;
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        CYTHON_FALLTHROUGH;
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        CYTHON_FALLTHROUGH;
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        CYTHON_FALLTHROUGH;
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        CYTHON_FALLTHROUGH;
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_or_object)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_template);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_filename);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text);
          if (value) { values[6] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_header);
          if (value) { values[7] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port);
          if (value) { values[8] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  9:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sq_text);
          if (value) { values[9] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 10:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sam_header);
          if (value) { values[10] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 11:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_check_header);
          if (value) { values[11] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 12:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_check_sq);
          if (value) { values[12] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 13:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_index_filename);
          if (value) { values[13] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 14:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_index);
          if (value) { values[14] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 15:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_require_index);
          if (value) { values[15] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 16:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_referencenames);
          if (value) { values[16] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 17:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_referencelengths);
          if (value) { values[17] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 18:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_duplicate_filehandle);
          if (value) { values[18] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 19:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ignore_truncation);
          if (value) { values[19] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 20:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format_options);
          if (value) { values[20] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case 21:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_threads);
          if (value) { values[21] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 787, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 22: values[21] = PyTuple_GET_ITEM(__pyx_args, 21);
        CYTHON_FALLTHROUGH;
        case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20);
        CYTHON_FALLTHROUGH;
        case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19);
        CYTHON_FALLTHROUGH;
        case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18);
        CYTHON_FALLTHROUGH;
        case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17);
        CYTHON_FALLTHROUGH;
        case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16);
        CYTHON_FALLTHROUGH;
        case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15);
        CYTHON_FALLTHROUGH;
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        CYTHON_FALLTHROUGH;
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        CYTHON_FALLTHROUGH;
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        CYTHON_FALLTHROUGH;
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        CYTHON_FALLTHROUGH;
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filepath_or_object = values[0];
    __pyx_v_mode = values[1];
    __pyx_v_template = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[2]);
    __pyx_v_reference_names = values[3];
    __pyx_v_reference_lengths = values[4];
    __pyx_v_reference_filename = values[5];
    __pyx_v_text = values[6];
    __pyx_v_header = values[7];
    __pyx_v_port = values[8];
    __pyx_v_add_sq_text = values[9];
    __pyx_v_add_sam_header = values[10];
    __pyx_v_check_header = values[11];
    __pyx_v_check_sq = values[12];
    __pyx_v_index_filename = values[13];
    __pyx_v_filepath_index = values[14];
    __pyx_v_require_index = values[15];
    __pyx_v_referencenames = values[16];
    __pyx_v_referencelengths = values[17];
    __pyx_v_duplicate_filehandle = values[18];
    __pyx_v_ignore_truncation = values[19];
    __pyx_v_format_options = values[20];
    __pyx_v_threads = values[21];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 22, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 787, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._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_17libcalignmentfile_AlignmentFile, 1, "template", 0))) __PYX_ERR(0, 790, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_filepath_or_object, __pyx_v_mode, __pyx_v_template, __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_reference_filename, __pyx_v_text, __pyx_v_header, __pyx_v_port, __pyx_v_add_sq_text, __pyx_v_add_sam_header, __pyx_v_check_header, __pyx_v_check_sq, __pyx_v_index_filename, __pyx_v_filepath_index, __pyx_v_require_index, __pyx_v_referencenames, __pyx_v_referencelengths, __pyx_v_duplicate_filehandle, __pyx_v_ignore_truncation, __pyx_v_format_options, __pyx_v_threads);

  /* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               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_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_add_sam_header, CYTHON_UNUSED PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_index_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_require_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_format_options, PyObject *__pyx_v_threads) {
  char *__pyx_v_cfilename;
  char *__pyx_v_creference_filename;
  char *__pyx_v_cindexname;
  CYTHON_UNUSED char *__pyx_v_cmode;
  bam_hdr_t *__pyx_v_hdr;
  PyObject *__pyx_v_filename = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_bfile_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  char *__pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  htsFile *__pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  char const *__pyx_t_18;
  bam_hdr_t *__pyx_t_19;
  int64_t __pyx_t_20;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_open", 0);
  __Pyx_TraceCall("_open", __pyx_f[0], 787, 0, __PYX_ERR(0, 787, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_mode);
  __Pyx_INCREF(__pyx_v_reference_names);
  __Pyx_INCREF(__pyx_v_reference_lengths);
  __Pyx_INCREF(__pyx_v_reference_filename);

  /* "pysam/libcalignmentfile.pyx":816
 * 
 *         '''
 *         cdef char *cfilename = NULL             # <<<<<<<<<<<<<<
 *         cdef char *creference_filename = NULL
 *         cdef char *cindexname = NULL
 */
  __pyx_v_cfilename = NULL;

  /* "pysam/libcalignmentfile.pyx":817
 *         '''
 *         cdef char *cfilename = NULL
 *         cdef char *creference_filename = NULL             # <<<<<<<<<<<<<<
 *         cdef char *cindexname = NULL
 *         cdef char *cmode = NULL
 */
  __pyx_v_creference_filename = NULL;

  /* "pysam/libcalignmentfile.pyx":818
 *         cdef char *cfilename = NULL
 *         cdef char *creference_filename = NULL
 *         cdef char *cindexname = NULL             # <<<<<<<<<<<<<<
 *         cdef char *cmode = NULL
 *         cdef bam_hdr_t * hdr = NULL
 */
  __pyx_v_cindexname = NULL;

  /* "pysam/libcalignmentfile.pyx":819
 *         cdef char *creference_filename = NULL
 *         cdef char *cindexname = NULL
 *         cdef char *cmode = NULL             # <<<<<<<<<<<<<<
 *         cdef bam_hdr_t * hdr = NULL
 * 
 */
  __pyx_v_cmode = NULL;

  /* "pysam/libcalignmentfile.pyx":820
 *         cdef char *cindexname = NULL
 *         cdef char *cmode = NULL
 *         cdef bam_hdr_t * hdr = NULL             # <<<<<<<<<<<<<<
 * 
 *         if threads > 1 and ignore_truncation:
 */
  __pyx_v_hdr = NULL;

  /* "pysam/libcalignmentfile.pyx":822
 *         cdef bam_hdr_t * hdr = NULL
 * 
 *         if threads > 1 and ignore_truncation:             # <<<<<<<<<<<<<<
 *            # This won't raise errors if reaching a truncated alignment,
 *            # because bgzf_mt_reader in htslib does not deal with
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_threads, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 822, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 822, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_ignore_truncation); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 822, __pyx_L1_error)
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":828
 *            # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888)
 *            # Better to avoid this (for now) than to produce seemingly correct results.
 *            raise ValueError('Cannot add extra threads when "ignore_truncation" is True')             # <<<<<<<<<<<<<<
 *         self.threads = threads
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 828, __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_ERR(0, 828, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":822
 *         cdef bam_hdr_t * hdr = NULL
 * 
 *         if threads > 1 and ignore_truncation:             # <<<<<<<<<<<<<<
 *            # This won't raise errors if reaching a truncated alignment,
 *            # because bgzf_mt_reader in htslib does not deal with
 */
  }

  /* "pysam/libcalignmentfile.pyx":829
 *            # Better to avoid this (for now) than to produce seemingly correct results.
 *            raise ValueError('Cannot add extra threads when "ignore_truncation" is True')
 *         self.threads = threads             # <<<<<<<<<<<<<<
 * 
 *         # for backwards compatibility:
 */
  __Pyx_INCREF(__pyx_v_threads);
  __Pyx_GIVEREF(__pyx_v_threads);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.threads);
  __pyx_v_self->__pyx_base.threads = __pyx_v_threads;

  /* "pysam/libcalignmentfile.pyx":832
 * 
 *         # for backwards compatibility:
 *         if referencenames is not None:             # <<<<<<<<<<<<<<
 *             reference_names = referencenames
 *         if referencelengths is not None:
 */
  __pyx_t_1 = (__pyx_v_referencenames != Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":833
 *         # for backwards compatibility:
 *         if referencenames is not None:
 *             reference_names = referencenames             # <<<<<<<<<<<<<<
 *         if referencelengths is not None:
 *             reference_lengths = referencelengths
 */
    __Pyx_INCREF(__pyx_v_referencenames);
    __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_v_referencenames);

    /* "pysam/libcalignmentfile.pyx":832
 * 
 *         # for backwards compatibility:
 *         if referencenames is not None:             # <<<<<<<<<<<<<<
 *             reference_names = referencenames
 *         if referencelengths is not None:
 */
  }

  /* "pysam/libcalignmentfile.pyx":834
 *         if referencenames is not None:
 *             reference_names = referencenames
 *         if referencelengths is not None:             # <<<<<<<<<<<<<<
 *             reference_lengths = referencelengths
 * 
 */
  __pyx_t_3 = (__pyx_v_referencelengths != Py_None);
  __pyx_t_1 = (__pyx_t_3 != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":835
 *             reference_names = referencenames
 *         if referencelengths is not None:
 *             reference_lengths = referencelengths             # <<<<<<<<<<<<<<
 * 
 *         # close a previously opened file
 */
    __Pyx_INCREF(__pyx_v_referencelengths);
    __Pyx_DECREF_SET(__pyx_v_reference_lengths, __pyx_v_referencelengths);

    /* "pysam/libcalignmentfile.pyx":834
 *         if referencenames is not None:
 *             reference_names = referencenames
 *         if referencelengths is not None:             # <<<<<<<<<<<<<<
 *             reference_lengths = referencelengths
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":838
 * 
 *         # close a previously opened file
 *         if self.is_open:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 838, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 838, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":839
 *         # close a previously opened file
 *         if self.is_open:
 *             self.close()             # <<<<<<<<<<<<<<
 * 
 *         # autodetection for read
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 839, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 839, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":838
 * 
 *         # close a previously opened file
 *         if self.is_open:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":842
 * 
 *         # autodetection for read
 *         if mode is None:             # <<<<<<<<<<<<<<
 *             mode = "r"
 * 
 */
  __pyx_t_1 = (__pyx_v_mode == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":843
 *         # autodetection for read
 *         if mode is None:
 *             mode = "r"             # <<<<<<<<<<<<<<
 * 
 *         if add_sam_header and mode == "w":
 */
    __Pyx_INCREF(__pyx_n_s_r);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_r);

    /* "pysam/libcalignmentfile.pyx":842
 * 
 *         # autodetection for read
 *         if mode is None:             # <<<<<<<<<<<<<<
 *             mode = "r"
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":845
 *             mode = "r"
 * 
 *         if add_sam_header and mode == "w":             # <<<<<<<<<<<<<<
 *             mode = "wh"
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_add_sam_header); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 845, __pyx_L1_error)
  if (__pyx_t_1) {
  } else {
    __pyx_t_3 = __pyx_t_1;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 845, __pyx_L1_error)
  __pyx_t_3 = __pyx_t_1;
  __pyx_L11_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":846
 * 
 *         if add_sam_header and mode == "w":
 *             mode = "wh"             # <<<<<<<<<<<<<<
 * 
 *         assert mode in ("r", "w", "rb", "wb", "wh",
 */
    __Pyx_INCREF(__pyx_n_s_wh);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wh);

    /* "pysam/libcalignmentfile.pyx":845
 *             mode = "r"
 * 
 *         if add_sam_header and mode == "w":             # <<<<<<<<<<<<<<
 *             mode = "wh"
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":848
 *             mode = "wh"
 * 
 *         assert mode in ("r", "w", "rb", "wb", "wh",             # <<<<<<<<<<<<<<
 *                         "wbu", "rU", "wb0",
 *                         "rc", "wc"), \
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __Pyx_INCREF(__pyx_v_mode);
    __pyx_t_2 = __pyx_v_mode;
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_rb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wh, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_rU, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wb0, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_rc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_1;
    __pyx_L13_bool_binop_done:;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!(__pyx_t_3 != 0))) {

      /* "pysam/libcalignmentfile.pyx":851
 *                         "wbu", "rU", "wb0",
 *                         "rc", "wc"), \
 *             "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
 * 
 *         self.duplicate_filehandle = duplicate_filehandle
 */
      __pyx_t_2 = __Pyx_PyString_FormatSafe(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      PyErr_SetObject(PyExc_AssertionError, __pyx_t_2);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_ERR(0, 848, __pyx_L1_error)
    }
  }
  #endif

  /* "pysam/libcalignmentfile.pyx":853
 *             "invalid file opening mode `%s`" % mode
 * 
 *         self.duplicate_filehandle = duplicate_filehandle             # <<<<<<<<<<<<<<
 * 
 *         # StringIO not supported
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_duplicate_filehandle); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 853, __pyx_L1_error)
  __pyx_v_self->__pyx_base.duplicate_filehandle = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":856
 * 
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "access from StringIO objects not supported")
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_IsInstance(__pyx_v_filepath_or_object, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = (__pyx_t_3 != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":857
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 857, __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_ERR(0, 857, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":856
 * 
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "access from StringIO objects not supported")
 */
  }

  /* "pysam/libcalignmentfile.pyx":860
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 *         elif isinstance(filepath_or_object, int):             # <<<<<<<<<<<<<<
 *             self.filename = filepath_or_object
 *             filename = None
 */
  __pyx_t_1 = PyInt_Check(__pyx_v_filepath_or_object); 
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":861
 *         # reading from a file descriptor
 *         elif isinstance(filepath_or_object, int):
 *             self.filename = filepath_or_object             # <<<<<<<<<<<<<<
 *             filename = None
 *             self.is_remote = False
 */
    __Pyx_INCREF(__pyx_v_filepath_or_object);
    __Pyx_GIVEREF(__pyx_v_filepath_or_object);
    __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
    __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
    __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object;

    /* "pysam/libcalignmentfile.pyx":862
 *         elif isinstance(filepath_or_object, int):
 *             self.filename = filepath_or_object
 *             filename = None             # <<<<<<<<<<<<<<
 *             self.is_remote = False
 *             self.is_stream = True
 */
    __Pyx_INCREF(Py_None);
    __pyx_v_filename = ((PyObject*)Py_None);

    /* "pysam/libcalignmentfile.pyx":863
 *             self.filename = filepath_or_object
 *             filename = None
 *             self.is_remote = False             # <<<<<<<<<<<<<<
 *             self.is_stream = True
 *         # reading from a File object or other object with fileno
 */
    __pyx_v_self->__pyx_base.is_remote = 0;

    /* "pysam/libcalignmentfile.pyx":864
 *             filename = None
 *             self.is_remote = False
 *             self.is_stream = True             # <<<<<<<<<<<<<<
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):
 */
    __pyx_v_self->__pyx_base.is_stream = 1;

    /* "pysam/libcalignmentfile.pyx":860
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 *         elif isinstance(filepath_or_object, int):             # <<<<<<<<<<<<<<
 *             self.filename = filepath_or_object
 *             filename = None
 */
    goto __pyx_L23;
  }

  /* "pysam/libcalignmentfile.pyx":866
 *             self.is_stream = True
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):             # <<<<<<<<<<<<<<
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')
 */
  __pyx_t_3 = __Pyx_HasAttr(__pyx_v_filepath_or_object, __pyx_n_s_fileno); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 866, __pyx_L1_error)
  __pyx_t_1 = (__pyx_t_3 != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":867
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):
 *             if filepath_or_object.closed:             # <<<<<<<<<<<<<<
 *                 raise ValueError('I/O operation on closed file')
 *             self.filename = filepath_or_object
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_closed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 867, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":868
 *         elif hasattr(filepath_or_object, "fileno"):
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')             # <<<<<<<<<<<<<<
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 868, __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_ERR(0, 868, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":867
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):
 *             if filepath_or_object.closed:             # <<<<<<<<<<<<<<
 *                 raise ValueError('I/O operation on closed file')
 *             self.filename = filepath_or_object
 */
    }

    /* "pysam/libcalignmentfile.pyx":869
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')
 *             self.filename = filepath_or_object             # <<<<<<<<<<<<<<
 *             # .name can be TextIOWrapper
 *             try:
 */
    __Pyx_INCREF(__pyx_v_filepath_or_object);
    __Pyx_GIVEREF(__pyx_v_filepath_or_object);
    __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
    __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
    __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object;

    /* "pysam/libcalignmentfile.pyx":871
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 *             try:             # <<<<<<<<<<<<<<
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":872
 *             # .name can be TextIOWrapper
 *             try:
 *                 filename = encode_filename(str(filepath_or_object.name))             # <<<<<<<<<<<<<<
 *                 cfilename = filename
 *             except AttributeError:
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 872, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 872, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 872, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_filename = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":873
 *             try:
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename             # <<<<<<<<<<<<<<
 *             except AttributeError:
 *                 filename = None
 */
        if (unlikely(__pyx_v_filename == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
          __PYX_ERR(0, 873, __pyx_L25_error)
        }
        __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 873, __pyx_L25_error)
        __pyx_v_cfilename = __pyx_t_9;

        /* "pysam/libcalignmentfile.pyx":871
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 *             try:             # <<<<<<<<<<<<<<
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 */
      }
      __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;
      goto __pyx_L30_try_end;
      __pyx_L25_error:;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":874
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 *             except AttributeError:             # <<<<<<<<<<<<<<
 *                 filename = None
 *             self.is_remote = False
 */
      __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 874, __pyx_L27_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_t_5);

        /* "pysam/libcalignmentfile.pyx":875
 *                 cfilename = filename
 *             except AttributeError:
 *                 filename = None             # <<<<<<<<<<<<<<
 *             self.is_remote = False
 *             self.is_stream = True
 */
        __Pyx_INCREF(Py_None);
        __Pyx_XDECREF_SET(__pyx_v_filename, ((PyObject*)Py_None));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        goto __pyx_L26_exception_handled;
      }
      goto __pyx_L27_except_error;
      __pyx_L27_except_error:;

      /* "pysam/libcalignmentfile.pyx":871
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 *             try:             # <<<<<<<<<<<<<<
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 */
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
      goto __pyx_L1_error;
      __pyx_L26_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
      __pyx_L30_try_end:;
    }

    /* "pysam/libcalignmentfile.pyx":876
 *             except AttributeError:
 *                 filename = None
 *             self.is_remote = False             # <<<<<<<<<<<<<<
 *             self.is_stream = True
 *         # what remains is a filename
 */
    __pyx_v_self->__pyx_base.is_remote = 0;

    /* "pysam/libcalignmentfile.pyx":877
 *                 filename = None
 *             self.is_remote = False
 *             self.is_stream = True             # <<<<<<<<<<<<<<
 *         # what remains is a filename
 *         else:
 */
    __pyx_v_self->__pyx_base.is_stream = 1;

    /* "pysam/libcalignmentfile.pyx":866
 *             self.is_stream = True
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):             # <<<<<<<<<<<<<<
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')
 */
    goto __pyx_L23;
  }

  /* "pysam/libcalignmentfile.pyx":880
 *         # what remains is a filename
 *         else:
 *             self.filename = filename = encode_filename(filepath_or_object)             # <<<<<<<<<<<<<<
 *             cfilename = filename
 *             self.is_remote = hisremote(cfilename)
 */
  /*else*/ {
    __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_or_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
    __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
    __pyx_v_self->__pyx_base.filename = __pyx_t_5;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_v_filename = ((PyObject*)__pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":881
 *         else:
 *             self.filename = filename = encode_filename(filepath_or_object)
 *             cfilename = filename             # <<<<<<<<<<<<<<
 *             self.is_remote = hisremote(cfilename)
 *             self.is_stream = self.filename == b'-'
 */
    if (unlikely(__pyx_v_filename == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
      __PYX_ERR(0, 881, __pyx_L1_error)
    }
    __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 881, __pyx_L1_error)
    __pyx_v_cfilename = __pyx_t_9;

    /* "pysam/libcalignmentfile.pyx":882
 *             self.filename = filename = encode_filename(filepath_or_object)
 *             cfilename = filename
 *             self.is_remote = hisremote(cfilename)             # <<<<<<<<<<<<<<
 *             self.is_stream = self.filename == b'-'
 * 
 */
    __pyx_v_self->__pyx_base.is_remote = hisremote(__pyx_v_cfilename);

    /* "pysam/libcalignmentfile.pyx":883
 *             cfilename = filename
 *             self.is_remote = hisremote(cfilename)
 *             self.is_stream = self.filename == b'-'             # <<<<<<<<<<<<<<
 * 
 *         # for htslib, wbu seems to not work
 */
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_self->__pyx_base.filename, __pyx_kp_b__24, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 883, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 883, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_self->__pyx_base.is_stream = __pyx_t_1;
  }
  __pyx_L23:;

  /* "pysam/libcalignmentfile.pyx":886
 * 
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":             # <<<<<<<<<<<<<<
 *             mode = "wb0"
 * 
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 886, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":887
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":
 *             mode = "wb0"             # <<<<<<<<<<<<<<
 * 
 *         self.mode = force_bytes(mode)
 */
    __Pyx_INCREF(__pyx_n_s_wb0);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wb0);

    /* "pysam/libcalignmentfile.pyx":886
 * 
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":             # <<<<<<<<<<<<<<
 *             mode = "wb0"
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":889
 *             mode = "wb0"
 * 
 *         self.mode = force_bytes(mode)             # <<<<<<<<<<<<<<
 *         self.reference_filename = reference_filename = encode_filename(
 *             reference_filename)
 */
  __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 889, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.mode);
  __pyx_v_self->__pyx_base.mode = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":890
 * 
 *         self.mode = force_bytes(mode)
 *         self.reference_filename = reference_filename = encode_filename(             # <<<<<<<<<<<<<<
 *             reference_filename)
 * 
 */
  __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_reference_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->reference_filename);
  __Pyx_DECREF(__pyx_v_self->reference_filename);
  __pyx_v_self->reference_filename = __pyx_t_5;
  __Pyx_INCREF(__pyx_t_5);
  __Pyx_DECREF_SET(__pyx_v_reference_filename, __pyx_t_5);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":893
 *             reference_filename)
 * 
 *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
 *             # open file for writing
 * 
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 893, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 893, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":896
 *             # open file for writing
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 896, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 896, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_text); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 896, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 896, __pyx_L1_error)
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 896, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_3;
    __pyx_L36_bool_binop_done:;
    __pyx_t_3 = ((!__pyx_t_1) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":897
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 *                     "and `reference_lengths` for writing")
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 897, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 897, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":896
 *             # open file for writing
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 */
    }

    /* "pysam/libcalignmentfile.pyx":901
 *                     "and `reference_lengths` for writing")
 * 
 *             if template:             # <<<<<<<<<<<<<<
 *                 # header is copied, though at the moment not strictly
 *                 # necessary as AlignmentHeader is immutable.
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 901, __pyx_L1_error)
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":904
 *                 # header is copied, though at the moment not strictly
 *                 # necessary as AlignmentHeader is immutable.
 *                 self.header = template.header.copy()             # <<<<<<<<<<<<<<
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_template->header), __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_v_self->header);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":901
 *                     "and `reference_lengths` for writing")
 * 
 *             if template:             # <<<<<<<<<<<<<<
 *                 # header is copied, though at the moment not strictly
 *                 # necessary as AlignmentHeader is immutable.
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":905
 *                 # necessary as AlignmentHeader is immutable.
 *                 self.header = template.header.copy()
 *             elif isinstance(header, AlignmentHeader):             # <<<<<<<<<<<<<<
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):
 */
    __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_header, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); 
    __pyx_t_1 = (__pyx_t_3 != 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":906
 *                 self.header = template.header.copy()
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()             # <<<<<<<<<<<<<<
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_header, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_v_self->header);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":905
 *                 # necessary as AlignmentHeader is immutable.
 *                 self.header = template.header.copy()
 *             elif isinstance(header, AlignmentHeader):             # <<<<<<<<<<<<<<
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":907
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 907, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyObject_IsInstance(__pyx_v_header, __pyx_t_5); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 907, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_3 = (__pyx_t_1 != 0);
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":908
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)             # <<<<<<<<<<<<<<
 *             elif reference_names and reference_lengths:
 *                 self.header = AlignmentHeader.from_references(
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 908, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_header) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_header);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 908, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 908, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_v_self->header);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":907
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":909
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_references(
 *                     reference_names,
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 909, __pyx_L1_error)
    if (__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L42_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 909, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_1;
    __pyx_L42_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":910
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 *                 self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                     reference_names,
 *                     reference_lengths,
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_references); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);

      /* "pysam/libcalignmentfile.pyx":912
 *                 self.header = AlignmentHeader.from_references(
 *                     reference_names,
 *                     reference_lengths,             # <<<<<<<<<<<<<<
 *                     add_sq_text=add_sq_text,
 *                     text=text)
 */
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_v_reference_names);
      __Pyx_GIVEREF(__pyx_v_reference_names);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_reference_names);
      __Pyx_INCREF(__pyx_v_reference_lengths);
      __Pyx_GIVEREF(__pyx_v_reference_lengths);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_reference_lengths);

      /* "pysam/libcalignmentfile.pyx":913
 *                     reference_names,
 *                     reference_lengths,
 *                     add_sq_text=add_sq_text,             # <<<<<<<<<<<<<<
 *                     text=text)
 *             elif text:
 */
      __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_add_sq_text, __pyx_v_add_sq_text) < 0) __PYX_ERR(0, 913, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":914
 *                     reference_lengths,
 *                     add_sq_text=add_sq_text,
 *                     text=text)             # <<<<<<<<<<<<<<
 *             elif text:
 *                 self.header = AlignmentHeader.from_text(text)
 */
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_text, __pyx_v_text) < 0) __PYX_ERR(0, 913, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":910
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 *                 self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                     reference_names,
 *                     reference_lengths,
 */
      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_11);
      __Pyx_GOTREF(__pyx_v_self->header);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_11);
      __pyx_t_11 = 0;

      /* "pysam/libcalignmentfile.pyx":909
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_references(
 *                     reference_names,
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":915
 *                     add_sq_text=add_sq_text,
 *                     text=text)
 *             elif text:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_text); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 915, __pyx_L1_error)
    if (likely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":916
 *                     text=text)
 *             elif text:
 *                 self.header = AlignmentHeader.from_text(text)             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("not enough information to construct header. Please provide template, "
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_text); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 916, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_11 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v_text) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_text);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 916, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 916, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_11);
      __Pyx_GOTREF(__pyx_v_self->header);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_11);
      __pyx_t_11 = 0;

      /* "pysam/libcalignmentfile.pyx":915
 *                     add_sq_text=add_sq_text,
 *                     text=text)
 *             elif text:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":918
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 *                 raise ValueError("not enough information to construct header. Please provide template, "             # <<<<<<<<<<<<<<
 *                                  "header, text or reference_names/reference_lengths")
 *             self.htsfile = self._open_htsfile()
 */
    /*else*/ {
      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 918, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_Raise(__pyx_t_11, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __PYX_ERR(0, 918, __pyx_L1_error)
    }
    __pyx_L41:;

    /* "pysam/libcalignmentfile.pyx":920
 *                 raise ValueError("not enough information to construct header. Please provide template, "
 *                                  "header, text or reference_names/reference_lengths")
 *             self.htsfile = self._open_htsfile()             # <<<<<<<<<<<<<<
 * 
 *             if self.htsfile == NULL:
 */
    __pyx_t_12 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_12 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 920, __pyx_L1_error)
    __pyx_v_self->__pyx_base.htsfile = __pyx_t_12;

    /* "pysam/libcalignmentfile.pyx":922
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 */
    __pyx_t_3 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0);
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":923
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),
 */
      __pyx_t_3 = (errno != 0);
      if (unlikely(__pyx_t_3)) {

        /* "pysam/libcalignmentfile.pyx":924
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(             # <<<<<<<<<<<<<<
 *                         force_str(filename),
 *                         force_str(strerror(errno))))
 */
        __pyx_t_11 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);

        /* "pysam/libcalignmentfile.pyx":925
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),             # <<<<<<<<<<<<<<
 *                         force_str(strerror(errno))))
 *                 else:
 */
        __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 925, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);

        /* "pysam/libcalignmentfile.pyx":926
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),
 *                         force_str(strerror(errno))))             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 */
        __pyx_t_13 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 926, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_14 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_13, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 926, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_5, __pyx_t_14};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_5, __pyx_t_14};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else
        #endif
        {
          __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 924, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_15);
          if (__pyx_t_13) {
            __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_14);
          PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_14);
          __pyx_t_5 = 0;
          __pyx_t_14 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "pysam/libcalignmentfile.pyx":924
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(             # <<<<<<<<<<<<<<
 *                         force_str(filename),
 *                         force_str(strerror(errno))))
 */
        __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
        __pyx_t_11 = 0;
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 924, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":923
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),
 */
      }

      /* "pysam/libcalignmentfile.pyx":928
 *                         force_str(strerror(errno))))
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))             # <<<<<<<<<<<<<<
 *             if format_options and len(format_options):
 *                 self.add_hts_options(format_options)
 */
      /*else*/ {
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_11 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_15 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_15)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_15);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
          }
        }
        __pyx_t_2 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_15, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_11);
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(0, 928, __pyx_L1_error)
      }

      /* "pysam/libcalignmentfile.pyx":922
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 */
    }

    /* "pysam/libcalignmentfile.pyx":929
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 *             # set filename with reference sequences. If no filename
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 929, __pyx_L1_error)
    if (__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L47_bool_binop_done;
    }
    __pyx_t_16 = PyObject_Length(__pyx_v_format_options); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 929, __pyx_L1_error)
    __pyx_t_1 = (__pyx_t_16 != 0);
    __pyx_t_3 = __pyx_t_1;
    __pyx_L47_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":930
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 *             if format_options and len(format_options):
 *                 self.add_hts_options(format_options)             # <<<<<<<<<<<<<<
 *             # set filename with reference sequences. If no filename
 *             # is given, the CRAM reference arrays will be built from
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_hts_options); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 930, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_11 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_4 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_11, __pyx_v_format_options) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_format_options);
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __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;

      /* "pysam/libcalignmentfile.pyx":929
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 *             # set filename with reference sequences. If no filename
 */
    }

    /* "pysam/libcalignmentfile.pyx":934
 *             # is given, the CRAM reference arrays will be built from
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:             # <<<<<<<<<<<<<<
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")
 */
    __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_c, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 934, __pyx_L1_error)
    __pyx_t_17 = (__pyx_t_1 != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_3 = __pyx_t_17;
      goto __pyx_L50_bool_binop_done;
    }
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 934, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_17;
    __pyx_L50_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":935
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):             # <<<<<<<<<<<<<<
 *                     raise ValueError("failure when setting reference filename")
 * 
 */
      __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 935, __pyx_L1_error)
      __pyx_t_3 = ((hts_set_fai_filename(__pyx_v_self->__pyx_base.htsfile, __pyx_t_18) != 0) != 0);
      if (unlikely(__pyx_t_3)) {

        /* "pysam/libcalignmentfile.pyx":936
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")             # <<<<<<<<<<<<<<
 * 
 *             # write header to htsfile
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __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_ERR(0, 936, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":935
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):             # <<<<<<<<<<<<<<
 *                     raise ValueError("failure when setting reference filename")
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":934
 *             # is given, the CRAM reference arrays will be built from
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:             # <<<<<<<<<<<<<<
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")
 */
    }

    /* "pysam/libcalignmentfile.pyx":939
 * 
 *             # write header to htsfile
 *             if "b" in mode or "c" in mode or "h" in mode:             # <<<<<<<<<<<<<<
 *                 hdr = self.header.ptr
 *                 with nogil:
 */
    __pyx_t_17 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_b, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 939, __pyx_L1_error)
    __pyx_t_1 = (__pyx_t_17 != 0);
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_c, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 939, __pyx_L1_error)
    __pyx_t_17 = (__pyx_t_1 != 0);
    if (!__pyx_t_17) {
    } else {
      __pyx_t_3 = __pyx_t_17;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_17 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_h, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 939, __pyx_L1_error)
    __pyx_t_1 = (__pyx_t_17 != 0);
    __pyx_t_3 = __pyx_t_1;
    __pyx_L54_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":940
 *             # write header to htsfile
 *             if "b" in mode or "c" in mode or "h" in mode:
 *                 hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     sam_hdr_write(self.htsfile, hdr)
 */
      __pyx_t_19 = __pyx_v_self->header->ptr;
      __pyx_v_hdr = __pyx_t_19;

      /* "pysam/libcalignmentfile.pyx":941
 *             if "b" in mode or "c" in mode or "h" in mode:
 *                 hdr = self.header.ptr
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":942
 *                 hdr = self.header.ptr
 *                 with nogil:
 *                     sam_hdr_write(self.htsfile, hdr)             # <<<<<<<<<<<<<<
 * 
 *         elif mode[0] == "r":
 */
            (void)(sam_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr));
          }

          /* "pysam/libcalignmentfile.pyx":941
 *             if "b" in mode or "c" in mode or "h" in mode:
 *                 hdr = self.header.ptr
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L59;
            }
            __pyx_L59:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":939
 * 
 *             # write header to htsfile
 *             if "b" in mode or "c" in mode or "h" in mode:             # <<<<<<<<<<<<<<
 *                 hdr = self.header.ptr
 *                 with nogil:
 */
    }

    /* "pysam/libcalignmentfile.pyx":893
 *             reference_filename)
 * 
 *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
 *             # open file for writing
 * 
 */
    goto __pyx_L34;
  }

  /* "pysam/libcalignmentfile.pyx":944
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
 *             # open file for reading
 *             self.htsfile = self._open_htsfile()
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":946
 *         elif mode[0] == "r":
 *             # open file for reading
 *             self.htsfile = self._open_htsfile()             # <<<<<<<<<<<<<<
 * 
 *             if self.htsfile == NULL:
 */
    __pyx_t_12 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_12 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 946, __pyx_L1_error)
    __pyx_v_self->__pyx_base.htsfile = __pyx_t_12;

    /* "pysam/libcalignmentfile.pyx":948
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 */
    __pyx_t_3 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0);
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":949
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 *                                   force_str(strerror(errno))))
 */
      __pyx_t_3 = (errno != 0);
      if (unlikely(__pyx_t_3)) {

        /* "pysam/libcalignmentfile.pyx":950
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),             # <<<<<<<<<<<<<<
 *                                   force_str(strerror(errno))))
 *                 else:
 */
        __pyx_t_4 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_15 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);

        /* "pysam/libcalignmentfile.pyx":951
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 *                                   force_str(strerror(errno))))             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 */
        __pyx_t_14 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_14, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_t_15, __pyx_t_5};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_t_15, __pyx_t_5};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else
        #endif
        {
          __pyx_t_13 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 950, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
          if (__pyx_t_14) {
            __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_14); __pyx_t_14 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_15);
          PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_10, __pyx_t_15);
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_10, __pyx_t_5);
          __pyx_t_15 = 0;
          __pyx_t_5 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "pysam/libcalignmentfile.pyx":950
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),             # <<<<<<<<<<<<<<
 *                                   force_str(strerror(errno))))
 *                 else:
 */
        __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2);
        __pyx_t_4 = 0;
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 950, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":949
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 *                                   force_str(strerror(errno))))
 */
      }

      /* "pysam/libcalignmentfile.pyx":953
 *                                   force_str(strerror(errno))))
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))             # <<<<<<<<<<<<<<
 * 
 *             if self.htsfile.format.category != sequence_data:
 */
      /*else*/ {
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_13 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
          }
        }
        __pyx_t_2 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_4);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_11, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __PYX_ERR(0, 953, __pyx_L1_error)
      }

      /* "pysam/libcalignmentfile.pyx":948
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 */
    }

    /* "pysam/libcalignmentfile.pyx":955
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 * 
 *             if self.htsfile.format.category != sequence_data:             # <<<<<<<<<<<<<<
 *                 raise ValueError("file does not contain alignment data")
 * 
 */
    __pyx_t_3 = ((__pyx_v_self->__pyx_base.htsfile->format.category != sequence_data) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":956
 * 
 *             if self.htsfile.format.category != sequence_data:
 *                 raise ValueError("file does not contain alignment data")             # <<<<<<<<<<<<<<
 * 
 *             if format_options and len(format_options):
 */
      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 956, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_Raise(__pyx_t_11, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __PYX_ERR(0, 956, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":955
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 * 
 *             if self.htsfile.format.category != sequence_data:             # <<<<<<<<<<<<<<
 *                 raise ValueError("file does not contain alignment data")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":958
 *                 raise ValueError("file does not contain alignment data")
 * 
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 958, __pyx_L1_error)
    if (__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L64_bool_binop_done;
    }
    __pyx_t_16 = PyObject_Length(__pyx_v_format_options); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 958, __pyx_L1_error)
    __pyx_t_1 = (__pyx_t_16 != 0);
    __pyx_t_3 = __pyx_t_1;
    __pyx_L64_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":959
 * 
 *             if format_options and len(format_options):
 *                 self.add_hts_options(format_options)             # <<<<<<<<<<<<<<
 * 
 *             self.check_truncation(ignore_truncation)
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_hts_options); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 959, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_11 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v_format_options) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_format_options);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 959, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

      /* "pysam/libcalignmentfile.pyx":958
 *                 raise ValueError("file does not contain alignment data")
 * 
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":961
 *                 self.add_hts_options(format_options)
 * 
 *             self.check_truncation(ignore_truncation)             # <<<<<<<<<<<<<<
 * 
 *             # bam/cram files require a valid header
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_truncation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_11 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v_ignore_truncation) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_ignore_truncation);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

    /* "pysam/libcalignmentfile.pyx":964
 * 
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 */
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L67_bool_binop_done;
    }
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_3 = __pyx_t_1;
    __pyx_L67_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":965
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":966
 *             if self.is_bam or self.is_cram:
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                 if hdr == NULL:
 *                     raise ValueError(
 */
            __pyx_v_hdr = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile);
          }

          /* "pysam/libcalignmentfile.pyx":965
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L71;
            }
            __pyx_L71:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":967
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "file does not have a valid header (mode='%s') "
 */
      __pyx_t_3 = ((__pyx_v_hdr == NULL) != 0);
      if (unlikely(__pyx_t_3)) {

        /* "pysam/libcalignmentfile.pyx":970
 *                     raise ValueError(
 *                         "file does not have a valid header (mode='%s') "
 *                         "- is it BAM/CRAM format?" % mode)             # <<<<<<<<<<<<<<
 *                 self.header = makeAlignmentHeader(hdr)
 *             else:
 */
        __pyx_t_11 = __Pyx_PyString_FormatSafe(__pyx_kp_s_file_does_not_have_a_valid_heade, __pyx_v_mode); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 970, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);

        /* "pysam/libcalignmentfile.pyx":968
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "file does not have a valid header (mode='%s') "
 *                         "- is it BAM/CRAM format?" % mode)
 */
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 968, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 968, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":967
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "file does not have a valid header (mode='%s') "
 */
      }

      /* "pysam/libcalignmentfile.pyx":971
 *                         "file does not have a valid header (mode='%s') "
 *                         "- is it BAM/CRAM format?" % mode)
 *                 self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 *             else:
 *                 # in sam files a header is optional. If not given,
 */
      __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 971, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_v_self->header);
      __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":964
 * 
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 */
      goto __pyx_L66;
    }

    /* "pysam/libcalignmentfile.pyx":976
 *                 # user may provide reference names and lengths to built
 *                 # an on-the-fly header.
 *                 if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(
 */
    /*else*/ {
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 976, __pyx_L1_error)
      if (__pyx_t_1) {
      } else {
        __pyx_t_3 = __pyx_t_1;
        goto __pyx_L74_bool_binop_done;
      }
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 976, __pyx_L1_error)
      __pyx_t_3 = __pyx_t_1;
      __pyx_L74_bool_binop_done:;
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":978
 *                 if reference_names and reference_lengths:
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 978, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);

        /* "pysam/libcalignmentfile.pyx":979
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(
 *                         reference_names=reference_names,             # <<<<<<<<<<<<<<
 *                         reference_lengths=reference_lengths,
 *                         add_sq_text=add_sq_text,
 */
        __pyx_t_11 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 979, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_reference_names, __pyx_v_reference_names) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":980
 *                     self.header = AlignmentHeader.from_references(
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,             # <<<<<<<<<<<<<<
 *                         add_sq_text=add_sq_text,
 *                         text=text)
 */
        if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_reference_lengths, __pyx_v_reference_lengths) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":981
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,
 *                         add_sq_text=add_sq_text,             # <<<<<<<<<<<<<<
 *                         text=text)
 *                 else:
 */
        if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_add_sq_text, __pyx_v_add_sq_text) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":982
 *                         reference_lengths=reference_lengths,
 *                         add_sq_text=add_sq_text,
 *                         text=text)             # <<<<<<<<<<<<<<
 *                 else:
 *                     with nogil:
 */
        if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_text, __pyx_v_text) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":978
 *                 if reference_names and reference_lengths:
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 978, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 978, __pyx_L1_error)
        __Pyx_GIVEREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_v_self->header);
        __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
        __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4);
        __pyx_t_4 = 0;

        /* "pysam/libcalignmentfile.pyx":976
 *                 # user may provide reference names and lengths to built
 *                 # an on-the-fly header.
 *                 if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(
 */
        goto __pyx_L73;
      }

      /* "pysam/libcalignmentfile.pyx":984
 *                         text=text)
 *                 else:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 */
      /*else*/ {
        {
            #ifdef WITH_THREAD
            PyThreadState *_save;
            Py_UNBLOCK_THREADS
            __Pyx_FastGIL_Remember();
            #endif
            /*try:*/ {

              /* "pysam/libcalignmentfile.pyx":985
 *                 else:
 *                     with nogil:
 *                         hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                     if hdr == NULL:
 *                         raise ValueError(
 */
              __pyx_v_hdr = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile);
            }

            /* "pysam/libcalignmentfile.pyx":984
 *                         text=text)
 *                 else:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 */
            /*finally:*/ {
              /*normal exit:*/{
                #ifdef WITH_THREAD
                __Pyx_FastGIL_Forget();
                Py_BLOCK_THREADS
                #endif
                goto __pyx_L78;
              }
              __pyx_L78:;
            }
        }

        /* "pysam/libcalignmentfile.pyx":986
 *                     with nogil:
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:             # <<<<<<<<<<<<<<
 *                         raise ValueError(
 *                             "SAM? file does not have a valid header (mode='%s'), "
 */
        __pyx_t_3 = ((__pyx_v_hdr == NULL) != 0);
        if (unlikely(__pyx_t_3)) {

          /* "pysam/libcalignmentfile.pyx":987
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 *                         raise ValueError(             # <<<<<<<<<<<<<<
 *                             "SAM? file does not have a valid header (mode='%s'), "
 *                             "please provide reference_names and reference_lengths")
 */
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 987, __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_ERR(0, 987, __pyx_L1_error)

          /* "pysam/libcalignmentfile.pyx":986
 *                     with nogil:
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:             # <<<<<<<<<<<<<<
 *                         raise ValueError(
 *                             "SAM? file does not have a valid header (mode='%s'), "
 */
        }

        /* "pysam/libcalignmentfile.pyx":990
 *                             "SAM? file does not have a valid header (mode='%s'), "
 *                             "please provide reference_names and reference_lengths")
 *                     self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 * 
 *             # set filename with reference sequences
 */
        __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 990, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_v_self->header);
        __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
        __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4);
        __pyx_t_4 = 0;
      }
      __pyx_L73:;
    }
    __pyx_L66:;

    /* "pysam/libcalignmentfile.pyx":993
 * 
 *             # set filename with reference sequences
 *             if self.is_cram and reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = self.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 993, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 993, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L81_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 993, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_1;
    __pyx_L81_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":994
 *             # set filename with reference sequences
 *             if self.is_cram and reference_filename:
 *                 creference_filename = self.reference_filename             # <<<<<<<<<<<<<<
 *                 hts_set_opt(self.htsfile,
 *                             CRAM_OPT_REFERENCE,
 */
      __pyx_t_9 = __Pyx_PyObject_AsWritableString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 994, __pyx_L1_error)
      __pyx_v_creference_filename = __pyx_t_9;

      /* "pysam/libcalignmentfile.pyx":995
 *             if self.is_cram and reference_filename:
 *                 creference_filename = self.reference_filename
 *                 hts_set_opt(self.htsfile,             # <<<<<<<<<<<<<<
 *                             CRAM_OPT_REFERENCE,
 *                             creference_filename)
 */
      (void)(hts_set_opt(__pyx_v_self->__pyx_base.htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename));

      /* "pysam/libcalignmentfile.pyx":993
 * 
 *             # set filename with reference sequences
 *             if self.is_cram and reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = self.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    }

    /* "pysam/libcalignmentfile.pyx":999
 *                             creference_filename)
 * 
 *             if check_sq and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     ("file has no sequences defined (mode='%s') - "
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 999, __pyx_L1_error)
    if (__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L84_bool_binop_done;
    }
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_11 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_3 = __pyx_t_1;
    __pyx_L84_bool_binop_done:;
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":1003
 *                     ("file has no sequences defined (mode='%s') - "
 *                      "is it SAM/BAM format? Consider opening with "
 *                      "check_sq=False") % mode)             # <<<<<<<<<<<<<<
 * 
 *             if self.is_bam or self.is_cram:
 */
      __pyx_t_11 = __Pyx_PyString_FormatSafe(__pyx_kp_s_file_has_no_sequences_defined_mo, __pyx_v_mode); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1003, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);

      /* "pysam/libcalignmentfile.pyx":1000
 * 
 *             if check_sq and self.header.nreferences == 0:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     ("file has no sequences defined (mode='%s') - "
 *                      "is it SAM/BAM format? Consider opening with "
 */
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 1000, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":999
 *                             creference_filename)
 * 
 *             if check_sq and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     ("file has no sequences defined (mode='%s') - "
 */
    }

    /* "pysam/libcalignmentfile.pyx":1005
 *                      "check_sq=False") % mode)
 * 
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L87_bool_binop_done;
    }
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __pyx_t_1;
    __pyx_L87_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":1006
 * 
 *             if self.is_bam or self.is_cram:
 *                 self.index_filename = index_filename or filepath_index             # <<<<<<<<<<<<<<
 *                 if self.index_filename:
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 */
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_index_filename); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1006, __pyx_L1_error)
      if (!__pyx_t_3) {
      } else {
        __Pyx_INCREF(__pyx_v_index_filename);
        __pyx_t_4 = __pyx_v_index_filename;
        goto __pyx_L89_bool_binop_done;
      }
      __Pyx_INCREF(__pyx_v_filepath_index);
      __pyx_t_4 = __pyx_v_filepath_index;
      __pyx_L89_bool_binop_done:;
      __Pyx_GIVEREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_v_self->__pyx_base.index_filename);
      __Pyx_DECREF(__pyx_v_self->__pyx_base.index_filename);
      __pyx_v_self->__pyx_base.index_filename = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "pysam/libcalignmentfile.pyx":1007
 *             if self.is_bam or self.is_cram:
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 */
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_self->__pyx_base.index_filename); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1007, __pyx_L1_error)
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":1008
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:
 *                     cindexname = bfile_name = encode_filename(self.index_filename)             # <<<<<<<<<<<<<<
 * 
 *                 if cfilename or cindexname:
 */
        __pyx_t_4 = __pyx_v_self->__pyx_base.index_filename;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_11 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1008, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(__pyx_t_11 == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
          __PYX_ERR(0, 1008, __pyx_L1_error)
        }
        __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_t_11); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 1008, __pyx_L1_error)
        __pyx_v_cindexname = __pyx_t_9;
        __Pyx_INCREF(__pyx_t_11);
        __pyx_v_bfile_name = ((PyObject*)__pyx_t_11);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "pysam/libcalignmentfile.pyx":1007
 *             if self.is_bam or self.is_cram:
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":1010
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 *                 if cfilename or cindexname:             # <<<<<<<<<<<<<<
 *                     with nogil:
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 */
      __pyx_t_1 = (__pyx_v_cfilename != 0);
      if (!__pyx_t_1) {
      } else {
        __pyx_t_3 = __pyx_t_1;
        goto __pyx_L93_bool_binop_done;
      }
      __pyx_t_1 = (__pyx_v_cindexname != 0);
      __pyx_t_3 = __pyx_t_1;
      __pyx_L93_bool_binop_done:;
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":1011
 * 
 *                 if cfilename or cindexname:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 * 
 */
        {
            #ifdef WITH_THREAD
            PyThreadState *_save;
            Py_UNBLOCK_THREADS
            __Pyx_FastGIL_Remember();
            #endif
            /*try:*/ {

              /* "pysam/libcalignmentfile.pyx":1012
 *                 if cfilename or cindexname:
 *                     with nogil:
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)             # <<<<<<<<<<<<<<
 * 
 *                     if not self.index and (cindexname or require_index):
 */
              __pyx_v_self->index = sam_index_load2(__pyx_v_self->__pyx_base.htsfile, __pyx_v_cfilename, __pyx_v_cindexname);
            }

            /* "pysam/libcalignmentfile.pyx":1011
 * 
 *                 if cfilename or cindexname:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 * 
 */
            /*finally:*/ {
              /*normal exit:*/{
                #ifdef WITH_THREAD
                __Pyx_FastGIL_Forget();
                Py_BLOCK_THREADS
                #endif
                goto __pyx_L97;
              }
              __pyx_L97:;
            }
        }

        /* "pysam/libcalignmentfile.pyx":1014
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 * 
 *                     if not self.index and (cindexname or require_index):             # <<<<<<<<<<<<<<
 *                         if errno:
 *                             raise IOError(errno, force_str(strerror(errno)))
 */
        __pyx_t_1 = ((!(__pyx_v_self->index != 0)) != 0);
        if (__pyx_t_1) {
        } else {
          __pyx_t_3 = __pyx_t_1;
          goto __pyx_L99_bool_binop_done;
        }
        __pyx_t_1 = (__pyx_v_cindexname != 0);
        if (!__pyx_t_1) {
        } else {
          __pyx_t_3 = __pyx_t_1;
          goto __pyx_L99_bool_binop_done;
        }
        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_require_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __pyx_t_3 = __pyx_t_1;
        __pyx_L99_bool_binop_done:;
        if (__pyx_t_3) {

          /* "pysam/libcalignmentfile.pyx":1015
 * 
 *                     if not self.index and (cindexname or require_index):
 *                         if errno:             # <<<<<<<<<<<<<<
 *                             raise IOError(errno, force_str(strerror(errno)))
 *                         else:
 */
          __pyx_t_3 = (errno != 0);
          if (unlikely(__pyx_t_3)) {

            /* "pysam/libcalignmentfile.pyx":1016
 *                     if not self.index and (cindexname or require_index):
 *                         if errno:
 *                             raise IOError(errno, force_str(strerror(errno)))             # <<<<<<<<<<<<<<
 *                         else:
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)
 */
            __pyx_t_11 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1016, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_4 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1016, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1016, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_GIVEREF(__pyx_t_11);
            PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_11);
            __Pyx_GIVEREF(__pyx_t_2);
            PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
            __pyx_t_11 = 0;
            __pyx_t_2 = 0;
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 1016, __pyx_L1_error)

            /* "pysam/libcalignmentfile.pyx":1015
 * 
 *                     if not self.index and (cindexname or require_index):
 *                         if errno:             # <<<<<<<<<<<<<<
 *                             raise IOError(errno, force_str(strerror(errno)))
 *                         else:
 */
          }

          /* "pysam/libcalignmentfile.pyx":1018
 *                             raise IOError(errno, force_str(strerror(errno)))
 *                         else:
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)             # <<<<<<<<<<<<<<
 * 
 *                 elif require_index:
 */
          /*else*/ {
            __pyx_t_2 = __Pyx_PyString_FormatSafe(__pyx_kp_s_unable_to_open_index_file_s, __pyx_v_self->__pyx_base.index_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1018, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1018, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_Raise(__pyx_t_4, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __PYX_ERR(0, 1018, __pyx_L1_error)
          }

          /* "pysam/libcalignmentfile.pyx":1014
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 * 
 *                     if not self.index and (cindexname or require_index):             # <<<<<<<<<<<<<<
 *                         if errno:
 *                             raise IOError(errno, force_str(strerror(errno)))
 */
        }

        /* "pysam/libcalignmentfile.pyx":1010
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 *                 if cfilename or cindexname:             # <<<<<<<<<<<<<<
 *                     with nogil:
 *                         self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 */
        goto __pyx_L92;
      }

      /* "pysam/libcalignmentfile.pyx":1020
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)
 * 
 *                 elif require_index:             # <<<<<<<<<<<<<<
 *                     raise IOError('unable to open index file')
 * 
 */
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_require_index); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1020, __pyx_L1_error)
      if (unlikely(__pyx_t_3)) {

        /* "pysam/libcalignmentfile.pyx":1021
 * 
 *                 elif require_index:
 *                     raise IOError('unable to open index file')             # <<<<<<<<<<<<<<
 * 
 *                 # save start of data section
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1021, __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_ERR(0, 1021, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1020
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)
 * 
 *                 elif require_index:             # <<<<<<<<<<<<<<
 *                     raise IOError('unable to open index file')
 * 
 */
      }
      __pyx_L92:;

      /* "pysam/libcalignmentfile.pyx":1024
 * 
 *                 # save start of data section
 *                 if not self.is_stream:             # <<<<<<<<<<<<<<
 *                     self.start_offset = self.tell()
 * 
 */
      __pyx_t_3 = ((!(__pyx_v_self->__pyx_base.is_stream != 0)) != 0);
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":1025
 *                 # save start of data section
 *                 if not self.is_stream:
 *                     self.start_offset = self.tell()             # <<<<<<<<<<<<<<
 * 
 *     def fetch(self,
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1025, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_11 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_11)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_11);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        __pyx_t_4 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1025, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_20 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_20 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1025, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_self->__pyx_base.start_offset = __pyx_t_20;

        /* "pysam/libcalignmentfile.pyx":1024
 * 
 *                 # save start of data section
 *                 if not self.is_stream:             # <<<<<<<<<<<<<<
 *                     self.start_offset = self.tell()
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":1005
 *                      "check_sq=False") % mode)
 * 
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:
 */
    }

    /* "pysam/libcalignmentfile.pyx":944
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
 *             # open file for reading
 *             self.htsfile = self._open_htsfile()
 */
  }
  __pyx_L34:;

  /* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */

  /* 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_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_filename);
  __Pyx_XDECREF(__pyx_v_bfile_name);
  __Pyx_XDECREF(__pyx_v_mode);
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XDECREF(__pyx_v_reference_lengths);
  __Pyx_XDECREF(__pyx_v_reference_filename);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1027
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch[] = "AlignmentFile.fetch(self, contig=None, start=None, stop=None, region=None, tid=None, until_eof=False, multiple_iterators=False, reference=None, end=None)\nfetch reads aligned in a :term:`region`.\n\n        See :meth:`~pysam.HTSFile.parse_region` for more information\n        on how genomic regions can be specified. :term:`reference` and\n        `end` are also accepted for backward compatibility as synonyms\n        for :term:`contig` and `stop`, respectively.\n\n        Without a `contig` or `region` all mapped reads in the file\n        will be fetched. The reads will be returned ordered by reference\n        sequence, which will not necessarily be the order within the\n        file. This mode of iteration still requires an index. If there is\n        no index, use `until_eof=True`.\n\n        If only `contig` is set, all reads aligned to `contig`\n        will be fetched.\n\n        A :term:`SAM` file does not allow random access. If `region`\n        or `contig` are given, an exception is raised.\n\n        Parameters\n        ----------\n\n        until_eof : bool\n\n           If `until_eof` is True, 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        multiple_iterators : bool\n\n           If `multiple_iterators` is True, multiple\n           iterators on the same file can be used at the same time. The\n           iterator returned will receive its own copy of a filehandle to\n           the file effectively re-opening the file. Re-opening a file\n           creates some overhead, so beware.\n\n        Returns\n        -------\n\n\t\tAn iterator over a collection of reads. : IteratorRow\n\n        Raises\n        ------\n\n        ValueError\n            if the genomic coordinates are out of range or invalid or the\n            file does not permit random access to genomic coordinates.\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_tid = 0;
  PyObject *__pyx_v_until_eof = 0;
  PyObject *__pyx_v_multiple_iterators = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 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_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_until_eof,&__pyx_n_s_multiple_iterators,&__pyx_n_s_reference,&__pyx_n_s_end,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};

    /* "pysam/libcalignmentfile.pyx":1028
 * 
 *     def fetch(self,
 *               contig=None,             # <<<<<<<<<<<<<<
 *               start=None,
 *               stop=None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1029
 *     def fetch(self,
 *               contig=None,
 *               start=None,             # <<<<<<<<<<<<<<
 *               stop=None,
 *               region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1030
 *               contig=None,
 *               start=None,
 *               stop=None,             # <<<<<<<<<<<<<<
 *               region=None,
 *               tid=None,
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1031
 *               start=None,
 *               stop=None,
 *               region=None,             # <<<<<<<<<<<<<<
 *               tid=None,
 *               until_eof=False,
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1032
 *               stop=None,
 *               region=None,
 *               tid=None,             # <<<<<<<<<<<<<<
 *               until_eof=False,
 *               multiple_iterators=False,
 */
    values[4] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1033
 *               region=None,
 *               tid=None,
 *               until_eof=False,             # <<<<<<<<<<<<<<
 *               multiple_iterators=False,
 *               reference=None,
 */
    values[5] = ((PyObject *)Py_False);

    /* "pysam/libcalignmentfile.pyx":1034
 *               tid=None,
 *               until_eof=False,
 *               multiple_iterators=False,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               end=None):
 */
    values[6] = ((PyObject *)Py_False);

    /* "pysam/libcalignmentfile.pyx":1035
 *               until_eof=False,
 *               multiple_iterators=False,
 *               reference=None,             # <<<<<<<<<<<<<<
 *               end=None):
 *         """fetch reads aligned in a :term:`region`.
 */
    values[7] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1036
 *               multiple_iterators=False,
 *               reference=None,
 *               end=None):             # <<<<<<<<<<<<<<
 *         """fetch reads aligned in a :term:`region`.
 * 
 */
    values[8] = ((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  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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 = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_until_eof);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          if (value) { values[6] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[7] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[8] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 1027, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_tid = values[4];
    __pyx_v_until_eof = values[5];
    __pyx_v_multiple_iterators = values[6];
    __pyx_v_reference = values[7];
    __pyx_v_end = values[8];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1027, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_tid, __pyx_v_until_eof, __pyx_v_multiple_iterators, __pyx_v_reference, __pyx_v_end);

  /* "pysam/libcalignmentfile.pyx":1027
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) {
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rstop;
  int __pyx_v_has_coord;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  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)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("fetch", 0);
  __Pyx_TraceCall("fetch", __pyx_f[0], 1027, 0, __PYX_ERR(0, 1027, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":1088
 *         cdef int rtid, rstart, rstop, has_coord
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1089
 * 
 *         if not self.is_open:
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1089, __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_ERR(0, 1089, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1088
 *         cdef int rtid, rstart, rstop, has_coord
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1091
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, tid,
 *             end=end, reference=reference)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":1092
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 *             contig, start, stop, region, tid,             # <<<<<<<<<<<<<<
 *             end=end, reference=reference)
 * 
 */
  __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_contig);
  __Pyx_GIVEREF(__pyx_v_contig);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_contig);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_start);
  __Pyx_INCREF(__pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_stop);
  __Pyx_INCREF(__pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_region);
  __Pyx_INCREF(__pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_tid);

  /* "pysam/libcalignmentfile.pyx":1093
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 *             contig, start, stop, region, tid,
 *             end=end, reference=reference)             # <<<<<<<<<<<<<<
 * 
 *        # Turn of re-opening if htsfile is a stream
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1093, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1093, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1093, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1091
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, tid,
 *             end=end, reference=reference)
 */
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
    PyObject* sequence = __pyx_t_6;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1091, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_7);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1091, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
    __pyx_t_8 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1091, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 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_ERR(0, 1091, __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_ERR(0, 1091, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1091, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1091, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1091, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1091, __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_rstop = __pyx_t_13;

  /* "pysam/libcalignmentfile.pyx":1096
 * 
 *        # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
  __pyx_t_3 = (__pyx_v_self->__pyx_base.is_stream != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1097
 *        # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:
 *             multiple_iterators = False             # <<<<<<<<<<<<<<
 * 
 *         if self.is_bam or self.is_cram:
 */
    __Pyx_INCREF(Py_False);
    __Pyx_DECREF_SET(__pyx_v_multiple_iterators, Py_False);

    /* "pysam/libcalignmentfile.pyx":1096
 * 
 *        # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1099
 *             multiple_iterators = False
 * 
 *         if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_3 = __pyx_t_2;
    goto __pyx_L8_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __pyx_t_2;
  __pyx_L8_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1100
 * 
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:             # <<<<<<<<<<<<<<
 *                 if not self.has_index():
 *                     raise ValueError(
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1100, __pyx_L1_error)
    __pyx_t_14 = ((!__pyx_t_2) != 0);
    if (__pyx_t_14) {
    } else {
      __pyx_t_3 = __pyx_t_14;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_14 = ((!(__pyx_v_self->__pyx_base.is_remote != 0)) != 0);
    __pyx_t_3 = __pyx_t_14;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":1101
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "fetch called on bamfile without index")
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1101, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1101, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1101, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_14 = ((!__pyx_t_3) != 0);
      if (unlikely(__pyx_t_14)) {

        /* "pysam/libcalignmentfile.pyx":1102
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "fetch called on bamfile without index")
 * 
 */
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1102, __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_ERR(0, 1102, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1101
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "fetch called on bamfile without index")
 */
      }

      /* "pysam/libcalignmentfile.pyx":1100
 * 
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:             # <<<<<<<<<<<<<<
 *                 if not self.has_index():
 *                     raise ValueError(
 */
    }

    /* "pysam/libcalignmentfile.pyx":1105
 *                         "fetch called on bamfile without index")
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,
 */
    __pyx_t_14 = (__pyx_v_has_coord != 0);
    if (__pyx_t_14) {

      /* "pysam/libcalignmentfile.pyx":1106
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)
 */
      __Pyx_XDECREF(__pyx_r);

      /* "pysam/libcalignmentfile.pyx":1107
 *             if has_coord:
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,             # <<<<<<<<<<<<<<
 *                     multiple_iterators=multiple_iterators)
 *             else:
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rstop); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pysam/libcalignmentfile.pyx":1106
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)
 */
      __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_1);
      __pyx_t_6 = 0;
      __pyx_t_7 = 0;
      __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":1108
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *             else:
 *                 if until_eof:
 */
      __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1108, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1106
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)
 */
      __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;

      /* "pysam/libcalignmentfile.pyx":1105
 *                         "fetch called on bamfile without index")
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,
 */
    }

    /* "pysam/libcalignmentfile.pyx":1110
 *                     multiple_iterators=multiple_iterators)
 *             else:
 *                 if until_eof:             # <<<<<<<<<<<<<<
 *                     return IteratorRowAll(
 *                         self,
 */
    /*else*/ {
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1110, __pyx_L1_error)
      if (__pyx_t_14) {

        /* "pysam/libcalignmentfile.pyx":1111
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __Pyx_XDECREF(__pyx_r);

        /* "pysam/libcalignmentfile.pyx":1112
 *                 if until_eof:
 *                     return IteratorRowAll(
 *                         self,             # <<<<<<<<<<<<<<
 *                         multiple_iterators=multiple_iterators)
 *                 else:
 */
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1111, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(((PyObject *)__pyx_v_self));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));

        /* "pysam/libcalignmentfile.pyx":1113
 *                     return IteratorRowAll(
 *                         self,
 *                         multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # AH: check - reason why no multiple_iterators for
 */
        __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1113, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1113, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1111
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1111, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L0;

        /* "pysam/libcalignmentfile.pyx":1110
 *                     multiple_iterators=multiple_iterators)
 *             else:
 *                 if until_eof:             # <<<<<<<<<<<<<<
 *                     return IteratorRowAll(
 *                         self,
 */
      }

      /* "pysam/libcalignmentfile.pyx":1117
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
      /*else*/ {
        __Pyx_XDECREF(__pyx_r);

        /* "pysam/libcalignmentfile.pyx":1118
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(
 *                         self,             # <<<<<<<<<<<<<<
 *                         multiple_iterators=multiple_iterators)
 *         else:
 */
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1117, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF(((PyObject *)__pyx_v_self));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
        PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self));

        /* "pysam/libcalignmentfile.pyx":1119
 *                     return IteratorRowAllRefs(
 *                         self,
 *                         multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *         else:
 *             if has_coord:
 */
        __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1119, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1119, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1117
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs), __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1117, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_7;
        __pyx_t_7 = 0;
        goto __pyx_L0;
      }
    }

    /* "pysam/libcalignmentfile.pyx":1099
 *             multiple_iterators = False
 * 
 *         if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 */
  }

  /* "pysam/libcalignmentfile.pyx":1121
 *                         multiple_iterators=multiple_iterators)
 *         else:
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "fetching by region is not available for SAM files")
 */
  /*else*/ {
    __pyx_t_14 = (__pyx_v_has_coord != 0);
    if (unlikely(__pyx_t_14)) {

      /* "pysam/libcalignmentfile.pyx":1122
 *         else:
 *             if has_coord:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetching by region is not available for SAM files")
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1122, __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_ERR(0, 1122, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1121
 *                         multiple_iterators=multiple_iterators)
 *         else:
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "fetching by region is not available for SAM files")
 */
    }

    /* "pysam/libcalignmentfile.pyx":1125
 *                     "fetching by region is not available for SAM files")
 * 
 *             if multiple_iterators == True:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "multiple iterators not implemented for SAM files")
 */
    __pyx_t_7 = PyObject_RichCompare(__pyx_v_multiple_iterators, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1125, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1125, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__pyx_t_14)) {

      /* "pysam/libcalignmentfile.pyx":1126
 * 
 *             if multiple_iterators == True:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "multiple iterators not implemented for SAM files")
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1126, __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_ERR(0, 1126, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1125
 *                     "fetching by region is not available for SAM files")
 * 
 *             if multiple_iterators == True:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "multiple iterators not implemented for SAM files")
 */
    }

    /* "pysam/libcalignmentfile.pyx":1129
 *                     "multiple iterators not implemented for SAM files")
 * 
 *             return IteratorRowAll(self,             # <<<<<<<<<<<<<<
 *                                   multiple_iterators=multiple_iterators)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1129, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));

    /* "pysam/libcalignmentfile.pyx":1130
 * 
 *             return IteratorRowAll(self,
 *                                   multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def head(self, n, multiple_iterators=True):
 */
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1130, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1129
 *                     "multiple iterators not implemented for SAM files")
 * 
 *             return IteratorRowAll(self,             # <<<<<<<<<<<<<<
 *                                   multiple_iterators=multiple_iterators)
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1129, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":1027
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_multiple_iterators);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1132
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return an iterator over the first n alignments.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head[] = "AlignmentFile.head(self, n, multiple_iterators=True)\nreturn an iterator over the first n alignments.\n\n        This iterator is is useful for inspecting the bam-file.\n\n        Parameters\n        ----------\n\n        multiple_iterators : bool\n\n            is set to True by default in order to\n            avoid changing the current file position.\n\n        Returns\n        -------\n\n\t\tan iterator over a collection of reads : IteratorRowHead\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_n = 0;
  PyObject *__pyx_v_multiple_iterators = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("head (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "head") < 0)) __PYX_ERR(0, 1132, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_n = values[0];
    __pyx_v_multiple_iterators = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("head", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1132, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_n, __pyx_v_multiple_iterators);

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("head", 0);
  __Pyx_TraceCall("head", __pyx_f[0], 1132, 0, __PYX_ERR(0, 1132, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1151
 * 
 *         '''
 *         return IteratorRowHead(self, n,             # <<<<<<<<<<<<<<
 *                                multiple_iterators=multiple_iterators)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(__pyx_v_n);
  __Pyx_GIVEREF(__pyx_v_n);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_n);

  /* "pysam/libcalignmentfile.pyx":1152
 *         '''
 *         return IteratorRowHead(self, n,
 *                                multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def mate(self, AlignedSegment read):
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1152, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1152, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1151
 * 
 *         '''
 *         return IteratorRowHead(self, n,             # <<<<<<<<<<<<<<
 *                                multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1151, __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_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1132
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return an iterator over the first n alignments.
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":1154
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self, AlignedSegment read):             # <<<<<<<<<<<<<<
 *         '''return the mate of :class:`pysam.AlignedSegment` `read`.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate[] = "AlignmentFile.mate(self, AlignedSegment read)\nreturn the mate of :class:`pysam.AlignedSegment` `read`.\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        Returns\n        -------\n\n        the mate : AlignedSegment\n\n        Raises\n        ------\n\n        ValueError\n            if the read is unpaired or the mate is unmapped\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  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_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1154, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__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_17libcalignmentfile_13AlignmentFile_12mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) {
  uint32_t __pyx_v_flag;
  int __pyx_v_x;
  PyObject *__pyx_v_mate = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("mate", 0);
  __Pyx_TraceCall("mate", __pyx_f[0], 1154, 0, __PYX_ERR(0, 1154, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1181
 * 
 *         '''
 *         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/libcalignmentfile.pyx":1183
 *         cdef uint32_t flag = read._delegate.core.flag
 * 
 *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 */
  __pyx_t_2 = (((__pyx_v_flag & BAM_FPAIRED) == 0) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1185
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))             # <<<<<<<<<<<<<<
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/libcalignmentfile.pyx":1184
 * 
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" %             # <<<<<<<<<<<<<<
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:
 */
    __pyx_t_4 = __Pyx_PyString_FormatSafe(__pyx_kp_s_read_s_is_unpaired, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1184, __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_ERR(0, 1184, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1183
 *         cdef uint32_t flag = read._delegate.core.flag
 * 
 *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 */
  }

  /* "pysam/libcalignmentfile.pyx":1186
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))
 */
  __pyx_t_2 = (((__pyx_v_flag & BAM_FMUNMAP) != 0) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1188
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))             # <<<<<<<<<<<<<<
 * 
 *         # xor flags to get the other mate
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1188, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/libcalignmentfile.pyx":1187
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %             # <<<<<<<<<<<<<<
 *                              (read.query_name))
 * 
 */
    __pyx_t_4 = __Pyx_PyString_FormatSafe(__pyx_kp_s_mate_s_is_unmapped, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1187, __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_ERR(0, 1187, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1186
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))
 */
  }

  /* "pysam/libcalignmentfile.pyx":1191
 * 
 *         # 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/libcalignmentfile.pyx":1192
 *         # xor flags to get the other mate
 *         cdef int x = BAM_FREAD1 + BAM_FREAD2
 *         flag = (flag ^ x) & x             # <<<<<<<<<<<<<<
 * 
 *         # Make sure to use a separate file to jump around
 */
  __pyx_v_flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x);

  /* "pysam/libcalignmentfile.pyx":1200
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         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_ERR(0, 1200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/libcalignmentfile.pyx":1201
 *         # by using tell and seek.
 *         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_ERR(0, 1201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/libcalignmentfile.pyx":1202
 *         for mate in self.fetch(
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,             # <<<<<<<<<<<<<<
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 */
  __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_v_read->_delegate->core.mpos + 1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1202, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/libcalignmentfile.pyx":1200
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         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_ERR(0, 1200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":1203
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid,             # <<<<<<<<<<<<<<
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 1203, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":1204
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):             # <<<<<<<<<<<<<<
 *             if mate.flag & flag != 0 and \
 *                mate.query_name == read.query_name:
 */
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, Py_True) < 0) __PYX_ERR(0, 1203, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1200
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         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_ERR(0, 1200, __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 (likely(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_ERR(0, 1200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1200, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __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_ERR(0, 1200, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1200, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __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_ERR(0, 1200, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1200, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #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(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1200, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_mate, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":1205
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.query_name == read.query_name:
 *                 break
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_flag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1205, __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_ERR(0, 1205, __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_ERR(0, 1205, __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 = __Pyx_PyInt_NeObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1205, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_9) {
    } else {
      __pyx_t_2 = __pyx_t_9;
      goto __pyx_L8_bool_binop_done;
    }

    /* "pysam/libcalignmentfile.pyx":1206
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \
 *                mate.query_name == read.query_name:             # <<<<<<<<<<<<<<
 *                 break
 *         else:
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_query_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1206, __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_ERR(0, 1206, __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_ERR(0, 1206, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __pyx_t_9;
    __pyx_L8_bool_binop_done:;

    /* "pysam/libcalignmentfile.pyx":1205
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.query_name == read.query_name:
 *                 break
 */
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":1207
 *             if mate.flag & flag != 0 and \
 *                mate.query_name == read.query_name:
 *                 break             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("mate not found")
 */
      goto __pyx_L6_break;

      /* "pysam/libcalignmentfile.pyx":1205
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.query_name == read.query_name:
 *                 break
 */
    }

    /* "pysam/libcalignmentfile.pyx":1200
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  }
  /*else*/ {

    /* "pysam/libcalignmentfile.pyx":1209
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1209, __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_ERR(0, 1209, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1200
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_L6_break:;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

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

  /* "pysam/libcalignmentfile.pyx":1154
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self, AlignedSegment read):             # <<<<<<<<<<<<<<
 *         '''return the mate of :class:`pysam.AlignedSegment` `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.libcalignmentfile.AlignmentFile.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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1213
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup[] = "AlignmentFile.pileup(self, contig=None, start=None, stop=None, region=None, reference=None, end=None, **kwargs)\nperform a :term:`pileup` within a :term:`region`. The region is\n        specified by :term:`contig`, `start` and `stop` (using\n        0-based indexing).  :term:`reference` and `end` are also accepted for\n        backward compatibility as synonyms for :term:`contig` and `stop`,\n        respectively.  Alternatively, a samtools 'region' string\n        can be supplied.\n\n        Without 'contig' or 'region' all reads will be used for the\n        pileup. The reads will be returned ordered by\n        :term:`contig` sequence, which will not necessarily be the\n        order within the file.\n\n        Note that :term:`SAM` formatted files do not allow random\n        access.  In these files, if a 'region' or 'contig' are\n        given an exception is raised.\n\n        .. note::\n\n            'all' reads which overlap the region are returned. The\n            first base returned will be the first base of the first\n            read 'not' necessarily the first base of the region used\n            in the query.\n\n        Parameters\n        ----------\n\n        truncate : bool\n\n           By default, the samtools pileup engine outputs all reads\n           overlapping a region. If truncate is True and a region is\n           given, only columns in the exact region specified are\n           returned.\n\n        max_depth : int\n           Maximum read depth permitted. The default limit is '8000'.\n\n        stepper : string\n           The stepper controls how the iterator advances.\n           Possible options for the stepper are\n\n           ``all``\n              skip reads in which any of the following flags are set:\n              BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL, BAM_FDUP\n\n           ``nofilter``\n              uses every single read turning off any filtering.\n\n           ``samtools``\n              same filter and read processing a""s in samtools\n              pileup. For full compatibility, this requires a\n              'fastafile' to be given. The following options all pertain\n              to filtering of the ``samtools`` stepper.\n\n        fastafile : :class:`~pysam.FastaFile` object.\n\n           This is required for some of the steppers.\n\n        ignore_overlaps: bool\n\n           If set to True, detect if read pairs overlap and only take\n           the higher quality base. This is the default.\n\n        flag_filter : int\n\n           ignore reads where any of the bits in the flag are set. The default is\n           BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP.\n\n        flag_require : int\n\n           only use reads where certain flags are set. The default is 0.\n\n        ignore_orphans: bool\n\n            ignore orphans (paired reads that are not in a proper pair).\n            The default is to ignore orphans.\n\n        min_base_quality: int\n\n           Minimum base quality. Bases below the minimum quality will\n           not be output. The default is 13.\n\n        adjust_capq_threshold: int\n\n           adjust mapping quality. The default is 0 for no\n           adjustment. The recommended value for adjustment is 50.\n\n        min_mapping_quality : int\n\n           only use reads above a minimum mapping quality. The default is 0.\n\n        compute_baq: bool\n\n           re-alignment computing per-Base Alignment Qualities (BAQ). The\n           default is to do re-alignment. Realignment requires a reference\n           sequence. If none is present, no realignment will be performed.\n\n        redo_baq: bool\n\n           recompute per-Base Alignment Quality on the fly ignoring\n           existing base qualities. The default is False (use existing\n           base qualities).\n\n        Returns\n        -------\n\n        an iterator over genomic positions. : IteratorColumn\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 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_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reference,&__pyx_n_s_end,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "pysam/libcalignmentfile.pyx":1214
 * 
 *     def pileup(self,
 *                contig=None,             # <<<<<<<<<<<<<<
 *                start=None,
 *                stop=None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1215
 *     def pileup(self,
 *                contig=None,
 *                start=None,             # <<<<<<<<<<<<<<
 *                stop=None,
 *                region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1216
 *                contig=None,
 *                start=None,
 *                stop=None,             # <<<<<<<<<<<<<<
 *                region=None,
 *                reference=None,
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1217
 *                start=None,
 *                stop=None,
 *                region=None,             # <<<<<<<<<<<<<<
 *                reference=None,
 *                end=None,
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1218
 *                stop=None,
 *                region=None,
 *                reference=None,             # <<<<<<<<<<<<<<
 *                end=None,
 *                **kwargs):
 */
    values[4] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1219
 *                region=None,
 *                reference=None,
 *                end=None,             # <<<<<<<<<<<<<<
 *                **kwargs):
 *         """perform a :term:`pileup` within a :term:`region`. The region is
 */
    values[5] = ((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  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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 = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[5] = 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_ERR(0, 1213, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_reference = values[4];
    __pyx_v_end = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1213, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reference, __pyx_v_end, __pyx_v_kwargs);

  /* "pysam/libcalignmentfile.pyx":1213
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reference, PyObject *__pyx_v_end, PyObject *__pyx_v_kwargs) {
  int __pyx_v_rtid;
  int __pyx_v_has_coord;
  int32_t __pyx_v_rstart;
  int32_t __pyx_v_rstop;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  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)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  int32_t __pyx_t_12;
  int32_t __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("pileup", 0);
  __Pyx_TraceCall("pileup", __pyx_f[0], 1213, 0, __PYX_ERR(0, 1213, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1332
 *         cdef int32_t rstart, rstop
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1332, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1333
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1333, __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_ERR(0, 1333, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1332
 *         cdef int32_t rstart, rstop
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1335
 *             raise ValueError("I/O operation on closed file")
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":1336
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 *             contig, start, stop, region, reference=reference, end=end)             # <<<<<<<<<<<<<<
 * 
 *         if has_coord:
 */
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_contig);
  __Pyx_GIVEREF(__pyx_v_contig);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_contig);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_start);
  __Pyx_INCREF(__pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_stop);
  __Pyx_INCREF(__pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_region);
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1336, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1336, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1335
 *             raise ValueError("I/O operation on closed file")
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
    PyObject* sequence = __pyx_t_6;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1335, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_7);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1335, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
    __pyx_t_8 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1335, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 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_ERR(0, 1335, __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_ERR(0, 1335, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_12 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int32_t(__pyx_t_7); if (unlikely((__pyx_t_13 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1335, __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_rstop = __pyx_t_13;

  /* "pysam/libcalignmentfile.pyx":1338
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 *         if has_coord:             # <<<<<<<<<<<<<<
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")
 */
  __pyx_t_3 = (__pyx_v_has_coord != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1339
 * 
 *         if has_coord:
 *             if not self.has_index():             # <<<<<<<<<<<<<<
 *                 raise ValueError("no index available for pileup")
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1339, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1339, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1339, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = ((!__pyx_t_3) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":1340
 *         if has_coord:
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorColumnRegion(self,
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1340, __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_ERR(0, 1340, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1339
 * 
 *         if has_coord:
 *             if not self.has_index():             # <<<<<<<<<<<<<<
 *                 raise ValueError("no index available for pileup")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":1342
 *                 raise ValueError("no index available for pileup")
 * 
 *             return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                         tid=rtid,
 *                                         start=rstart,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1342, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));

    /* "pysam/libcalignmentfile.pyx":1343
 * 
 *             return IteratorColumnRegion(self,
 *                                         tid=rtid,             # <<<<<<<<<<<<<<
 *                                         start=rstart,
 *                                         stop=rstop,
 */
    __pyx_t_1 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":1344
 *             return IteratorColumnRegion(self,
 *                                         tid=rtid,
 *                                         start=rstart,             # <<<<<<<<<<<<<<
 *                                         stop=rstop,
 *                                         **kwargs)
 */
    __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_rstart); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_4) < 0) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":1345
 *                                         tid=rtid,
 *                                         start=rstart,
 *                                         stop=rstop,             # <<<<<<<<<<<<<<
 *                                         **kwargs)
 *         else:
 */
    __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_rstop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1345, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_stop, __pyx_t_4) < 0) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1346
 *                                         start=rstart,
 *                                         stop=rstop,
 *                                         **kwargs)             # <<<<<<<<<<<<<<
 *         else:
 *             if self.has_index():
 */
    if (__Pyx_MergeKeywords(__pyx_t_7, __pyx_v_kwargs) < 0) __PYX_ERR(0, 1346, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1342
 *                 raise ValueError("no index available for pileup")
 * 
 *             return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                         tid=rtid,
 *                                         start=rstart,
 */
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion), __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1342, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1338
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 *         if has_coord:             # <<<<<<<<<<<<<<
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")
 */
  }

  /* "pysam/libcalignmentfile.pyx":1348
 *                                         **kwargs)
 *         else:
 *             if self.has_index():             # <<<<<<<<<<<<<<
 *                 return IteratorColumnAllRefs(self, **kwargs)
 *             else:
 */
  /*else*/ {
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1348, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":1349
 *         else:
 *             if self.has_index():
 *                 return IteratorColumnAllRefs(self, **kwargs)             # <<<<<<<<<<<<<<
 *             else:
 *                 return IteratorColumnAll(self, **kwargs)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
      __pyx_t_7 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1349, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs), __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1349, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;

      /* "pysam/libcalignmentfile.pyx":1348
 *                                         **kwargs)
 *         else:
 *             if self.has_index():             # <<<<<<<<<<<<<<
 *                 return IteratorColumnAllRefs(self, **kwargs)
 *             else:
 */
    }

    /* "pysam/libcalignmentfile.pyx":1351
 *                 return IteratorColumnAllRefs(self, **kwargs)
 *             else:
 *                 return IteratorColumnAll(self, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     def count(self,
 */
    /*else*/ {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1351, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
      __pyx_t_7 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1351, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll), __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1351, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
    }
  }

  /* "pysam/libcalignmentfile.pyx":1213
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __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.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1353
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count[] = "AlignmentFile.count(self, contig=None, start=None, stop=None, region=None, until_eof=False, read_callback='nofilter', reference=None, end=None)\ncount the number of reads in :term:`region`\n\n        The region is specified by :term:`contig`, `start` and `stop`.\n        :term:`reference` and `end` are also accepted for backward\n        compatibility as synonyms for :term:`contig` and `stop`,\n        respectively.  Alternatively, a `samtools`_ :term:`region`\n        string can be supplied.\n\n        A :term:`SAM` file does not allow random access and if\n        `region` or `contig` are given, an exception is raised.\n\n        Parameters\n        ----------\n\n        contig : string\n            reference_name of the genomic region (chromosome)\n\n        start : int\n            start of the genomic region (0-based inclusive)\n\n        stop : int\n            end of the genomic region (0-based exclusive)\n\n        region : string\n            a region string in samtools format.\n\n        until_eof : bool\n            count until the end of the file, possibly including\n            unmapped reads as well.\n\n        read_callback: string or function\n\n            select a call-back to ignore reads when counting. It can\n            be either a string with the following values:\n\n            ``all``\n                skip reads in which any of the following\n                flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n                BAM_FDUP\n\n            ``nofilter``\n                uses every single read\n\n            Alternatively, `read_callback` can be a function\n            ``check_read(read)`` that should return True only for\n            those reads that shall be included in the counting.\n\n        reference : string\n            backward compatible synonym for `contig`\n\n        end : int\n            backward compatible synonym for `stop`\n\n        Raises\n        ------\n\n        ValueError\n            if the genomic coordin""ates are out of range or invalid.\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_until_eof = 0;
  PyObject *__pyx_v_read_callback = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 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_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_until_eof,&__pyx_n_s_read_callback,&__pyx_n_s_reference,&__pyx_n_s_end,0};
    PyObject* values[8] = {0,0,0,0,0,0,0,0};

    /* "pysam/libcalignmentfile.pyx":1354
 * 
 *     def count(self,
 *               contig=None,             # <<<<<<<<<<<<<<
 *               start=None,
 *               stop=None,
 */
    values[0] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1355
 *     def count(self,
 *               contig=None,
 *               start=None,             # <<<<<<<<<<<<<<
 *               stop=None,
 *               region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1356
 *               contig=None,
 *               start=None,
 *               stop=None,             # <<<<<<<<<<<<<<
 *               region=None,
 *               until_eof=False,
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1357
 *               start=None,
 *               stop=None,
 *               region=None,             # <<<<<<<<<<<<<<
 *               until_eof=False,
 *               read_callback="nofilter",
 */
    values[3] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1358
 *               stop=None,
 *               region=None,
 *               until_eof=False,             # <<<<<<<<<<<<<<
 *               read_callback="nofilter",
 *               reference=None,
 */
    values[4] = ((PyObject *)Py_False);
    values[5] = ((PyObject *)__pyx_n_s_nofilter);

    /* "pysam/libcalignmentfile.pyx":1360
 *               until_eof=False,
 *               read_callback="nofilter",
 *               reference=None,             # <<<<<<<<<<<<<<
 *               end=None):
 *         '''count the number of reads in :term:`region`
 */
    values[6] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1361
 *               read_callback="nofilter",
 *               reference=None,
 *               end=None):             # <<<<<<<<<<<<<<
 *         '''count the number of reads in :term:`region`
 * 
 */
    values[7] = ((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  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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 = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_until_eof);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_read_callback);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[6] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[7] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) __PYX_ERR(0, 1353, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_until_eof = values[4];
    __pyx_v_read_callback = values[5];
    __pyx_v_reference = values[6];
    __pyx_v_end = values[7];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count", 0, 0, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1353, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_until_eof, __pyx_v_read_callback, __pyx_v_reference, __pyx_v_end);

  /* "pysam/libcalignmentfile.pyx":1353
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) {
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0;
  long __pyx_v_counter;
  int __pyx_v_filter_method;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("count", 0);
  __Pyx_TraceCall("count", __pyx_f[0], 1353, 0, __PYX_ERR(0, 1353, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1423
 *         '''
 *         cdef AlignedSegment read
 *         cdef long counter = 0             # <<<<<<<<<<<<<<
 * 
 *         if not self.is_open:
 */
  __pyx_v_counter = 0;

  /* "pysam/libcalignmentfile.pyx":1425
 *         cdef long counter = 0
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1425, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1425, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1426
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         cdef int filter_method = 0
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1426, __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_ERR(0, 1426, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1425
 *         cdef long counter = 0
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1428
 *             raise ValueError("I/O operation on closed file")
 * 
 *         cdef int filter_method = 0             # <<<<<<<<<<<<<<
 *         if read_callback == "all":
 *             filter_method = 1
 */
  __pyx_v_filter_method = 0;

  /* "pysam/libcalignmentfile.pyx":1429
 * 
 *         cdef int filter_method = 0
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1429, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1430
 *         cdef int filter_method = 0
 *         if read_callback == "all":
 *             filter_method = 1             # <<<<<<<<<<<<<<
 *         elif read_callback == "nofilter":
 *             filter_method = 2
 */
    __pyx_v_filter_method = 1;

    /* "pysam/libcalignmentfile.pyx":1429
 * 
 *         cdef int filter_method = 0
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":1431
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1431, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1432
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 *             filter_method = 2             # <<<<<<<<<<<<<<
 * 
 *         for read in self.fetch(contig=contig,
 */
    __pyx_v_filter_method = 2;

    /* "pysam/libcalignmentfile.pyx":1431
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":1434
 *             filter_method = 2
 * 
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1434, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1434, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1435
 * 
 *         for read in self.fetch(contig=contig,
 *                                start=start,             # <<<<<<<<<<<<<<
 *                                stop=stop,
 *                                reference=reference,
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1436
 *         for read in self.fetch(contig=contig,
 *                                start=start,
 *                                stop=stop,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                end=end,
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1437
 *                                start=start,
 *                                stop=stop,
 *                                reference=reference,             # <<<<<<<<<<<<<<
 *                                end=end,
 *                                region=region,
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1438
 *                                stop=stop,
 *                                reference=reference,
 *                                end=end,             # <<<<<<<<<<<<<<
 *                                region=region,
 *                                until_eof=until_eof):
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1439
 *                                reference=reference,
 *                                end=end,
 *                                region=region,             # <<<<<<<<<<<<<<
 *                                until_eof=until_eof):
 *             # apply filter
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1440
 *                                end=end,
 *                                region=region,
 *                                until_eof=until_eof):             # <<<<<<<<<<<<<<
 *             # apply filter
 *             if filter_method == 1:
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_until_eof, __pyx_v_until_eof) < 0) __PYX_ERR(0, 1434, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1434
 *             filter_method = 2
 * 
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1434, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
    __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1434, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1434, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1434, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1434, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1434, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1434, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_7(__pyx_t_4);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1434, __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_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1434, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":1442
 *                                until_eof=until_eof):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
    switch (__pyx_v_filter_method) {
      case 1:

      /* "pysam/libcalignmentfile.pyx":1444
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1444, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_5, __pyx_int_1796, 0x704, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1444, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1444, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":1445
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue             # <<<<<<<<<<<<<<
 *             elif filter_method == 2:
 *                 # filter = "nofilter"
 */
        goto __pyx_L5_continue;

        /* "pysam/libcalignmentfile.pyx":1444
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      }

      /* "pysam/libcalignmentfile.pyx":1442
 *                                until_eof=until_eof):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
      break;
      case 2:

      /* "pysam/libcalignmentfile.pyx":1446
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue
 *             elif filter_method == 2:             # <<<<<<<<<<<<<<
 *                 # filter = "nofilter"
 *                 pass
 */
      break;
      default:

      /* "pysam/libcalignmentfile.pyx":1450
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 *             counter += 1
 */
      __Pyx_INCREF(__pyx_v_read_callback);
      __pyx_t_5 = __pyx_v_read_callback; __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, ((PyObject *)__pyx_v_read)) : __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_read));
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1450, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1450, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_2 = ((!__pyx_t_3) != 0);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":1451
 *             else:
 *                 if not read_callback(read):
 *                     continue             # <<<<<<<<<<<<<<
 *             counter += 1
 * 
 */
        goto __pyx_L5_continue;

        /* "pysam/libcalignmentfile.pyx":1450
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 *             counter += 1
 */
      }
      break;
    }

    /* "pysam/libcalignmentfile.pyx":1452
 *                 if not read_callback(read):
 *                     continue
 *             counter += 1             # <<<<<<<<<<<<<<
 * 
 *         return counter
 */
    __pyx_v_counter = (__pyx_v_counter + 1);

    /* "pysam/libcalignmentfile.pyx":1434
 *             filter_method = 2
 * 
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
    __pyx_L5_continue:;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":1454
 *             counter += 1
 * 
 *         return counter             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1353
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1457
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 *     def count_coverage(self,             # <<<<<<<<<<<<<<
 *                        contig,
 *                        start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage[] = "AlignmentFile.count_coverage(self, contig, start=None, stop=None, region=None, quality_threshold=15, read_callback='all', reference=None, end=None)\ncount the coverage of genomic positions by reads in :term:`region`.\n\n        The region is specified by :term:`contig`, `start` and `stop`.\n        :term:`reference` and `end` are also accepted for backward\n        compatibility as synonyms for :term:`contig` and `stop`,\n        respectively.  Alternatively, a `samtools`_ :term:`region`\n        string can be supplied.  The coverage is computed per-base [ACGT].\n\n        Parameters\n        ----------\n\n        contig : string\n            reference_name of the genomic region (chromosome)\n\n        start : int\n            start of the genomic region (0-based inclusive). If not\n            given, count from the start of the chromosome.\n\n        stop : int\n            end of the genomic region (0-based exclusive). If not given,\n            count to the end of the chromosome.\n\n        region : string\n            a region string.\n\n        quality_threshold : int\n            quality_threshold is the minimum quality score (in phred) a\n            base has to reach to be counted.\n\n        read_callback: string or function\n\n            select a call-back to ignore reads when counting. It can\n            be either a string with the following values:\n\n            ``all``\n                skip reads in which any of the following\n                flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n                BAM_FDUP\n\n            ``nofilter``\n                uses every single read\n\n            Alternatively, `read_callback` can be a function\n            ``check_read(read)`` that should return True only for\n            those reads that shall be included in the counting.\n\n        reference : string\n            backward compatible synonym for `contig`\n\n        end : int\n            backward compatible synonym for `stop`\n\n        Rai""ses\n        ------\n\n        ValueError\n            if the genomic coordinates are out of range or invalid.\n\n        Returns\n        -------\n\n        four array.arrays of the same length in order A C G T : tuple\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_quality_threshold = 0;
  PyObject *__pyx_v_read_callback = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("count_coverage (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_quality_threshold,&__pyx_n_s_read_callback,&__pyx_n_s_reference,&__pyx_n_s_end,0};
    PyObject* values[8] = {0,0,0,0,0,0,0,0};

    /* "pysam/libcalignmentfile.pyx":1459
 *     def count_coverage(self,
 *                        contig,
 *                        start=None,             # <<<<<<<<<<<<<<
 *                        stop=None,
 *                        region=None,
 */
    values[1] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1460
 *                        contig,
 *                        start=None,
 *                        stop=None,             # <<<<<<<<<<<<<<
 *                        region=None,
 *                        quality_threshold=15,
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1461
 *                        start=None,
 *                        stop=None,
 *                        region=None,             # <<<<<<<<<<<<<<
 *                        quality_threshold=15,
 *                        read_callback='all',
 */
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)__pyx_int_15);
    values[5] = ((PyObject *)__pyx_n_s_all);

    /* "pysam/libcalignmentfile.pyx":1464
 *                        quality_threshold=15,
 *                        read_callback='all',
 *                        reference=None,             # <<<<<<<<<<<<<<
 *                        end=None):
 *         """count the coverage of genomic positions by reads in :term:`region`.
 */
    values[6] = ((PyObject *)Py_None);

    /* "pysam/libcalignmentfile.pyx":1465
 *                        read_callback='all',
 *                        reference=None,
 *                        end=None):             # <<<<<<<<<<<<<<
 *         """count the coverage of genomic positions by reads in :term:`region`.
 * 
 */
    values[7] = ((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  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quality_threshold);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_read_callback);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[6] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[7] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count_coverage") < 0)) __PYX_ERR(0, 1457, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_quality_threshold = values[4];
    __pyx_v_read_callback = values[5];
    __pyx_v_reference = values[6];
    __pyx_v_end = values[7];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 1, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1457, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_quality_threshold, __pyx_v_read_callback, __pyx_v_reference, __pyx_v_end);

  /* "pysam/libcalignmentfile.pyx":1457
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 *     def count_coverage(self,             # <<<<<<<<<<<<<<
 *                        contig,
 *                        start=None,
 */

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) {
  uint32_t __pyx_v_contig_length;
  int __pyx_v__start;
  int __pyx_v__stop;
  int __pyx_v_length;
  arrayobject *__pyx_v_int_array_template = 0;
  arrayobject *__pyx_v_count_a = 0;
  arrayobject *__pyx_v_count_c = 0;
  arrayobject *__pyx_v_count_g = 0;
  arrayobject *__pyx_v_count_t = 0;
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0;
  PyObject *__pyx_v_seq = 0;
  arrayobject *__pyx_v_quality = 0;
  int __pyx_v_qpos;
  int __pyx_v_refpos;
  CYTHON_UNUSED int __pyx_v_c;
  int __pyx_v_filter_method;
  int __pyx_v__threshold;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  uint32_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *(*__pyx_t_16)(PyObject *);
  int __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("count_coverage", 0);
  __Pyx_TraceCall("count_coverage", __pyx_f[0], 1457, 0, __PYX_ERR(0, 1457, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1531
 *         """
 * 
 *         cdef uint32_t contig_length = self.get_reference_length(contig)             # <<<<<<<<<<<<<<
 *         cdef int _start = start if start is not None else 0
 *         cdef int _stop = stop if stop is not None else contig_length
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_contig) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_contig);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1531, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_contig_length = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":1532
 * 
 *         cdef uint32_t contig_length = self.get_reference_length(contig)
 *         cdef int _start = start if start is not None else 0             # <<<<<<<<<<<<<<
 *         cdef int _stop = stop if stop is not None else contig_length
 *         _stop = _stop if _stop < contig_length else contig_length
 */
  __pyx_t_6 = (__pyx_v_start != Py_None);
  if ((__pyx_t_6 != 0)) {
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1532, __pyx_L1_error)
    __pyx_t_5 = __pyx_t_7;
  } else {
    __pyx_t_5 = 0;
  }
  __pyx_v__start = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":1533
 *         cdef uint32_t contig_length = self.get_reference_length(contig)
 *         cdef int _start = start if start is not None else 0
 *         cdef int _stop = stop if stop is not None else contig_length             # <<<<<<<<<<<<<<
 *         _stop = _stop if _stop < contig_length else contig_length
 * 
 */
  __pyx_t_6 = (__pyx_v_stop != Py_None);
  if ((__pyx_t_6 != 0)) {
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1533, __pyx_L1_error)
    __pyx_t_5 = __pyx_t_7;
  } else {
    __pyx_t_5 = __pyx_v_contig_length;
  }
  __pyx_v__stop = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":1534
 *         cdef int _start = start if start is not None else 0
 *         cdef int _stop = stop if stop is not None else contig_length
 *         _stop = _stop if _stop < contig_length else contig_length             # <<<<<<<<<<<<<<
 * 
 *         if _stop == _start:
 */
  if (((__pyx_v__stop < __pyx_v_contig_length) != 0)) {
    __pyx_t_4 = __pyx_v__stop;
  } else {
    __pyx_t_4 = __pyx_v_contig_length;
  }
  __pyx_v__stop = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":1536
 *         _stop = _stop if _stop < contig_length else contig_length
 * 
 *         if _stop == _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 */
  __pyx_t_6 = ((__pyx_v__stop == __pyx_v__start) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "pysam/libcalignmentfile.pyx":1537
 * 
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")             # <<<<<<<<<<<<<<
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1537, __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_ERR(0, 1537, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1536
 *         _stop = _stop if _stop < contig_length else contig_length
 * 
 *         if _stop == _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1538
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size less than 0")
 * 
 */
  __pyx_t_6 = ((__pyx_v__stop < __pyx_v__start) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "pysam/libcalignmentfile.pyx":1539
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")             # <<<<<<<<<<<<<<
 * 
 *         cdef int length = _stop - _start
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1539, __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_ERR(0, 1539, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1538
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size less than 0")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1541
 *             raise ValueError("interval of size less than 0")
 * 
 *         cdef int length = _stop - _start             # <<<<<<<<<<<<<<
 *         cdef c_array.array int_array_template = array.array('L', [])
 *         cdef c_array.array count_a
 */
  __pyx_v_length = (__pyx_v__stop - __pyx_v__start);

  /* "pysam/libcalignmentfile.pyx":1542
 * 
 *         cdef int length = _stop - _start
 *         cdef c_array.array int_array_template = array.array('L', [])             # <<<<<<<<<<<<<<
 *         cdef c_array.array count_a
 *         cdef c_array.array count_c
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_L);
  __Pyx_GIVEREF(__pyx_n_s_L);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_L);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_int_array_template = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1547
 *         cdef c_array.array count_g
 *         cdef c_array.array count_t
 *         count_a = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_c = c_array.clone(int_array_template, length, zero=True)
 *         count_g = c_array.clone(int_array_template, length, zero=True)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_a = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1548
 *         cdef c_array.array count_t
 *         count_a = c_array.clone(int_array_template, length, zero=True)
 *         count_c = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_g = c_array.clone(int_array_template, length, zero=True)
 *         count_t = c_array.clone(int_array_template, length, zero=True)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_c = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1549
 *         count_a = c_array.clone(int_array_template, length, zero=True)
 *         count_c = c_array.clone(int_array_template, length, zero=True)
 *         count_g = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_t = c_array.clone(int_array_template, length, zero=True)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1549, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_g = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1550
 *         count_c = c_array.clone(int_array_template, length, zero=True)
 *         count_g = c_array.clone(int_array_template, length, zero=True)
 *         count_t = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 * 
 *         cdef AlignedSegment read
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1550, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_t = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1557
 *         cdef int qpos
 *         cdef int refpos
 *         cdef int c = 0             # <<<<<<<<<<<<<<
 *         cdef int filter_method = 0
 * 
 */
  __pyx_v_c = 0;

  /* "pysam/libcalignmentfile.pyx":1558
 *         cdef int refpos
 *         cdef int c = 0
 *         cdef int filter_method = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_filter_method = 0;

  /* "pysam/libcalignmentfile.pyx":1561
 * 
 * 
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
  __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1561, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "pysam/libcalignmentfile.pyx":1562
 * 
 *         if read_callback == "all":
 *             filter_method = 1             # <<<<<<<<<<<<<<
 *         elif read_callback == "nofilter":
 *             filter_method = 2
 */
    __pyx_v_filter_method = 1;

    /* "pysam/libcalignmentfile.pyx":1561
 * 
 * 
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
    goto __pyx_L5;
  }

  /* "pysam/libcalignmentfile.pyx":1563
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1563, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "pysam/libcalignmentfile.pyx":1564
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 *             filter_method = 2             # <<<<<<<<<<<<<<
 * 
 *         cdef int _threshold = quality_threshold or 0
 */
    __pyx_v_filter_method = 2;

    /* "pysam/libcalignmentfile.pyx":1563
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  }
  __pyx_L5:;

  /* "pysam/libcalignmentfile.pyx":1566
 *             filter_method = 2
 * 
 *         cdef int _threshold = quality_threshold or 0             # <<<<<<<<<<<<<<
 *         for read in self.fetch(contig=contig,
 *                                reference=reference,
 */
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_quality_threshold); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1566, __pyx_L1_error)
  if (!__pyx_t_6) {
  } else {
    __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_quality_threshold); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1566, __pyx_L1_error)
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_5 = 0;
  __pyx_L6_bool_binop_done:;
  __pyx_v__threshold = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":1567
 * 
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                start=start,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 1567, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1568
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,
 *                                reference=reference,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1567, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1569
 *         for read in self.fetch(contig=contig,
 *                                reference=reference,
 *                                start=start,             # <<<<<<<<<<<<<<
 *                                stop=stop,
 *                                end=end,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1567, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1570
 *                                reference=reference,
 *                                start=start,
 *                                stop=stop,             # <<<<<<<<<<<<<<
 *                                end=end,
 *                                region=region):
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 1567, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1571
 *                                start=start,
 *                                stop=stop,
 *                                end=end,             # <<<<<<<<<<<<<<
 *                                region=region):
 *             # apply filter
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1567, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1572
 *                                stop=stop,
 *                                end=end,
 *                                region=region):             # <<<<<<<<<<<<<<
 *             # apply filter
 *             if filter_method == 1:
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1567, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1567
 * 
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                start=start,
 */
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1567, __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;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1567, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_9)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1567, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1567, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 1567, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1567, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_9(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1567, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1567, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1574
 *                                region=region):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
    switch (__pyx_v_filter_method) {
      case 1:

      /* "pysam/libcalignmentfile.pyx":1576
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1576, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_3, __pyx_int_1796, 0x704, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1576, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1576, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_6) {

        /* "pysam/libcalignmentfile.pyx":1577
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue             # <<<<<<<<<<<<<<
 *             elif filter_method == 2:
 *                 # filter = "nofilter"
 */
        goto __pyx_L8_continue;

        /* "pysam/libcalignmentfile.pyx":1576
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      }

      /* "pysam/libcalignmentfile.pyx":1574
 *                                region=region):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
      break;
      case 2:

      /* "pysam/libcalignmentfile.pyx":1578
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue
 *             elif filter_method == 2:             # <<<<<<<<<<<<<<
 *                 # filter = "nofilter"
 *                 pass
 */
      break;
      default:

      /* "pysam/libcalignmentfile.pyx":1582
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
      __Pyx_INCREF(__pyx_v_read_callback);
      __pyx_t_3 = __pyx_v_read_callback; __pyx_t_10 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_10, ((PyObject *)__pyx_v_read)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_read));
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1582, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1582, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_11 = ((!__pyx_t_6) != 0);
      if (__pyx_t_11) {

        /* "pysam/libcalignmentfile.pyx":1583
 *             else:
 *                 if not read_callback(read):
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *             # count
 */
        goto __pyx_L8_continue;

        /* "pysam/libcalignmentfile.pyx":1582
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
      }
      break;
    }

    /* "pysam/libcalignmentfile.pyx":1586
 * 
 *             # count
 *             seq = read.seq             # <<<<<<<<<<<<<<
 *             if seq is None:
 *                 continue
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_seq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    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_ERR(0, 1586, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seq, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1587
 *             # count
 *             seq = read.seq
 *             if seq is None:             # <<<<<<<<<<<<<<
 *                 continue
 *             quality = read.query_qualities
 */
    __pyx_t_11 = (__pyx_v_seq == ((PyObject*)Py_None));
    __pyx_t_6 = (__pyx_t_11 != 0);
    if (__pyx_t_6) {

      /* "pysam/libcalignmentfile.pyx":1588
 *             seq = read.seq
 *             if seq is None:
 *                 continue             # <<<<<<<<<<<<<<
 *             quality = read.query_qualities
 * 
 */
      goto __pyx_L8_continue;

      /* "pysam/libcalignmentfile.pyx":1587
 *             # count
 *             seq = read.seq
 *             if seq is None:             # <<<<<<<<<<<<<<
 *                 continue
 *             quality = read.query_qualities
 */
    }

    /* "pysam/libcalignmentfile.pyx":1589
 *             if seq is None:
 *                 continue
 *             quality = read.query_qualities             # <<<<<<<<<<<<<<
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1589, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1589, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_quality, ((arrayobject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1591
 *             quality = read.query_qualities
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):             # <<<<<<<<<<<<<<
 *                 if qpos is not None and refpos is not None and \
 *                    _start <= refpos < _stop:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_10 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_10, Py_True) : __Pyx_PyObject_CallOneArg(__pyx_t_3, Py_True);
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_12 = 0;
      __pyx_t_13 = NULL;
    } else {
      __pyx_t_12 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1591, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_13 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1591, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_13)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 1591, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 1591, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_13(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1591, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1591, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_14 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_14);
        #else
        __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1591, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1591, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_15 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1591, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext;
        index = 0; __pyx_t_10 = __pyx_t_16(__pyx_t_15); if (unlikely(!__pyx_t_10)) goto __pyx_L15_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        index = 1; __pyx_t_14 = __pyx_t_16(__pyx_t_15); if (unlikely(!__pyx_t_14)) goto __pyx_L15_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_14);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_15), 2) < 0) __PYX_ERR(0, 1591, __pyx_L1_error)
        __pyx_t_16 = NULL;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        goto __pyx_L16_unpacking_done;
        __pyx_L15_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_16 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1591, __pyx_L1_error)
        __pyx_L16_unpacking_done:;
      }
      __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1591, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1591, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_v_qpos = __pyx_t_5;
      __pyx_v_refpos = __pyx_t_7;

      /* "pysam/libcalignmentfile.pyx":1592
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \             # <<<<<<<<<<<<<<
 *                    _start <= refpos < _stop:
 * 
 */
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_qpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = (__pyx_t_1 != Py_None);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_17 = (__pyx_t_11 != 0);
      if (__pyx_t_17) {
      } else {
        __pyx_t_6 = __pyx_t_17;
        goto __pyx_L18_bool_binop_done;
      }
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_refpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_17 = (__pyx_t_1 != Py_None);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_11 = (__pyx_t_17 != 0);
      if (__pyx_t_11) {
      } else {
        __pyx_t_6 = __pyx_t_11;
        goto __pyx_L18_bool_binop_done;
      }

      /* "pysam/libcalignmentfile.pyx":1593
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \
 *                    _start <= refpos < _stop:             # <<<<<<<<<<<<<<
 * 
 *                     # only check base quality if _threshold > 0
 */
      __pyx_t_11 = (__pyx_v__start <= __pyx_v_refpos);
      if (__pyx_t_11) {
        __pyx_t_11 = (__pyx_v_refpos < __pyx_v__stop);
      }
      __pyx_t_17 = (__pyx_t_11 != 0);
      __pyx_t_6 = __pyx_t_17;
      __pyx_L18_bool_binop_done:;

      /* "pysam/libcalignmentfile.pyx":1592
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \             # <<<<<<<<<<<<<<
 *                    _start <= refpos < _stop:
 * 
 */
      if (__pyx_t_6) {

        /* "pysam/libcalignmentfile.pyx":1596
 * 
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 */
        __pyx_t_17 = (__pyx_v__threshold != 0);
        if (!__pyx_t_17) {
          goto __pyx_L23_next_or;
        } else {
        }
        __pyx_t_17 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_quality)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 1596, __pyx_L1_error)
        if (!__pyx_t_17) {
          goto __pyx_L23_next_or;
        } else {
        }
        __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quality), __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1596, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v__threshold); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1596, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_10 = PyObject_RichCompare(__pyx_t_1, __pyx_t_14, Py_GE); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1596, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 1596, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (!__pyx_t_17) {
        } else {
          __pyx_t_6 = __pyx_t_17;
          goto __pyx_L22_bool_binop_done;
        }
        __pyx_L23_next_or:;
        __pyx_t_17 = ((!(__pyx_v__threshold != 0)) != 0);
        __pyx_t_6 = __pyx_t_17;
        __pyx_L22_bool_binop_done:;
        if (__pyx_t_6) {

          /* "pysam/libcalignmentfile.pyx":1597
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:
 *                         if seq[qpos] == 'A':             # <<<<<<<<<<<<<<
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 */
          __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1597, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_t_10, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1597, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_6) {

            /* "pysam/libcalignmentfile.pyx":1598
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 */
            __pyx_t_7 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_a->data.as_ulongs[__pyx_t_7]) = ((__pyx_v_count_a->data.as_ulongs[__pyx_t_7]) + 1);

            /* "pysam/libcalignmentfile.pyx":1597
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:
 *                         if seq[qpos] == 'A':             # <<<<<<<<<<<<<<
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 */
          }

          /* "pysam/libcalignmentfile.pyx":1599
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':             # <<<<<<<<<<<<<<
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':
 */
          __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1599, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_t_10, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1599, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_6) {

            /* "pysam/libcalignmentfile.pyx":1600
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 */
            __pyx_t_7 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_c->data.as_ulongs[__pyx_t_7]) = ((__pyx_v_count_c->data.as_ulongs[__pyx_t_7]) + 1);

            /* "pysam/libcalignmentfile.pyx":1599
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':             # <<<<<<<<<<<<<<
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':
 */
          }

          /* "pysam/libcalignmentfile.pyx":1601
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':             # <<<<<<<<<<<<<<
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':
 */
          __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1601, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_t_10, __pyx_n_s_G, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1601, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_6) {

            /* "pysam/libcalignmentfile.pyx":1602
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'T':
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 */
            __pyx_t_7 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_g->data.as_ulongs[__pyx_t_7]) = ((__pyx_v_count_g->data.as_ulongs[__pyx_t_7]) + 1);

            /* "pysam/libcalignmentfile.pyx":1601
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':             # <<<<<<<<<<<<<<
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':
 */
          }

          /* "pysam/libcalignmentfile.pyx":1603
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':             # <<<<<<<<<<<<<<
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 * 
 */
          __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1603, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = (__Pyx_PyString_Equals(__pyx_t_10, __pyx_n_s_T, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1603, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_6) {

            /* "pysam/libcalignmentfile.pyx":1604
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':
 *                             count_t.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 * 
 *         return count_a, count_c, count_g, count_t
 */
            __pyx_t_7 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_t->data.as_ulongs[__pyx_t_7]) = ((__pyx_v_count_t->data.as_ulongs[__pyx_t_7]) + 1);

            /* "pysam/libcalignmentfile.pyx":1603
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':             # <<<<<<<<<<<<<<
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 * 
 */
          }

          /* "pysam/libcalignmentfile.pyx":1596
 * 
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 */
        }

        /* "pysam/libcalignmentfile.pyx":1592
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \             # <<<<<<<<<<<<<<
 *                    _start <= refpos < _stop:
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":1591
 *             quality = read.query_qualities
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):             # <<<<<<<<<<<<<<
 *                 if qpos is not None and refpos is not None and \
 *                    _start <= refpos < _stop:
 */
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1567
 * 
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                start=start,
 */
    __pyx_L8_continue:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":1606
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 * 
 *         return count_a, count_c, count_g, count_t             # <<<<<<<<<<<<<<
 * 
 *     def find_introns_slow(self, read_iterator):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1606, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_count_a));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_a));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_count_a));
  __Pyx_INCREF(((PyObject *)__pyx_v_count_c));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_c));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_count_c));
  __Pyx_INCREF(((PyObject *)__pyx_v_count_g));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_g));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_count_g));
  __Pyx_INCREF(((PyObject *)__pyx_v_count_t));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_t));
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_count_t));
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1457
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 *     def count_coverage(self,             # <<<<<<<<<<<<<<
 *                        contig,
 *                        start=None,
 */

  /* 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_10);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_int_array_template);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_a);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_c);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_g);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_t);
  __Pyx_XDECREF((PyObject *)__pyx_v_read);
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_XDECREF((PyObject *)__pyx_v_quality);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1608
 *         return count_a, count_c, count_g, count_t
 * 
 *     def find_introns_slow(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow[] = "AlignmentFile.find_introns_slow(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n        Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n        and their support ( = number of reads ).\n\n        read_iterator can be the result of a .fetch(...) call.\n        Or it can be a generator filtering such reads. Example\n        samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_introns_slow (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_read_iterator));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) {
  PyObject *__pyx_v_res = NULL;
  PyObject *__pyx_v_r = NULL;
  PyObject *__pyx_v_last_read_pos = NULL;
  PyObject *__pyx_v_read_loc = NULL;
  PyObject *__pyx_v_genome_loc = NULL;
  PyObject *__pyx_v_start = NULL;
  PyObject *__pyx_v_stop = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("find_introns_slow", 0);
  __Pyx_TraceCall("find_introns_slow", __pyx_f[0], 1608, 0, __PYX_ERR(0, 1608, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1617
 *         samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)
 *         """
 *         res = collections.Counter()             # <<<<<<<<<<<<<<
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1617, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Counter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1617, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1617, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_res = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1618
 *         """
 *         res = collections.Counter()
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 */
  if (likely(PyList_CheckExact(__pyx_v_read_iterator)) || PyTuple_CheckExact(__pyx_v_read_iterator)) {
    __pyx_t_1 = __pyx_v_read_iterator; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1618, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1618, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1618, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1618, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1618, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1618, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_1);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1618, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1619
 *         res = collections.Counter()
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:             # <<<<<<<<<<<<<<
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1619, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_N, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1619, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = (__pyx_t_6 != 0);
    if (__pyx_t_7) {

      /* "pysam/libcalignmentfile.pyx":1620
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False             # <<<<<<<<<<<<<<
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:
 */
      __Pyx_INCREF(Py_False);
      __Pyx_XDECREF_SET(__pyx_v_last_read_pos, Py_False);

      /* "pysam/libcalignmentfile.pyx":1621
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():             # <<<<<<<<<<<<<<
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1621, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1621, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_9 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1621, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1621, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1621, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1621, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1621, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1621, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_10(__pyx_t_2);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1621, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
          PyObject* sequence = __pyx_t_3;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 1621, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_11 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_11);
          #else
          __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1621, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1621, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          #endif
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_12 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1621, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext;
          index = 0; __pyx_t_8 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_8);
          index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L8_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_11);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) __PYX_ERR(0, 1621, __pyx_L1_error)
          __pyx_t_13 = NULL;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          goto __pyx_L9_unpacking_done;
          __pyx_L8_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_13 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 1621, __pyx_L1_error)
          __pyx_L9_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_read_loc, __pyx_t_8);
        __pyx_t_8 = 0;
        __Pyx_XDECREF_SET(__pyx_v_genome_loc, __pyx_t_11);
        __pyx_t_11 = 0;

        /* "pysam/libcalignmentfile.pyx":1622
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:             # <<<<<<<<<<<<<<
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:
 */
        __pyx_t_6 = (__pyx_v_read_loc == Py_None);
        __pyx_t_14 = (__pyx_t_6 != 0);
        if (__pyx_t_14) {
        } else {
          __pyx_t_7 = __pyx_t_14;
          goto __pyx_L11_bool_binop_done;
        }
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_last_read_pos); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1622, __pyx_L1_error)
        __pyx_t_7 = __pyx_t_14;
        __pyx_L11_bool_binop_done:;
        if (__pyx_t_7) {

          /* "pysam/libcalignmentfile.pyx":1623
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc             # <<<<<<<<<<<<<<
 *                     elif read_loc and last_read_pos is None:
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 */
          __Pyx_INCREF(__pyx_v_genome_loc);
          __Pyx_XDECREF_SET(__pyx_v_start, __pyx_v_genome_loc);

          /* "pysam/libcalignmentfile.pyx":1622
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:             # <<<<<<<<<<<<<<
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:
 */
          goto __pyx_L10;
        }

        /* "pysam/libcalignmentfile.pyx":1624
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:             # <<<<<<<<<<<<<<
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1
 */
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_read_loc); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1624, __pyx_L1_error)
        if (__pyx_t_14) {
        } else {
          __pyx_t_7 = __pyx_t_14;
          goto __pyx_L13_bool_binop_done;
        }
        __pyx_t_14 = (__pyx_v_last_read_pos == Py_None);
        __pyx_t_6 = (__pyx_t_14 != 0);
        __pyx_t_7 = __pyx_t_6;
        __pyx_L13_bool_binop_done:;
        if (__pyx_t_7) {

          /* "pysam/libcalignmentfile.pyx":1625
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:
 *                         stop = genome_loc  # we are right exclusive ,so this is correct             # <<<<<<<<<<<<<<
 *                         res[(start, stop)] += 1
 *                         del start
 */
          __Pyx_INCREF(__pyx_v_genome_loc);
          __pyx_v_stop = __pyx_v_genome_loc;

          /* "pysam/libcalignmentfile.pyx":1626
 *                     elif read_loc and last_read_pos is None:
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1             # <<<<<<<<<<<<<<
 *                         del start
 *                         del stop
 */
          if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1626, __pyx_L1_error) }
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1626, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_INCREF(__pyx_v_start);
          __Pyx_GIVEREF(__pyx_v_start);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_start);
          __Pyx_INCREF(__pyx_v_stop);
          __Pyx_GIVEREF(__pyx_v_stop);
          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_stop);
          __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1626, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_11, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1626, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_res, __pyx_t_3, __pyx_t_8) < 0)) __PYX_ERR(0, 1626, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pysam/libcalignmentfile.pyx":1627
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1
 *                         del start             # <<<<<<<<<<<<<<
 *                         del stop
 *                     last_read_pos = read_loc
 */
          if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1627, __pyx_L1_error) }
          __Pyx_DECREF(__pyx_v_start);
          __pyx_v_start = NULL;

          /* "pysam/libcalignmentfile.pyx":1628
 *                         res[(start, stop)] += 1
 *                         del start
 *                         del stop             # <<<<<<<<<<<<<<
 *                     last_read_pos = read_loc
 *         return res
 */
          __Pyx_DECREF(__pyx_v_stop);
          __pyx_v_stop = NULL;

          /* "pysam/libcalignmentfile.pyx":1624
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:             # <<<<<<<<<<<<<<
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1
 */
        }
        __pyx_L10:;

        /* "pysam/libcalignmentfile.pyx":1629
 *                         del start
 *                         del stop
 *                     last_read_pos = read_loc             # <<<<<<<<<<<<<<
 *         return res
 * 
 */
        __Pyx_INCREF(__pyx_v_read_loc);
        __Pyx_DECREF_SET(__pyx_v_last_read_pos, __pyx_v_read_loc);

        /* "pysam/libcalignmentfile.pyx":1621
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():             # <<<<<<<<<<<<<<
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 */
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":1619
 *         res = collections.Counter()
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:             # <<<<<<<<<<<<<<
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 */
    }

    /* "pysam/libcalignmentfile.pyx":1618
 *         """
 *         res = collections.Counter()
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1630
 *                         del stop
 *                     last_read_pos = read_loc
 *         return res             # <<<<<<<<<<<<<<
 * 
 *     def find_introns(self, read_iterator):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_res);
  __pyx_r = __pyx_v_res;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1608
 *         return count_a, count_c, count_g, count_t
 * 
 *     def find_introns_slow(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

  /* 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_8);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns_slow", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_res);
  __Pyx_XDECREF(__pyx_v_r);
  __Pyx_XDECREF(__pyx_v_last_read_pos);
  __Pyx_XDECREF(__pyx_v_read_loc);
  __Pyx_XDECREF(__pyx_v_genome_loc);
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_stop);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1632
 *         return res
 * 
 *     def find_introns(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns[] = "AlignmentFile.find_introns(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n        Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n        and their support ( = number of reads ).\n\n        read_iterator can be the result of a .fetch(...) call.\n        Or it can be a generator filtering such reads. Example\n        samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_introns (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_read_iterator));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) {
  uint32_t __pyx_v_base_position;
  uint32_t __pyx_v_junc_start;
  uint32_t __pyx_v_nt;
  int __pyx_v_op;
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_r = 0;
  int __pyx_v_BAM_CREF_SKIP;
  PyObject *__pyx_v_res = NULL;
  PyObject *__pyx_v_match_or_deletion = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  uint32_t __pyx_t_6;
  Py_ssize_t __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;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("find_introns", 0);
  __Pyx_TraceCall("find_introns", __pyx_f[0], 1632, 0, __PYX_ERR(0, 1632, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1645
 *             int op
 *             AlignedSegment r
 *             int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP             # <<<<<<<<<<<<<<
 * 
 *         res = collections.Counter()
 */
  __pyx_v_BAM_CREF_SKIP = 3;

  /* "pysam/libcalignmentfile.pyx":1647
 *             int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP
 * 
 *         res = collections.Counter()             # <<<<<<<<<<<<<<
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Counter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_res = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1649
 *         res = collections.Counter()
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position             # <<<<<<<<<<<<<<
 *         for r in read_iterator:
 *             base_position = r.pos
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PySet_Add(__pyx_t_1, __pyx_int_0) < 0) __PYX_ERR(0, 1649, __pyx_L1_error)
  if (PySet_Add(__pyx_t_1, __pyx_int_2) < 0) __PYX_ERR(0, 1649, __pyx_L1_error)
  if (PySet_Add(__pyx_t_1, __pyx_int_7) < 0) __PYX_ERR(0, 1649, __pyx_L1_error)
  if (PySet_Add(__pyx_t_1, __pyx_int_8) < 0) __PYX_ERR(0, 1649, __pyx_L1_error)
  __pyx_v_match_or_deletion = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1650
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             base_position = r.pos
 * 
 */
  if (likely(PyList_CheckExact(__pyx_v_read_iterator)) || PyTuple_CheckExact(__pyx_v_read_iterator)) {
    __pyx_t_1 = __pyx_v_read_iterator; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1650, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1650, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1650, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1650, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1650, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_1);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1650, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1650, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_r, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1651
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 *         for r in read_iterator:
 *             base_position = r.pos             # <<<<<<<<<<<<<<
 * 
 *             for op, nt in r.cigartuples:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_6 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_base_position = __pyx_t_6;

    /* "pysam/libcalignmentfile.pyx":1653
 *             base_position = r.pos
 * 
 *             for op, nt in r.cigartuples:             # <<<<<<<<<<<<<<
 *                 if op in match_or_deletion:
 *                     base_position += nt
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1653, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 1653, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_8(__pyx_t_2);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1653, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
        PyObject* sequence = __pyx_t_3;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1653, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        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_ERR(0, 1653, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1653, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1653, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_L7_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_L7_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 1653, __pyx_L1_error)
        __pyx_t_12 = NULL;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L8_unpacking_done;
        __pyx_L7_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1653, __pyx_L1_error)
        __pyx_L8_unpacking_done:;
      }
      __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1653, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_6 = __Pyx_PyInt_As_uint32_t(__pyx_t_10); if (unlikely((__pyx_t_6 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1653, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_v_op = __pyx_t_13;
      __pyx_v_nt = __pyx_t_6;

      /* "pysam/libcalignmentfile.pyx":1654
 * 
 *             for op, nt in r.cigartuples:
 *                 if op in match_or_deletion:             # <<<<<<<<<<<<<<
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1654, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_14 = (__Pyx_PySet_ContainsTF(__pyx_t_3, __pyx_v_match_or_deletion, Py_EQ)); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1654, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_15 = (__pyx_t_14 != 0);
      if (__pyx_t_15) {

        /* "pysam/libcalignmentfile.pyx":1655
 *             for op, nt in r.cigartuples:
 *                 if op in match_or_deletion:
 *                     base_position += nt             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CREF_SKIP:
 *                     junc_start = base_position
 */
        __pyx_v_base_position = (__pyx_v_base_position + __pyx_v_nt);

        /* "pysam/libcalignmentfile.pyx":1654
 * 
 *             for op, nt in r.cigartuples:
 *                 if op in match_or_deletion:             # <<<<<<<<<<<<<<
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:
 */
        goto __pyx_L9;
      }

      /* "pysam/libcalignmentfile.pyx":1656
 *                 if op in match_or_deletion:
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     junc_start = base_position
 *                     base_position += nt
 */
      __pyx_t_15 = ((__pyx_v_op == __pyx_v_BAM_CREF_SKIP) != 0);
      if (__pyx_t_15) {

        /* "pysam/libcalignmentfile.pyx":1657
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:
 *                     junc_start = base_position             # <<<<<<<<<<<<<<
 *                     base_position += nt
 *                     res[(junc_start, base_position)] += 1
 */
        __pyx_v_junc_start = __pyx_v_base_position;

        /* "pysam/libcalignmentfile.pyx":1658
 *                 elif op == BAM_CREF_SKIP:
 *                     junc_start = base_position
 *                     base_position += nt             # <<<<<<<<<<<<<<
 *                     res[(junc_start, base_position)] += 1
 *         return res
 */
        __pyx_v_base_position = (__pyx_v_base_position + __pyx_v_nt);

        /* "pysam/libcalignmentfile.pyx":1659
 *                     junc_start = base_position
 *                     base_position += nt
 *                     res[(junc_start, base_position)] += 1             # <<<<<<<<<<<<<<
 *         return res
 * 
 */
        __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_junc_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_base_position); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10);
        __pyx_t_3 = 0;
        __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_10, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(PyObject_SetItem(__pyx_v_res, __pyx_t_9, __pyx_t_3) < 0)) __PYX_ERR(0, 1659, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pysam/libcalignmentfile.pyx":1656
 *                 if op in match_or_deletion:
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     junc_start = base_position
 *                     base_position += nt
 */
      }
      __pyx_L9:;

      /* "pysam/libcalignmentfile.pyx":1653
 *             base_position = r.pos
 * 
 *             for op, nt in r.cigartuples:             # <<<<<<<<<<<<<<
 *                 if op in match_or_deletion:
 *                     base_position += nt
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":1650
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             base_position = r.pos
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1660
 *                     base_position += nt
 *                     res[(junc_start, base_position)] += 1
 *         return res             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_res);
  __pyx_r = __pyx_v_res;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1632
 *         return res
 * 
 *     def find_introns(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

  /* 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_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_r);
  __Pyx_XDECREF(__pyx_v_res);
  __Pyx_XDECREF(__pyx_v_match_or_deletion);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1663
 * 
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close[] = "AlignmentFile.close(self)\ncloses the :class:`pysam.AlignmentFile`.";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  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_RefNannySetupContext("close", 0);
  __Pyx_TraceCall("close", __pyx_f[0], 1663, 0, __PYX_ERR(0, 1663, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1666
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 *         if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1667
 * 
 *         if self.htsfile == NULL:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret = hts_close(self.htsfile)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1666
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 *         if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1669
 *             return
 * 
 *         cdef int ret = hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 * 
 */
  __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile);

  /* "pysam/libcalignmentfile.pyx":1670
 * 
 *         cdef int ret = hts_close(self.htsfile)
 *         self.htsfile = NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.index != NULL:
 */
  __pyx_v_self->__pyx_base.htsfile = NULL;

  /* "pysam/libcalignmentfile.pyx":1672
 *         self.htsfile = NULL
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->index != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1673
 * 
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)             # <<<<<<<<<<<<<<
 *             self.index = NULL
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/libcalignmentfile.pyx":1674
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)
 *             self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *         self.header = None
 */
    __pyx_v_self->index = NULL;

    /* "pysam/libcalignmentfile.pyx":1672
 *         self.htsfile = NULL
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1676
 *             self.index = NULL
 * 
 *         self.header = None             # <<<<<<<<<<<<<<
 * 
 *         if ret < 0:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->header);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
  __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None);

  /* "pysam/libcalignmentfile.pyx":1678
 *         self.header = None
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  __pyx_t_1 = ((__pyx_v_ret < 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1680
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
    __pyx_t_1 = ((errno == EPIPE) != 0);
    if (likely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":1681
 *             global errno
 *             if errno == EPIPE:
 *                 errno = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))
 */
      errno = 0;

      /* "pysam/libcalignmentfile.pyx":1680
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
      goto __pyx_L6;
    }

    /* "pysam/libcalignmentfile.pyx":1683
 *                 errno = 0
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1683, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1683, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1683, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1683, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
      __pyx_t_2 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1683, __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_ERR(0, 1683, __pyx_L1_error)
    }
    __pyx_L6:;

    /* "pysam/libcalignmentfile.pyx":1678
 *         self.header = None
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1663
 * 
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 */

  /* 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.libcalignmentfile.AlignmentFile.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1685
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = 0
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  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_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1685, 0, __PYX_ERR(0, 1685, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1686
 * 
 *     def __dealloc__(self):
 *         cdef int ret = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.htsfile != NULL:
 */
  __pyx_v_ret = 0;

  /* "pysam/libcalignmentfile.pyx":1688
 *         cdef int ret = 0
 * 
 *         if self.htsfile != NULL:             # <<<<<<<<<<<<<<
 *             ret = hts_close(self.htsfile)
 *             self.htsfile = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1689
 * 
 *         if self.htsfile != NULL:
 *             ret = hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *             self.htsfile = NULL
 * 
 */
    __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile);

    /* "pysam/libcalignmentfile.pyx":1690
 *         if self.htsfile != NULL:
 *             ret = hts_close(self.htsfile)
 *             self.htsfile = NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.index != NULL:
 */
    __pyx_v_self->__pyx_base.htsfile = NULL;

    /* "pysam/libcalignmentfile.pyx":1688
 *         cdef int ret = 0
 * 
 *         if self.htsfile != NULL:             # <<<<<<<<<<<<<<
 *             ret = hts_close(self.htsfile)
 *             self.htsfile = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1692
 *             self.htsfile = NULL
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  __pyx_t_1 = ((__pyx_v_self->index != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1693
 * 
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)             # <<<<<<<<<<<<<<
 *             self.index = NULL
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/libcalignmentfile.pyx":1694
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)
 *             self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *         self.header = None
 */
    __pyx_v_self->index = NULL;

    /* "pysam/libcalignmentfile.pyx":1692
 *             self.htsfile = NULL
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1696
 *             self.index = NULL
 * 
 *         self.header = None             # <<<<<<<<<<<<<<
 * 
 *         if self.b:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->header);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
  __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None);

  /* "pysam/libcalignmentfile.pyx":1698
 *         self.header = None
 * 
 *         if self.b:             # <<<<<<<<<<<<<<
 *             bam_destroy1(self.b)
 *             self.b = NULL
 */
  __pyx_t_1 = (__pyx_v_self->b != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1699
 * 
 *         if self.b:
 *             bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *             self.b = NULL
 * 
 */
    bam_destroy1(__pyx_v_self->b);

    /* "pysam/libcalignmentfile.pyx":1700
 *         if self.b:
 *             bam_destroy1(self.b)
 *             self.b = NULL             # <<<<<<<<<<<<<<
 * 
 *         if ret < 0:
 */
    __pyx_v_self->b = NULL;

    /* "pysam/libcalignmentfile.pyx":1698
 *         self.header = None
 * 
 *         if self.b:             # <<<<<<<<<<<<<<
 *             bam_destroy1(self.b)
 *             self.b = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1702
 *             self.b = NULL
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  __pyx_t_1 = ((__pyx_v_ret < 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1704
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
    __pyx_t_1 = ((errno == EPIPE) != 0);
    if (likely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":1705
 *             global errno
 *             if errno == EPIPE:
 *                 errno = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))
 */
      errno = 0;

      /* "pysam/libcalignmentfile.pyx":1704
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
      goto __pyx_L7;
    }

    /* "pysam/libcalignmentfile.pyx":1707
 *                 errno = 0
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))             # <<<<<<<<<<<<<<
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1707, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1707, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1707, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1707, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
      __pyx_t_2 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1707, __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_ERR(0, 1707, __pyx_L1_error)
    }
    __pyx_L7:;

    /* "pysam/libcalignmentfile.pyx":1702
 *             self.b = NULL
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1685
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = 0
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/libcalignmentfile.pyx":1709
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedSegment` to disk.
 */

static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch) {
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write", 0);
  __Pyx_TraceCall("write", __pyx_f[0], 1709, 0, __PYX_ERR(0, 1709, __pyx_L1_error));
  /* 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) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1709, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write)) {
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, ((PyObject *)__pyx_v_read)) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_read));
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1709, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1709, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_5;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "pysam/libcalignmentfile.pyx":1722
 *                 this will be 0.
 *         '''
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1722, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1722, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_7 = ((!__pyx_t_6) != 0);
  if (__pyx_t_7) {

    /* "pysam/libcalignmentfile.pyx":1723
 *         '''
 *         if not self.is_open:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1722
 *                 this will be 0.
 *         '''
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1725
 *             return 0
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "AlignedSegment refers to reference number {} that "
 */
  __pyx_t_7 = ((__pyx_v_self->header->ptr->n_targets <= __pyx_v_read->_delegate->core.tid) != 0);
  if (unlikely(__pyx_t_7)) {

    /* "pysam/libcalignmentfile.pyx":1728
 *             raise ValueError(
 *                 "AlignedSegment refers to reference number {} that "
 *                 "is larger than the number of references ({}) in the header".format(             # <<<<<<<<<<<<<<
 *                     read._delegate.core.tid, self.header.ptr.n_targets))
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_AlignedSegment_refers_to_referen, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1728, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pysam/libcalignmentfile.pyx":1729
 *                 "AlignedSegment refers to reference number {} that "
 *                 "is larger than the number of references ({}) in the header".format(
 *                     read._delegate.core.tid, self.header.ptr.n_targets))             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret
 */
    __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->ptr->n_targets); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = NULL;
    __pyx_t_5 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_5 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_3, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1728, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_3, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1728, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1728, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_8) {
        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_5, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_5, __pyx_t_4);
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1728, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":1726
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "AlignedSegment refers to reference number {} that "
 *                 "is larger than the number of references ({}) in the header".format(
 */
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1726, __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_ERR(0, 1726, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1725
 *             return 0
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "AlignedSegment refers to reference number {} that "
 */
  }

  /* "pysam/libcalignmentfile.pyx":1732
 * 
 *         cdef int ret
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_write1(self.htsfile,
 *                              self.header.ptr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":1733
 *         cdef int ret
 *         with nogil:
 *             ret = sam_write1(self.htsfile,             # <<<<<<<<<<<<<<
 *                              self.header.ptr,
 *                              read._delegate)
 */
        __pyx_v_ret = sam_write1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr, __pyx_v_read->_delegate);
      }

      /* "pysam/libcalignmentfile.pyx":1732
 * 
 *         cdef int ret
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_write1(self.htsfile,
 *                              self.header.ptr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L7;
        }
        __pyx_L7:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":1740
 *         #      when ret == -1 we get a "SystemError: error return without
 *         #      exception set".
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             raise IOError(
 *             "sam_write1 failed with error code {}".format(ret))
 */
  __pyx_t_7 = ((__pyx_v_ret < 0) != 0);
  if (unlikely(__pyx_t_7)) {

    /* "pysam/libcalignmentfile.pyx":1742
 *         if ret < 0:
 *             raise IOError(
 *             "sam_write1 failed with error code {}".format(ret))             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_sam_write1_failed_with_error_cod, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1742, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1742, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1742, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1741
 *         #      exception set".
 *         if ret < 0:
 *             raise IOError(             # <<<<<<<<<<<<<<
 *             "sam_write1 failed with error code {}".format(ret))
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1741, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1740
 *         #      when ret == -1 we get a "SystemError: error return without
 *         #      exception set".
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             raise IOError(
 *             "sam_write1 failed with error code {}".format(ret))
 */
  }

  /* "pysam/libcalignmentfile.pyx":1744
 *             "sam_write1 failed with error code {}".format(ret))
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     # context manager interface
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1709
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedSegment` to disk.
 */

  /* 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_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28write[] = "AlignmentFile.write(self, AlignedSegment read) -> int\n\n        write a single :class:`pysam.AlignedSegment` to disk.\n\n        Raises:\n            ValueError\n                if the writing failed\n\n        Returns:\n            int :\n                the number of bytes written. If the file is closed,\n                this will be 0.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  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_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1709, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__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_17libcalignmentfile_13AlignmentFile_28write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("write", 0);
  __Pyx_TraceCall("write (wrapper)", __pyx_f[0], 1709, 0, __PYX_ERR(0, 1709, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(__pyx_v_self, __pyx_v_read, 1); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1709, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1709, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

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

/* "pysam/libcalignmentfile.pyx":1747
 * 
 *     # context manager interface
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__[] = "AlignmentFile.__enter__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__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_17libcalignmentfile_13AlignmentFile_30__enter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__enter__", 0);
  __Pyx_TraceCall("__enter__", __pyx_f[0], 1747, 0, __PYX_ERR(0, 1747, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1748
 *     # context manager interface
 *     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/libcalignmentfile.pyx":1747
 * 
 *     # context manager interface
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__[] = "AlignmentFile.__exit__(self, exc_type, exc_value, traceback)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 1750, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 1750, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 1750, __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_ERR(0, 1750, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__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_17libcalignmentfile_13AlignmentFile_32__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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_TraceDeclarations
  __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_RefNannySetupContext("__exit__", 0);
  __Pyx_TraceCall("__exit__", __pyx_f[0], 1750, 0, __PYX_ERR(0, 1750, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1751
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()             # <<<<<<<<<<<<<<
 *         return False
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1752
 *     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/libcalignmentfile.pyx":1750
 *         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_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1766
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1766, 0, __PYX_ERR(0, 1766, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1767
 *         """
 *         def __get__(self):
 *             self.check_index()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = 0
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1767, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1767, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1769
 *             self.check_index()
 *             cdef int tid
 *             cdef uint64_t total = 0             # <<<<<<<<<<<<<<
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 */
  __pyx_v_total = 0;

  /* "pysam/libcalignmentfile.pyx":1771
 *             cdef uint64_t total = 0
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) {

    /* "pysam/libcalignmentfile.pyx":1772
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":1773
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *                 total += mapped
 *             return total
 */
          (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped)));
        }

        /* "pysam/libcalignmentfile.pyx":1772
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":1774
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped             # <<<<<<<<<<<<<<
 *             return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + __pyx_v_mapped);
  }

  /* "pysam/libcalignmentfile.pyx":1775
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 *             return total             # <<<<<<<<<<<<<<
 * 
 *     property unmapped:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1766
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

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

/* "pysam/libcalignmentfile.pyx":1784
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1784, 0, __PYX_ERR(0, 1784, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1785
 *         """
 *         def __get__(self):
 *             self.check_index()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = hts_idx_get_n_no_coor(self.index)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1785, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1785, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1787
 *             self.check_index()
 *             cdef int tid
 *             cdef uint64_t total = hts_idx_get_n_no_coor(self.index)             # <<<<<<<<<<<<<<
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 */
  __pyx_v_total = hts_idx_get_n_no_coor(__pyx_v_self->index);

  /* "pysam/libcalignmentfile.pyx":1789
 *             cdef uint64_t total = hts_idx_get_n_no_coor(self.index)
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1789, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1789, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) {

    /* "pysam/libcalignmentfile.pyx":1790
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":1791
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *                 total += unmapped
 *             return total
 */
          (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped)));
        }

        /* "pysam/libcalignmentfile.pyx":1790
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":1792
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped             # <<<<<<<<<<<<<<
 *             return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + __pyx_v_unmapped);
  }

  /* "pysam/libcalignmentfile.pyx":1793
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 *             return total             # <<<<<<<<<<<<<<
 * 
 *     property nocoordinate:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1793, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1784
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

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

/* "pysam/libcalignmentfile.pyx":1802
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef uint64_t n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  uint64_t __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1802, 0, __PYX_ERR(0, 1802, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1803
 *         """
 *         def __get__(self):
 *             self.check_index()             # <<<<<<<<<<<<<<
 *             cdef uint64_t n
 *             with nogil:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1805
 *             self.check_index()
 *             cdef uint64_t n
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 n = hts_idx_get_n_no_coor(self.index)
 *             return n
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":1806
 *             cdef uint64_t n
 *             with nogil:
 *                 n = hts_idx_get_n_no_coor(self.index)             # <<<<<<<<<<<<<<
 *             return n
 * 
 */
        __pyx_v_n = hts_idx_get_n_no_coor(__pyx_v_self->index);
      }

      /* "pysam/libcalignmentfile.pyx":1805
 *             self.check_index()
 *             cdef uint64_t n
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 n = hts_idx_get_n_no_coor(self.index)
 *             return n
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":1807
 *             with nogil:
 *                 n = hts_idx_get_n_no_coor(self.index)
 *             return n             # <<<<<<<<<<<<<<
 * 
 *     def get_index_statistics(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1807, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1802
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef uint64_t n
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nocoordinate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1809
 *             return n
 * 
 *     def get_index_statistics(self):             # <<<<<<<<<<<<<<
 *         """return statistics about mapped/unmapped reads per chromosome as
 *         they are stored in the index, similarly to the statistics printed
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics[] = "AlignmentFile.get_index_statistics(self)\nreturn statistics about mapped/unmapped reads per chromosome as\n        they are stored in the index, similarly to the statistics printed\n        by the ``samtools idxstats`` command.\n\n        CRAI indexes do not record these statistics, so for a CRAM file\n        with a .crai index the returned statistics will all be 0.\n\n        Returns:\n            list :\n                a list of records for each chromosome. Each record has the\n                attributes 'contig', 'mapped', 'unmapped' and 'total'.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_index_statistics (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_tid;
  uint64_t __pyx_v_mapped;
  uint64_t __pyx_v_unmapped;
  PyObject *__pyx_v_results = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_index_statistics", 0);
  __Pyx_TraceCall("get_index_statistics", __pyx_f[0], 1809, 0, __PYX_ERR(0, 1809, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1823
 *         """
 * 
 *         self.check_index()             # <<<<<<<<<<<<<<
 *         cdef int tid
 *         cdef uint64_t mapped, unmapped
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1823, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1823, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1826
 *         cdef int tid
 *         cdef uint64_t mapped, unmapped
 *         results = []             # <<<<<<<<<<<<<<
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1826, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_results = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1828
 *         results = []
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1828, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) {

    /* "pysam/libcalignmentfile.pyx":1829
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":1830
 *         for tid from 0 <= tid < self.nreferences:
 *             with nogil:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *             results.append(
 *                 IndexStats._make((
 */
          (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped)));
        }

        /* "pysam/libcalignmentfile.pyx":1829
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":1832
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(
 *                 IndexStats._make((             # <<<<<<<<<<<<<<
 *                     self.get_reference_name(tid),
 *                     mapped,
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_IndexStats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_make); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":1833
 *             results.append(
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),             # <<<<<<<<<<<<<<
 *                     mapped,
 *                     unmapped,
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1833, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1833, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1833, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":1834
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),
 *                     mapped,             # <<<<<<<<<<<<<<
 *                     unmapped,
 *                     mapped + unmapped)))
 */
    __pyx_t_5 = __Pyx_PyInt_From_uint64_t(__pyx_v_mapped); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1834, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "pysam/libcalignmentfile.pyx":1835
 *                     self.get_reference_name(tid),
 *                     mapped,
 *                     unmapped,             # <<<<<<<<<<<<<<
 *                     mapped + unmapped)))
 * 
 */
    __pyx_t_6 = __Pyx_PyInt_From_uint64_t(__pyx_v_unmapped); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1835, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "pysam/libcalignmentfile.pyx":1836
 *                     mapped,
 *                     unmapped,
 *                     mapped + unmapped)))             # <<<<<<<<<<<<<<
 * 
 *         return results
 */
    __pyx_t_7 = __Pyx_PyInt_From_uint64_t((__pyx_v_mapped + __pyx_v_unmapped)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1836, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);

    /* "pysam/libcalignmentfile.pyx":1833
 *             results.append(
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),             # <<<<<<<<<<<<<<
 *                     mapped,
 *                     unmapped,
 */
    __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1833, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_7);
    __pyx_t_2 = 0;
    __pyx_t_5 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1831
 *             with nogil:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(             # <<<<<<<<<<<<<<
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),
 */
    __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_1); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 1831, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":1838
 *                     mapped + unmapped)))
 * 
 *         return results             # <<<<<<<<<<<<<<
 * 
 *     ###############################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_results);
  __pyx_r = __pyx_v_results;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1809
 *             return n
 * 
 *     def get_index_statistics(self):             # <<<<<<<<<<<<<<
 *         """return statistics about mapped/unmapped reads per chromosome as
 *         they are stored in the index, similarly to the statistics printed
 */

  /* 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_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_index_statistics", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1845
 *     ## and multiple_iterators)
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  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_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1845, 0, __PYX_ERR(0, 1845, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1846
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1846, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1846, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1847
 *     def __iter__(self):
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         if not self.is_bam and self.header.nreferences == 0:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1847, __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_ERR(0, 1847, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1846
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1849
 *             raise ValueError("I/O operation on closed file")
 * 
 *         if not self.is_bam and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1849, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1849, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = ((!__pyx_t_2) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1849, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1849, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1849, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __pyx_t_4;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1850
 * 
 *         if not self.is_bam and self.header.nreferences == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1850, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 1850, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1849
 *             raise ValueError("I/O operation on closed file")
 * 
 *         if not self.is_bam and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 */
  }

  /* "pysam/libcalignmentfile.pyx":1852
 *             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/libcalignmentfile.pyx":1845
 *     ## and multiple_iterators)
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 */

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

/* "pysam/libcalignmentfile.pyx":1854
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1854, 0, __PYX_ERR(0, 1854, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1855
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1854
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1857
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 */

static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam_hdr_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1857, 0, __PYX_ERR(0, 1857, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1862
 *         '''
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_1 = __pyx_v_self->header->ptr;
  __pyx_v_hdr = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":1863
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":1864
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->b);
      }

      /* "pysam/libcalignmentfile.pyx":1863
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":1867
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1857
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1869
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  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_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1869, 0, __PYX_ERR(0, 1869, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1870
 * 
 *     def __next__(self):
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/libcalignmentfile.pyx":1871
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1872
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = ((PyObject *)__pyx_v_self->header);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1872, __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;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1871
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1873
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -1L) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1874
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 1874, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1873
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1876
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 *     ###########################################
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1876, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1869
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

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

/* "pysam/libcalignmentfile.pyx":1880
 *     ###########################################
 *     # methods/properties referencing the header
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid[] = "AlignmentFile.is_valid_tid(self, int tid)\n\n        return True if the numerical :term:`tid` is valid; False otherwise.\n\n        Note that the unmapped tid code (-1) counts as an invalid.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid) {
  int __pyx_v_tid;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0);
  assert(__pyx_arg_tid); {
    __pyx_v_tid = __Pyx_PyInt_As_int(__pyx_arg_tid); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1880, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((int)__pyx_v_tid));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_valid_tid", 0);
  __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 1880, 0, __PYX_ERR(0, 1880, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1886
 *         Note that the unmapped tid code (-1) counts as an invalid.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.is_valid_tid(tid)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1887
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.is_valid_tid(tid)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1887, __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_ERR(0, 1887, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1886
 *         Note that the unmapped tid code (-1) counts as an invalid.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.is_valid_tid(tid)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1888
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.is_valid_tid(tid)             # <<<<<<<<<<<<<<
 * 
 *     def get_tid(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_is_valid_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1880
 *     ###########################################
 *     # methods/properties referencing the header
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

  /* 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.libcalignmentfile.AlignmentFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1890
 *         return self.header.is_valid_tid(tid)
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid[] = "AlignmentFile.get_tid(self, reference)\n\n        return the numerical :term:`tid` corresponding to\n        :term:`reference`\n\n        returns -1 if reference is not known.\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tid (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("get_tid", 0);
  __Pyx_TraceCall("get_tid", __pyx_f[0], 1890, 0, __PYX_ERR(0, 1890, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1897
 *         returns -1 if reference is not known.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_tid(reference)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1898
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.get_tid(reference)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1898, __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_ERR(0, 1898, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1897
 *         returns -1 if reference is not known.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_tid(reference)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1899
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_tid(reference)             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_name(self, tid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_reference) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_reference);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1890
 *         return self.header.is_valid_tid(tid)
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

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

/* "pysam/libcalignmentfile.pyx":1901
 *         return self.header.get_tid(reference)
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name[] = "AlignmentFile.get_reference_name(self, tid)\n\n        return :term:`reference` name corresponding to numerical :term:`tid`\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("get_reference_name", 0);
  __Pyx_TraceCall("get_reference_name", __pyx_f[0], 1901, 0, __PYX_ERR(0, 1901, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1905
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_name(tid)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1906
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.get_reference_name(tid)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1906, __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_ERR(0, 1906, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1905
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_name(tid)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1907
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_name(tid)             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_length(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1907, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_tid) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_tid);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1907, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1901
 *         return self.header.get_tid(reference)
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 */

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

/* "pysam/libcalignmentfile.pyx":1909
 *         return self.header.get_reference_name(tid)
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length[] = "AlignmentFile.get_reference_length(self, reference)\n\n        return :term:`reference` length corresponding to numerical :term:`tid`\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("get_reference_length", 0);
  __Pyx_TraceCall("get_reference_length", __pyx_f[0], 1909, 0, __PYX_ERR(0, 1909, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1913
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_length(reference)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1914
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.get_reference_length(reference)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1914, __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_ERR(0, 1914, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1913
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_length(reference)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1915
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_length(reference)             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1915, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_reference) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_reference);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1915, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1909
 *         return self.header.get_reference_name(tid)
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 */

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

/* "pysam/libcalignmentfile.pyx":1920
 *         """int with the number of :term:`reference` sequences in the file.
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.nreferences
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1920, 0, __PYX_ERR(0, 1920, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1921
 *         This is a read-only attribute."""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.nreferences
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1921, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1922
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.nreferences             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1921
 *         This is a read-only attribute."""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.nreferences
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1924
 *                 return self.header.nreferences
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1924, __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_ERR(0, 1924, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1920
 *         """int with the number of :term:`reference` sequences in the file.
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.nreferences
 */

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

/* "pysam/libcalignmentfile.pyx":1929
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.references
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1929, 0, __PYX_ERR(0, 1929, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1930
 *         read-only attribute"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.references
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1930, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1931
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.references             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1931, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1930
 *         read-only attribute"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.references
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1933
 *                 return self.header.references
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __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_ERR(0, 1933, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1929
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.references
 */

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

/* "pysam/libcalignmentfile.pyx":1941
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.lengths
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1941, 0, __PYX_ERR(0, 1941, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1942
 *         """
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.lengths
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1942, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1943
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.lengths             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_lengths); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1943, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1942
 *         """
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.lengths
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1945
 *                 return self.header.lengths
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     # Compatibility functions for pysam < 0.14
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1945, __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_ERR(0, 1945, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1941
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.lengths
 */

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

/* "pysam/libcalignmentfile.pyx":1950
 *     property text:
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.__str__()
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  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_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1950, 0, __PYX_ERR(0, 1950, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1951
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.__str__()
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1951, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1952
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.__str__()             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1952, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1951
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.__str__()
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1954
 *                 return self.header.__str__()
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     # Compatibility functions for pysam < 0.8.3
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1954, __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_ERR(0, 1954, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1950
 *     property text:
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.__str__()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1957
 * 
 *     # Compatibility functions for pysam < 0.8.3
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid[] = "AlignmentFile.gettid(self, reference)\ndeprecated, use :meth:`get_tid` instead";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gettid (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("gettid", 0);
  __Pyx_TraceCall("gettid", __pyx_f[0], 1957, 0, __PYX_ERR(0, 1957, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1959
 *     def gettid(self, reference):
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)             # <<<<<<<<<<<<<<
 * 
 *     def getrname(self, tid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1959, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_reference) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1959, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1957
 * 
 *     # Compatibility functions for pysam < 0.8.3
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)
 */

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

/* "pysam/libcalignmentfile.pyx":1961
 *         return self.get_tid(reference)
 * 
 *     def getrname(self, tid):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname[] = "AlignmentFile.getrname(self, tid)\ndeprecated, use :meth:`get_reference_name` instead";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getrname (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("getrname", 0);
  __Pyx_TraceCall("getrname", __pyx_f[0], 1961, 0, __PYX_ERR(0, 1961, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1963
 *     def getrname(self, tid):
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_tid) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tid);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1961
 *         return self.get_tid(reference)
 * 
 *     def getrname(self, tid):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)
 */

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

/* "pysam/libcalignmentfile.pxd":45
 * 
 * cdef class AlignmentFile(HTSFile):
 *     cdef readonly object reference_filename             # <<<<<<<<<<<<<<
 *     cdef readonly AlignmentHeader header
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[2], 45, 0, __PYX_ERR(2, 45, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->reference_filename);
  __pyx_r = __pyx_v_self->reference_filename;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.reference_filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pxd":46
 * cdef class AlignmentFile(HTSFile):
 *     cdef readonly object reference_filename
 *     cdef readonly AlignmentHeader header             # <<<<<<<<<<<<<<
 * 
 *     # pointer to index
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[2], 46, 0, __PYX_ERR(2, 46, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->header));
  __pyx_r = ((PyObject *)__pyx_v_self->header);
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__[] = "AlignmentFile.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__[] = "AlignmentFile.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

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

/* "pysam/libcalignmentfile.pyx":1991
 *     '''
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 *         cdef char *creference_filename
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_multiple_iterators;
  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_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 1991, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1991, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1991, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1991, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

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

static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  char *__pyx_v_cfilename;
  char *__pyx_v_creference_filename;
  char *__pyx_v_cindexname;
  CYTHON_UNUSED PyObject *__pyx_v_bindex_filename = NULL;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  char *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  htsFile *__pyx_t_7;
  hts_idx_t *__pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1991, 0, __PYX_ERR(0, 1991, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1994
 *         cdef char *cfilename
 *         cdef char *creference_filename
 *         cdef char *cindexname = NULL             # <<<<<<<<<<<<<<
 * 
 *         if not samfile.is_open:
 */
  __pyx_v_cindexname = NULL;

  /* "pysam/libcalignmentfile.pyx":1996
 *         cdef char *cindexname = NULL
 * 
 *         if not samfile.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1996, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1997
 * 
 *         if not samfile.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as the
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1997, __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_ERR(0, 1997, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1996
 *         cdef char *cindexname = NULL
 * 
 *         if not samfile.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2001
 *         # 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/libcalignmentfile.pyx":2005
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 * 
 *             cfilename = samfile.filename
 */
  __pyx_t_3 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":2007
 *         if multiple_iterators:
 * 
 *             cfilename = samfile.filename             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 */
    __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2007, __pyx_L1_error)
    __pyx_v_cfilename = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":2008
 * 
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             assert self.htsfile != NULL
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2009
 *             cfilename = samfile.filename
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')             # <<<<<<<<<<<<<<
 *             assert self.htsfile != NULL
 * 
 */
          __pyx_v_self->htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r"));
        }

        /* "pysam/libcalignmentfile.pyx":2008
 * 
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             assert self.htsfile != NULL
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L7;
          }
          __pyx_L7:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2010
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             assert self.htsfile != NULL             # <<<<<<<<<<<<<<
 * 
 *             if samfile.has_index():
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        __PYX_ERR(0, 2010, __pyx_L1_error)
      }
    }
    #endif

    /* "pysam/libcalignmentfile.pyx":2012
 *             assert self.htsfile != NULL
 * 
 *             if samfile.has_index():             # <<<<<<<<<<<<<<
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2012, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":2013
 * 
 *             if samfile.has_index():
 *                 if samfile.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:
 */
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->__pyx_base.index_filename); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2013, __pyx_L1_error)
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":2014
 *             if samfile.has_index():
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 */
        __pyx_t_1 = __pyx_v_samfile->__pyx_base.index_filename;
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(__pyx_t_5 == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
          __PYX_ERR(0, 2014, __pyx_L1_error)
        }
        __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_t_5); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2014, __pyx_L1_error)
        __pyx_v_cindexname = __pyx_t_4;
        __Pyx_INCREF(__pyx_t_5);
        __pyx_v_bindex_filename = ((PyObject*)__pyx_t_5);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pysam/libcalignmentfile.pyx":2013
 * 
 *             if samfile.has_index():
 *                 if samfile.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:
 */
      }

      /* "pysam/libcalignmentfile.pyx":2015
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 *             else:
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":2016
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)             # <<<<<<<<<<<<<<
 *             else:
 *                 self.index = NULL
 */
            __pyx_v_self->index = sam_index_load2(__pyx_v_self->htsfile, __pyx_v_cfilename, __pyx_v_cindexname);
          }

          /* "pysam/libcalignmentfile.pyx":2015
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 *             else:
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L12;
            }
            __pyx_L12:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":2012
 *             assert self.htsfile != NULL
 * 
 *             if samfile.has_index():             # <<<<<<<<<<<<<<
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 */
      goto __pyx_L8;
    }

    /* "pysam/libcalignmentfile.pyx":2018
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 *             else:
 *                 self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *             # need to advance in newly opened file to position after header
 */
    /*else*/ {
      __pyx_v_self->index = NULL;
    }
    __pyx_L8:;

    /* "pysam/libcalignmentfile.pyx":2022
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2023
 *             # better: use seek/tell?
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")
 */
          __pyx_v_hdr = sam_hdr_read(__pyx_v_self->htsfile);
        }

        /* "pysam/libcalignmentfile.pyx":2022
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L15;
          }
          __pyx_L15:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2024
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:             # <<<<<<<<<<<<<<
 *                 raise IOError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    __pyx_t_3 = ((__pyx_v_hdr == NULL) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":2025
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")             # <<<<<<<<<<<<<<
 *             self.header = makeAlignmentHeader(hdr)
 * 
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2025, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 2025, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2024
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:             # <<<<<<<<<<<<<<
 *                 raise IOError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    }

    /* "pysam/libcalignmentfile.pyx":2026
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 * 
 *             self.owns_samfile = True
 */
    __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2026, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->header);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":2028
 *             self.header = makeAlignmentHeader(hdr)
 * 
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 * 
 *             # options specific to CRAM files
 */
    __pyx_v_self->owns_samfile = 1;

    /* "pysam/libcalignmentfile.pyx":2031
 * 
 *             # options specific to CRAM files
 *             if samfile.is_cram and samfile.reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = samfile.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2031, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_2) {
    } else {
      __pyx_t_3 = __pyx_t_2;
      goto __pyx_L18_bool_binop_done;
    }
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->reference_filename); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2031, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_2;
    __pyx_L18_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":2032
 *             # options specific to CRAM files
 *             if samfile.is_cram and samfile.reference_filename:
 *                 creference_filename = samfile.reference_filename             # <<<<<<<<<<<<<<
 *                 hts_set_opt(self.htsfile,
 *                             CRAM_OPT_REFERENCE,
 */
      __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->reference_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2032, __pyx_L1_error)
      __pyx_v_creference_filename = __pyx_t_4;

      /* "pysam/libcalignmentfile.pyx":2033
 *             if samfile.is_cram and samfile.reference_filename:
 *                 creference_filename = samfile.reference_filename
 *                 hts_set_opt(self.htsfile,             # <<<<<<<<<<<<<<
 *                             CRAM_OPT_REFERENCE,
 *                             creference_filename)
 */
      (void)(hts_set_opt(__pyx_v_self->htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename));

      /* "pysam/libcalignmentfile.pyx":2031
 * 
 *             # options specific to CRAM files
 *             if samfile.is_cram and samfile.reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = samfile.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    }

    /* "pysam/libcalignmentfile.pyx":2005
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 * 
 *             cfilename = samfile.filename
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2038
 * 
 *         else:
 *             self.htsfile = samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.index = samfile.index
 *             self.owns_samfile = False
 */
  /*else*/ {
    __pyx_t_7 = __pyx_v_samfile->__pyx_base.htsfile;
    __pyx_v_self->htsfile = __pyx_t_7;

    /* "pysam/libcalignmentfile.pyx":2039
 *         else:
 *             self.htsfile = samfile.htsfile
 *             self.index = samfile.index             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 *             self.header = samfile.header
 */
    __pyx_t_8 = __pyx_v_samfile->index;
    __pyx_v_self->index = __pyx_t_8;

    /* "pysam/libcalignmentfile.pyx":2040
 *             self.htsfile = samfile.htsfile
 *             self.index = samfile.index
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 *             self.header = samfile.header
 * 
 */
    __pyx_v_self->owns_samfile = 0;

    /* "pysam/libcalignmentfile.pyx":2041
 *             self.index = samfile.index
 *             self.owns_samfile = False
 *             self.header = samfile.header             # <<<<<<<<<<<<<<
 * 
 *         self.retval = 0
 */
    __pyx_t_5 = ((PyObject *)__pyx_v_samfile->header);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->header);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
    __pyx_t_5 = 0;
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":2043
 *             self.header = samfile.header
 * 
 *         self.retval = 0             # <<<<<<<<<<<<<<
 * 
 *         self.b = bam_init1()
 */
  __pyx_v_self->retval = 0;

  /* "pysam/libcalignmentfile.pyx":2045
 *         self.retval = 0
 * 
 *         self.b = bam_init1()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->b = bam_init1();

  /* "pysam/libcalignmentfile.pyx":1991
 *     '''
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 *         cdef char *creference_filename
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_bindex_filename);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2047
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self));

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

static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2047, 0, __PYX_ERR(0, 2047, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2048
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */
  bam_destroy1(__pyx_v_self->b);

  /* "pysam/libcalignmentfile.pyx":2049
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 *             hts_idx_destroy(self.index)
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2050
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 * 
 */
    (void)(hts_close(__pyx_v_self->htsfile));

    /* "pysam/libcalignmentfile.pyx":2051
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 *             hts_idx_destroy(self.index)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/libcalignmentfile.pyx":2049
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 *             hts_idx_destroy(self.index)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2047
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRow.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__[] = "IteratorRow.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__[] = "IteratorRow.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

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

/* "pysam/libcalignmentfile.pyx":2068
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_beg;
  int __pyx_v_stop;
  int __pyx_v_multiple_iterators;
  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_stop,&__pyx_n_s_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); __PYX_ERR(0, 2068, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_beg)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); __PYX_ERR(0, 2068, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); __PYX_ERR(0, 2068, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 2068, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        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_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2069, __pyx_L3_error)
    __pyx_v_beg = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2069, __pyx_L3_error)
    __pyx_v_stop = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_stop == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2069, __pyx_L3_error)
    if (values[4]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2070, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2070
 *     def __init__(self, AlignmentFile samfile,
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile.has_index():
 */
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2068, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2068, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_stop, __pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":2068
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):
 */

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

static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_stop, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2068, 0, __PYX_ERR(0, 2068, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2072
 *                  int multiple_iterators=False):
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for iteration")
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2072, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2072, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2072, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (unlikely(__pyx_t_5)) {

    /* "pysam/libcalignmentfile.pyx":2073
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for iteration")             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile,
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2073, __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_ERR(0, 2073, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2072
 *                  int multiple_iterators=False):
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for iteration")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2075
 *             raise ValueError("no index available for iteration")
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 *         with nogil:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));

  /* "pysam/libcalignmentfile.pyx":2076
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *         with nogil:
 *             self.iter = sam_itr_queryi(
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2076, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2076, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_6) < 0) __PYX_ERR(0, 2076, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/libcalignmentfile.pyx":2075
 *             raise ValueError("no index available for iteration")
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 *         with nogil:
 */
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/libcalignmentfile.pyx":2077
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.iter = sam_itr_queryi(
 *                 self.index,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2078
 *                              multiple_iterators=multiple_iterators)
 *         with nogil:
 *             self.iter = sam_itr_queryi(             # <<<<<<<<<<<<<<
 *                 self.index,
 *                 tid,
 */
        __pyx_v_self->iter = sam_itr_queryi(__pyx_v_self->__pyx_base.index, __pyx_v_tid, __pyx_v_beg, __pyx_v_stop);
      }

      /* "pysam/libcalignmentfile.pyx":2077
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.iter = sam_itr_queryi(
 *                 self.index,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2068
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):
 */

  /* 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_6);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2084
 *                 stop)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2084, 0, __PYX_ERR(0, 2084, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2085
 * 
 *     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/libcalignmentfile.pyx":2084
 *                 stop)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2087
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2087, 0, __PYX_ERR(0, 2087, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2088
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2087
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowRegion.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2090
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:
 */

static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 2090, 0, __PYX_ERR(0, 2090, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2092
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),
 *                                        self.iter,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2093
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:
 *             self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),             # <<<<<<<<<<<<<<
 *                                        self.iter,
 *                                        self.b,
 */
        __pyx_v_self->__pyx_base.retval = hts_itr_next(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_v_self->iter, __pyx_v_self->__pyx_base.b, __pyx_v_self->__pyx_base.htsfile);
      }

      /* "pysam/libcalignmentfile.pyx":2092
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),
 *                                        self.iter,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2090
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowRegion.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2098
 *                                        self.htsfile)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         self.cnext()
 *         if self.retval >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2098, 0, __PYX_ERR(0, 2098, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2099
 * 
 *     def __next__(self):
 *         self.cnext()             # <<<<<<<<<<<<<<
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  (void)(((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self));

  /* "pysam/libcalignmentfile.pyx":2100
 *     def __next__(self):
 *         self.cnext()
 *         if self.retval >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2101
 *         self.cnext()
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif self.retval == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2101, __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;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2100
 *     def __next__(self):
 *         self.cnext()
 *         if self.retval >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2102
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         elif self.retval == -2:
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval == -1L) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2103
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         elif self.retval == -2:
 *             # Note: it is currently not the case that hts_iter_next
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2103, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2102
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         elif self.retval == -2:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2104
 *         elif self.retval == -1:
 *             raise StopIteration
 *         elif self.retval == -2:             # <<<<<<<<<<<<<<
 *             # Note: it is currently not the case that hts_iter_next
 *             # returns -2 for a truncated file.
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval == -2L) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2108
 *             # returns -2 for a truncated file.
 *             # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2108, __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_ERR(0, 2108, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2104
 *         elif self.retval == -1:
 *             raise StopIteration
 *         elif self.retval == -2:             # <<<<<<<<<<<<<<
 *             # Note: it is currently not the case that hts_iter_next
 *             # returns -2 for a truncated file.
 */
  }

  /* "pysam/libcalignmentfile.pyx":2110
 *             raise IOError('truncated file')
 *         else:
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_error_while_reading_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.retval); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_6 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2110, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2110, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2110, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_v_self->__pyx_base.samfile->__pyx_base.filename);
      __Pyx_GIVEREF(__pyx_v_self->__pyx_base.samfile->__pyx_base.filename);
      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2110, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2110, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2110, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2098
 *                                        self.htsfile)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         self.cnext()
 *         if self.retval >= 0:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2112
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2112, 0, __PYX_ERR(0, 2112, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2113
 * 
 *     def __dealloc__(self):
 *         hts_itr_destroy(self.iter)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  hts_itr_destroy(__pyx_v_self->iter);

  /* "pysam/libcalignmentfile.pyx":2112
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowRegion.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__[] = "IteratorRowRegion.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__[] = "IteratorRowRegion.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 */

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

/* "pysam/libcalignmentfile.pyx":2128
 *     """
 * 
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  AlignmentFile samfile,
 *                  int n,
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_n;
  int __pyx_v_multiple_iterators;
  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_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 2128, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 2128, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        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_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2130, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2131, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2131
 *                  AlignmentFile samfile,
 *                  int n,
 *                  int multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile,
 */
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2128, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2129, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self), __pyx_v_samfile, __pyx_v_n, __pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":2128
 *     """
 * 
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  AlignmentFile samfile,
 *                  int n,
 */

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

static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2128, 0, __PYX_ERR(0, 2128, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2133
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));

  /* "pysam/libcalignmentfile.pyx":2134
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         self.max_rows = n
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2133
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2133, __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/libcalignmentfile.pyx":2136
 *                              multiple_iterators=multiple_iterators)
 * 
 *         self.max_rows = n             # <<<<<<<<<<<<<<
 *         self.current_row = 0
 * 
 */
  __pyx_v_self->max_rows = __pyx_v_n;

  /* "pysam/libcalignmentfile.pyx":2137
 * 
 *         self.max_rows = n
 *         self.current_row = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_row = 0;

  /* "pysam/libcalignmentfile.pyx":2128
 *     """
 * 
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  AlignmentFile samfile,
 *                  int n,
 */

  /* 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.libcalignmentfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2139
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2139, 0, __PYX_ERR(0, 2139, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2140
 * 
 *     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/libcalignmentfile.pyx":2139
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2142
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2142, 0, __PYX_ERR(0, 2142, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2143
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2142
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowHead.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2145
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam_hdr_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 2145, 0, __PYX_ERR(0, 2145, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2148
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base.header->ptr;
  __pyx_v_hdr = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2149
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2150
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b);
      }

      /* "pysam/libcalignmentfile.pyx":2149
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2153
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2145
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowHead.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2155
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  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_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2155, 0, __PYX_ERR(0, 2155, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2156
 * 
 *     def __next__(self):
 *         if self.current_row >= self.max_rows:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->current_row >= __pyx_v_self->max_rows) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2157
 *     def __next__(self):
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret = self.cnext()
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2157, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2156
 * 
 *     def __next__(self):
 *         if self.current_row >= self.max_rows:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2159
 *             raise StopIteration
 * 
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             self.current_row += 1
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/libcalignmentfile.pyx":2160
 * 
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2161
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             self.current_row += 1             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
    __pyx_v_self->current_row = (__pyx_v_self->current_row + 1);

    /* "pysam/libcalignmentfile.pyx":2162
 *         if ret >= 0:
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2162, __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;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2160
 * 
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2163
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -1L) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2164
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2164, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2163
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2166
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2166, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2166, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2155
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration
 */

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

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__[] = "IteratorRowHead.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__[] = "IteratorRowHead.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

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

/* "pysam/libcalignmentfile.pyx":2182
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int multiple_iterators=False):
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_multiple_iterators;
  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_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 2182, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2183, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2183
 * 
 *     def __init__(self, AlignmentFile samfile,
 *                  int multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile,
 */
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2182, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2182, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":2182
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int multiple_iterators=False):
 * 
 */

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

static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2182, 0, __PYX_ERR(0, 2182, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2185
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));

  /* "pysam/libcalignmentfile.pyx":2186
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2186, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2186, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2186, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2185
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2185, __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/libcalignmentfile.pyx":2182
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int multiple_iterators=False):
 * 
 */

  /* 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.libcalignmentfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2188
 *                              multiple_iterators=multiple_iterators)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2188, 0, __PYX_ERR(0, 2188, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2189
 * 
 *     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/libcalignmentfile.pyx":2188
 *                              multiple_iterators=multiple_iterators)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2191
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2191, 0, __PYX_ERR(0, 2191, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2192
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2191
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowAll.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2194
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam_hdr_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 2194, 0, __PYX_ERR(0, 2194, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2197
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base.header->ptr;
  __pyx_v_hdr = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2198
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2199
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b);
      }

      /* "pysam/libcalignmentfile.pyx":2198
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2202
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2194
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowAll.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2204
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  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_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2204, 0, __PYX_ERR(0, 2204, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2205
 * 
 *     def __next__(self):
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/libcalignmentfile.pyx":2206
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2207
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2207, __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;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2206
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2208
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -1L) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2209
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2209, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2208
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2211
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2211, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2204
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

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

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__[] = "IteratorRowAll.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__[] = "IteratorRowAll.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

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

/* "pysam/libcalignmentfile.pyx":2225
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  multiple_iterators=False):
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_multiple_iterators = 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_multiple_iterators,0};
    PyObject* values[2] = {0,0};

    /* "pysam/libcalignmentfile.pyx":2226
 * 
 *     def __init__(self, AlignmentFile samfile,
 *                  multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile,
 */
    values[1] = ((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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 2225, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_multiple_iterators = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2225, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2225, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":2225
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  multiple_iterators=False):
 * 
 */

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

static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2225, 0, __PYX_ERR(0, 2225, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2228
 *                  multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));

  /* "pysam/libcalignmentfile.pyx":2229
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         if not samfile.has_index():
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2229, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 2229, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2228
 *                  multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2228, __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/libcalignmentfile.pyx":2231
 *                              multiple_iterators=multiple_iterators)
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for fetch")
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2231, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_4 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2231, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __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_ERR(0, 2231, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "pysam/libcalignmentfile.pyx":2232
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2232, __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_ERR(0, 2232, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2231
 *                              multiple_iterators=multiple_iterators)
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for fetch")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2234
 *             raise ValueError("no index available for fetch")
 * 
 *         self.tid = -1             # <<<<<<<<<<<<<<
 * 
 *     def nextiter(self):
 */
  __pyx_v_self->tid = -1;

  /* "pysam/libcalignmentfile.pyx":2225
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  multiple_iterators=False):
 * 
 */

  /* 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.libcalignmentfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2236
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter[] = "IteratorRowAllRefs.nextiter(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_18IteratorRowAllRefs_2nextiter(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  htsFile *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("nextiter", 0);
  __Pyx_TraceCall("nextiter", __pyx_f[0], 2236, 0, __PYX_ERR(0, 2236, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2240
 *         # will not be re-opened.
 *         self.rowiter = IteratorRowRegion(self.samfile,
 *                                          self.tid,             # <<<<<<<<<<<<<<
 *                                          0,
 *                                          MAX_POS)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":2242
 *                                          self.tid,
 *                                          0,
 *                                          MAX_POS)             # <<<<<<<<<<<<<<
 *         # set htsfile and header of the rowiter
 *         # to the values in this iterator to reflect multiple_iterators
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_5pysam_17libcalignmentfile_MAX_POS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2242, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":2239
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 *         self.rowiter = IteratorRowRegion(self.samfile,             # <<<<<<<<<<<<<<
 *                                          self.tid,
 *                                          0,
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2239, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->__pyx_base.samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->__pyx_base.samfile));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->__pyx_base.samfile));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2239, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->rowiter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->rowiter));
  __pyx_v_self->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2245
 *         # set htsfile and header of the rowiter
 *         # to the values in this iterator to reflect multiple_iterators
 *         self.rowiter.htsfile = self.htsfile             # <<<<<<<<<<<<<<
 *         self.rowiter.header = self.header
 * 
 */
  __pyx_t_4 = __pyx_v_self->__pyx_base.htsfile;
  __pyx_v_self->rowiter->__pyx_base.htsfile = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":2246
 *         # to the values in this iterator to reflect multiple_iterators
 *         self.rowiter.htsfile = self.htsfile
 *         self.rowiter.header = self.header             # <<<<<<<<<<<<<<
 * 
 *         # make sure the iterator understand that IteratorRowAllRefs
 */
  __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF(__pyx_v_self->rowiter->__pyx_base.header);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->rowiter->__pyx_base.header));
  __pyx_v_self->rowiter->__pyx_base.header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2250
 *         # make sure the iterator understand that IteratorRowAllRefs
 *         # has ownership
 *         self.rowiter.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->rowiter->__pyx_base.owns_samfile = 0;

  /* "pysam/libcalignmentfile.pyx":2236
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 */

  /* 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.libcalignmentfile.IteratorRowAllRefs.nextiter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2252
 *         self.rowiter.owns_samfile = False
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2252, 0, __PYX_ERR(0, 2252, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2253
 * 
 *     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/libcalignmentfile.pyx":2252
 *         self.rowiter.owns_samfile = False
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2255
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         # Create an initial iterator
 *         if self.tid == -1:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2255, 0, __PYX_ERR(0, 2255, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2257
 *     def __next__(self):
 *         # Create an initial iterator
 *         if self.tid == -1:             # <<<<<<<<<<<<<<
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 */
  __pyx_t_1 = ((__pyx_v_self->tid == -1L) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2258
 *         # 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_ERR(0, 2258, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2258, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = ((!__pyx_t_1) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":2259
 *         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_ERR(0, 2259, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2258
 *         # Create an initial iterator
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 *             self.tid = 0
 */
    }

    /* "pysam/libcalignmentfile.pyx":2260
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 *             self.tid = 0             # <<<<<<<<<<<<<<
 *             self.nextiter()
 * 
 */
    __pyx_v_self->tid = 0;

    /* "pysam/libcalignmentfile.pyx":2261
 *                 raise StopIteration
 *             self.tid = 0
 *             self.nextiter()             # <<<<<<<<<<<<<<
 * 
 *         while 1:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2261, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2261, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":2257
 *     def __next__(self):
 *         # Create an initial iterator
 *         if self.tid == -1:             # <<<<<<<<<<<<<<
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 */
  }

  /* "pysam/libcalignmentfile.pyx":2263
 *             self.nextiter()
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.rowiter.cnext()
 * 
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2264
 * 
 *         while 1:
 *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
 * 
 *             # If current iterator is not exhausted, return aligned read
 */
    (void)(((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter));

    /* "pysam/libcalignmentfile.pyx":2267
 * 
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:             # <<<<<<<<<<<<<<
 *                 return makeAlignedSegment(self.rowiter.b, self.header)
 * 
 */
    __pyx_t_3 = ((__pyx_v_self->rowiter->__pyx_base.retval > 0) != 0);
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":2268
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:
 *                 return makeAlignedSegment(self.rowiter.b, self.header)             # <<<<<<<<<<<<<<
 * 
 *             self.tid += 1
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->rowiter->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;

      /* "pysam/libcalignmentfile.pyx":2267
 * 
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:             # <<<<<<<<<<<<<<
 *                 return makeAlignedSegment(self.rowiter.b, self.header)
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2270
 *                 return makeAlignedSegment(self.rowiter.b, self.header)
 * 
 *             self.tid += 1             # <<<<<<<<<<<<<<
 * 
 *             # Otherwise, proceed to next reference or stop
 */
    __pyx_v_self->tid = (__pyx_v_self->tid + 1);

    /* "pysam/libcalignmentfile.pyx":2273
 * 
 *             # 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_ERR(0, 2273, __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_ERR(0, 2273, __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_ERR(0, 2273, __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_ERR(0, 2273, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (likely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":2274
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:
 *                 self.nextiter()             # <<<<<<<<<<<<<<
 *             else:
 *                 raise StopIteration
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2274, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2274, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":2273
 * 
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.nextiter()
 *             else:
 */
      goto __pyx_L8;
    }

    /* "pysam/libcalignmentfile.pyx":2276
 *                 self.nextiter()
 *             else:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    /*else*/ {
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      __PYX_ERR(0, 2276, __pyx_L1_error)
    }
    __pyx_L8:;
  }

  /* "pysam/libcalignmentfile.pyx":2255
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         # Create an initial iterator
 *         if self.tid == -1:
 */

  /* 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.libcalignmentfile.IteratorRowAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__[] = "IteratorRowAllRefs.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__[] = "IteratorRowAllRefs.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

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

/* "pysam/libcalignmentfile.pyx":2289
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, multiple_iterators=multiple_iterators)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_positions = 0;
  int __pyx_v_multiple_iterators;
  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_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 2289, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 2289, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        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_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_positions = values[1];
    if (values[2]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2289, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2289, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2289, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self), __pyx_v_samfile, __pyx_v_positions, __pyx_v_multiple_iterators);

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

static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2289, 0, __PYX_ERR(0, 2289, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2291
 *     def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True):
 * 
 *         IteratorRow.__init__(self, samfile, multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         self.positions = positions
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2291, __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_ERR(0, 2291, __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/libcalignmentfile.pyx":2293
 *         IteratorRow.__init__(self, samfile, multiple_iterators=multiple_iterators)
 * 
 *         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/libcalignmentfile.pyx":2294
 * 
 *         self.positions = positions
 *         self.current_pos = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_pos = 0;

  /* "pysam/libcalignmentfile.pyx":2289
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile, multiple_iterators=multiple_iterators)
 */

  /* 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.libcalignmentfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2296
 *         self.current_pos = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2296, 0, __PYX_ERR(0, 2296, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2297
 * 
 *     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/libcalignmentfile.pyx":2296
 *         self.current_pos = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2299
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2299, 0, __PYX_ERR(0, 2299, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2300
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2299
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowSelection.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2302
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 *         # end iteration if out of positions
 */

static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  uint64_t __pyx_v_pos;
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  uint64_t __pyx_t_4;
  bam_hdr_t *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 2302, 0, __PYX_ERR(0, 2302, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2305
 *         '''cversion of iterator'''
 *         # end iteration if out of positions
 *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]
 */
  __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 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2305, __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/libcalignmentfile.pyx":2307
 *         if self.current_pos >= len(self.positions): return -1
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]             # <<<<<<<<<<<<<<
 *         with nogil:
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),
 */
  __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)) __PYX_ERR(0, 2307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2307, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":2308
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),
 *                       pos,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2309
 *         cdef uint64_t pos = self.positions[self.current_pos]
 *         with nogil:
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),             # <<<<<<<<<<<<<<
 *                       pos,
 *                       0)
 */
        (void)(bgzf_seek(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_v_pos, 0));
      }

      /* "pysam/libcalignmentfile.pyx":2308
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),
 *                       pos,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2312
 *                       pos,
 *                       0)
 *         self.current_pos += 1             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret
 */
  __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);

  /* "pysam/libcalignmentfile.pyx":2315
 * 
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_5 = __pyx_v_self->__pyx_base.header->ptr;
  __pyx_v_hdr = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":2316
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2317
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b);
      }

      /* "pysam/libcalignmentfile.pyx":2316
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L9;
        }
        __pyx_L9:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2320
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2302
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 *         # end iteration if out of positions
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowSelection.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2322
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  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_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2322, 0, __PYX_ERR(0, 2322, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2323
 * 
 *     def __next__(self):
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/libcalignmentfile.pyx":2324
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2325
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2325, __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;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2324
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2326
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -1L) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2327
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2327, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2326
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2329
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2329, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2329, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2322
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

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

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__[] = "IteratorRowSelection.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__[] = "IteratorRowSelection.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */

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

/* "pysam/libcalignmentfile.pyx":2332
 * 
 * 
 * cdef int __advance_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__advance_nofilter", 0);
  __Pyx_TraceCall("__advance_nofilter", __pyx_f[0], 2332, 0, __PYX_ERR(0, 2332, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2335
 *     '''advance without any read filtering.
 *     '''
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     with nogil:
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2337
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 *     return ret
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2338
 *     cdef int ret
 *     with nogil:
 *         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);
      }

      /* "pysam/libcalignmentfile.pyx":2337
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 *     return ret
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2339
 *     with nogil:
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2332
 * 
 * 
 * cdef int __advance_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_nofilter", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2342
 * 
 * 
 * cdef int __advance_raw_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance (without iterator) without any read filtering.
 *     '''
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_nofilter(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__advance_raw_nofilter", 0);
  __Pyx_TraceCall("__advance_raw_nofilter", __pyx_f[0], 2342, 0, __PYX_ERR(0, 2342, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2345
 *     '''advance (without iterator) without any read filtering.
 *     '''
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     with nogil:
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2347
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_read1(d.htsfile, d.header, b)
 *     return ret
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2348
 *     cdef int ret
 *     with nogil:
 *         ret = sam_read1(d.htsfile, d.header, b)             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
        __pyx_v_ret = sam_read1(__pyx_v_d->htsfile, __pyx_v_d->header, __pyx_v_b);
      }

      /* "pysam/libcalignmentfile.pyx":2347
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_read1(d.htsfile, d.header, b)
 *     return ret
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2349
 *     with nogil:
 *         ret = sam_read1(d.htsfile, d.header, b)
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2342
 * 
 * 
 * cdef int __advance_raw_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance (without iterator) without any read filtering.
 *     '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_raw_nofilter", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2352
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  CYTHON_UNUSED PyObject *__pyx_v_mask = 0;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__advance_all", 0);
  __Pyx_TraceCall("__advance_all", __pyx_f[0], 2352, 0, __PYX_ERR(0, 2352, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2358
 *     '''
 * 
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP
 *     cdef int ret
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2359
 * 
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     while 1:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_mask = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2361
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP
 *     cdef int ret
 *     while 1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2362
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2363
 *     while 1:
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 *         if ret < 0:
 *             break
 */
          __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
        }

        /* "pysam/libcalignmentfile.pyx":2362
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2364
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    __pyx_t_2 = ((__pyx_v_ret < 0) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2365
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:
 *             break             # <<<<<<<<<<<<<<
 *         if b.core.flag & d.flag_filter:
 *             continue
 */
      goto __pyx_L4_break;

      /* "pysam/libcalignmentfile.pyx":2364
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2366
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    __pyx_t_2 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2367
 *             break
 *         if b.core.flag & d.flag_filter:
 *             continue             # <<<<<<<<<<<<<<
 *         break
 *     return ret
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2366
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    }

    /* "pysam/libcalignmentfile.pyx":2368
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         break             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
    goto __pyx_L4_break;
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;

  /* "pysam/libcalignmentfile.pyx":2369
 *             continue
 *         break
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2352
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_all", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mask);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2372
 * 
 * 
 * cdef int __advance_raw_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__advance_raw_all", 0);
  __Pyx_TraceCall("__advance_raw_all", __pyx_f[0], 2372, 0, __PYX_ERR(0, 2372, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2378
 *     '''
 * 
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     while 1:
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2380
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     while 1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2381
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2382
 *     while 1:
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)             # <<<<<<<<<<<<<<
 *         if ret < 0:
 *             break
 */
          __pyx_v_ret = sam_read1(__pyx_v_d->htsfile, __pyx_v_d->header, __pyx_v_b);
        }

        /* "pysam/libcalignmentfile.pyx":2381
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2383
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    __pyx_t_1 = ((__pyx_v_ret < 0) != 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2384
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 *             break             # <<<<<<<<<<<<<<
 *         if b.core.flag & d.flag_filter:
 *             continue
 */
      goto __pyx_L4_break;

      /* "pysam/libcalignmentfile.pyx":2383
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2385
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    __pyx_t_1 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2386
 *             break
 *         if b.core.flag & d.flag_filter:
 *             continue             # <<<<<<<<<<<<<<
 *         break
 *     return ret
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2385
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    }

    /* "pysam/libcalignmentfile.pyx":2387
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         break             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
    goto __pyx_L4_break;
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;

  /* "pysam/libcalignmentfile.pyx":2388
 *             continue
 *         break
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2372
 * 
 * 
 * cdef int __advance_raw_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_raw_all", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2391
 * 
 * 
 * cdef int __advance_samtools(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_samtools(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_v_q;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__advance_samtools", 0);
  __Pyx_TraceCall("__advance_samtools", __pyx_f[0], 2391, 0, __PYX_ERR(0, 2391, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2395
 *     the samtools pileup.
 *     '''
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     cdef int q
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2399
 *     cdef int q
 * 
 *     while 1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2400
 * 
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2401
 *     while 1:
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)             # <<<<<<<<<<<<<<
 *         if ret < 0:
 *             break
 */
          if ((__pyx_v_d->iter != 0)) {
            __pyx_t_1 = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
          } else {
            __pyx_t_1 = sam_read1(__pyx_v_d->htsfile, __pyx_v_d->header, __pyx_v_b);
          }
          __pyx_v_ret = __pyx_t_1;
        }

        /* "pysam/libcalignmentfile.pyx":2400
 * 
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2402
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    __pyx_t_2 = ((__pyx_v_ret < 0) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2403
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 *             break             # <<<<<<<<<<<<<<
 *         if b.core.flag & d.flag_filter:
 *             continue
 */
      goto __pyx_L4_break;

      /* "pysam/libcalignmentfile.pyx":2402
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2404
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 */
    __pyx_t_2 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2405
 *             break
 *         if b.core.flag & d.flag_filter:
 *             continue             # <<<<<<<<<<<<<<
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 *             continue
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2404
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 */
    }

    /* "pysam/libcalignmentfile.pyx":2406
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    __pyx_t_3 = (__pyx_v_d->flag_require != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = ((!((__pyx_v_b->core.flag & __pyx_v_d->flag_require) != 0)) != 0);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2407
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         # reload sequence
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2406
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2410
 * 
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
 *             if d.seq != NULL:
 *                 free(d.seq)
 */
    __pyx_t_3 = ((__pyx_v_d->fastafile != NULL) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_b->core.tid != __pyx_v_d->tid) != 0);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L16_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2411
 *         # 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_2 = ((__pyx_v_d->seq != NULL) != 0);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2412
 *         if d.fastafile != NULL and b.core.tid != d.tid:
 *             if d.seq != NULL:
 *                 free(d.seq)             # <<<<<<<<<<<<<<
 *             d.tid = b.core.tid
 *             with nogil:
 */
        free(__pyx_v_d->seq);

        /* "pysam/libcalignmentfile.pyx":2411
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:
 *             if d.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(d.seq)
 *             d.tid = b.core.tid
 */
      }

      /* "pysam/libcalignmentfile.pyx":2413
 *             if d.seq != NULL:
 *                 free(d.seq)
 *             d.tid = b.core.tid             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 d.seq = faidx_fetch_seq(
 */
      __pyx_t_4 = __pyx_v_b->core.tid;
      __pyx_v_d->tid = __pyx_t_4;

      /* "pysam/libcalignmentfile.pyx":2414
 *                 free(d.seq)
 *             d.tid = b.core.tid
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 d.seq = faidx_fetch_seq(
 *                     d.fastafile,
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":2415
 *             d.tid = b.core.tid
 *             with nogil:
 *                 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_17libcalignmentfile_MAX_POS, (&__pyx_v_d->seq_len));
          }

          /* "pysam/libcalignmentfile.pyx":2414
 *                 free(d.seq)
 *             d.tid = b.core.tid
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 d.seq = faidx_fetch_seq(
 *                     d.fastafile,
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L23;
            }
            __pyx_L23:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":2421
 *                     &d.seq_len)
 * 
 *             if d.seq == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(
 */
      __pyx_t_2 = ((__pyx_v_d->seq == NULL) != 0);
      if (unlikely(__pyx_t_2)) {

        /* "pysam/libcalignmentfile.pyx":2423
 *             if d.seq == NULL:
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(             # <<<<<<<<<<<<<<
 *                         d.header.target_name[d.tid], d.tid))
 * 
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_reference_sequence_for_tid_not_f, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2423, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);

        /* "pysam/libcalignmentfile.pyx":2424
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(
 *                         d.header.target_name[d.tid], d.tid))             # <<<<<<<<<<<<<<
 * 
 *         # realign read - changes base qualities
 */
        __pyx_t_7 = __Pyx_PyBytes_FromString((__pyx_v_d->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2424, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_d->tid); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2424, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = NULL;
        __pyx_t_1 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_1 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2423, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2423, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2423, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          if (__pyx_t_9) {
            __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_1, __pyx_t_7);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_1, __pyx_t_8);
          __pyx_t_7 = 0;
          __pyx_t_8 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2423, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "pysam/libcalignmentfile.pyx":2422
 * 
 *             if d.seq == NULL:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "reference sequence for '{}' (tid={}) not found".format(
 *                         d.header.target_name[d.tid], d.tid))
 */
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2422, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_6, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __PYX_ERR(0, 2422, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":2421
 *                     &d.seq_len)
 * 
 *             if d.seq == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(
 */
      }

      /* "pysam/libcalignmentfile.pyx":2410
 * 
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
 *             if d.seq != NULL:
 *                 free(d.seq)
 */
    }

    /* "pysam/libcalignmentfile.pyx":2427
 * 
 *         # realign read - changes base qualities
 *         if d.seq != NULL and d.compute_baq:             # <<<<<<<<<<<<<<
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 */
    __pyx_t_3 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L26_bool_binop_done;
    }
    __pyx_t_3 = (__pyx_v_d->compute_baq != 0);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L26_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2430
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 *             if d.redo_baq:             # <<<<<<<<<<<<<<
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)
 *             else:
 */
      __pyx_t_2 = (__pyx_v_d->redo_baq != 0);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2431
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 *             if d.redo_baq:
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)             # <<<<<<<<<<<<<<
 *             else:
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)
 */
        (void)(sam_prob_realn(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, 7));

        /* "pysam/libcalignmentfile.pyx":2430
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 *             if d.redo_baq:             # <<<<<<<<<<<<<<
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)
 *             else:
 */
        goto __pyx_L28;
      }

      /* "pysam/libcalignmentfile.pyx":2433
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)
 *             else:
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)             # <<<<<<<<<<<<<<
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 */
      /*else*/ {
        (void)(sam_prob_realn(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, 3));
      }
      __pyx_L28:;

      /* "pysam/libcalignmentfile.pyx":2427
 * 
 *         # realign read - changes base qualities
 *         if d.seq != NULL and d.compute_baq:             # <<<<<<<<<<<<<<
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 */
    }

    /* "pysam/libcalignmentfile.pyx":2435
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:             # <<<<<<<<<<<<<<
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:
 */
    __pyx_t_3 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L30_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_d->adjust_capq_threshold > 10) != 0);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L30_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2436
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)             # <<<<<<<<<<<<<<
 *             if q < 0:
 *                 continue
 */
      __pyx_v_q = sam_cap_mapq(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, __pyx_v_d->adjust_capq_threshold);

      /* "pysam/libcalignmentfile.pyx":2437
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:             # <<<<<<<<<<<<<<
 *                 continue
 *             elif b.core.qual > q:
 */
      __pyx_t_2 = ((__pyx_v_q < 0) != 0);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2438
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:
 *                 continue             # <<<<<<<<<<<<<<
 *             elif b.core.qual > q:
 *                 b.core.qual = q
 */
        goto __pyx_L3_continue;

        /* "pysam/libcalignmentfile.pyx":2437
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:             # <<<<<<<<<<<<<<
 *                 continue
 *             elif b.core.qual > q:
 */
      }

      /* "pysam/libcalignmentfile.pyx":2439
 *             if q < 0:
 *                 continue
 *             elif b.core.qual > q:             # <<<<<<<<<<<<<<
 *                 b.core.qual = q
 * 
 */
      __pyx_t_2 = ((__pyx_v_b->core.qual > __pyx_v_q) != 0);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2440
 *                 continue
 *             elif b.core.qual > q:
 *                 b.core.qual = q             # <<<<<<<<<<<<<<
 * 
 *         if b.core.qual < d.min_mapping_quality:
 */
        __pyx_v_b->core.qual = __pyx_v_q;

        /* "pysam/libcalignmentfile.pyx":2439
 *             if q < 0:
 *                 continue
 *             elif b.core.qual > q:             # <<<<<<<<<<<<<<
 *                 b.core.qual = q
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":2435
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:             # <<<<<<<<<<<<<<
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2442
 *                 b.core.qual = q
 * 
 *         if b.core.qual < d.min_mapping_quality:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 */
    __pyx_t_2 = ((__pyx_v_b->core.qual < __pyx_v_d->min_mapping_quality) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2443
 * 
 *         if b.core.qual < d.min_mapping_quality:
 *             continue             # <<<<<<<<<<<<<<
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 *             continue
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2442
 *                 b.core.qual = q
 * 
 *         if b.core.qual < d.min_mapping_quality:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 */
    }

    /* "pysam/libcalignmentfile.pyx":2444
 *         if b.core.qual < d.min_mapping_quality:
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    __pyx_t_3 = (__pyx_v_d->ignore_orphans != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L35_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_b->core.flag & BAM_FPAIRED) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L35_bool_binop_done;
    }
    __pyx_t_3 = ((!((__pyx_v_b->core.flag & BAM_FPROPER_PAIR) != 0)) != 0);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L35_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2445
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         break
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2444
 *         if b.core.qual < d.min_mapping_quality:
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2447
 *             continue
 * 
 *         break             # <<<<<<<<<<<<<<
 * 
 *     return ret
 */
    goto __pyx_L4_break;
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;

  /* "pysam/libcalignmentfile.pyx":2449
 *         break
 * 
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2391
 * 
 * 
 * cdef int __advance_samtools(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_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_samtools", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2484
 *     '''
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__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_ERR(0, 2484, __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_17libcalignmentfile_AlignmentFile *)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2484, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2484, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_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_17libcalignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  uint32_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2484, 0, __PYX_ERR(0, 2484, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2485
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", "samtools")
 */
  __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/libcalignmentfile.pyx":2486
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)             # <<<<<<<<<<<<<<
 *         self.stepper = kwargs.get("stepper", "samtools")
 *         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_ERR(0, 2486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9libcfaidx_FastaFile))))) __PYX_ERR(0, 2486, __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_9libcfaidx_FastaFile *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2487
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", "samtools")             # <<<<<<<<<<<<<<
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_stepper, __pyx_n_s_samtools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2487, __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/libcalignmentfile.pyx":2488
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", "samtools")
 *         self.max_depth = kwargs.get("max_depth", 8000)             # <<<<<<<<<<<<<<
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_max_depth, __pyx_int_8000); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2488, __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_ERR(0, 2488, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->max_depth = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2489
 *         self.stepper = kwargs.get("stepper", "samtools")
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)             # <<<<<<<<<<<<<<
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 *         self.iterdata.seq = NULL
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_ignore_overlaps, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2489, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2489, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->ignore_overlaps = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2490
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_min_base_quality, __pyx_int_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->min_base_quality = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":2491
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/libcalignmentfile.pyx":2492
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 *         self.iterdata.seq = NULL
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)             # <<<<<<<<<<<<<<
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_min_mapping_quality, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2492, __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_ERR(0, 2492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->iterdata.min_mapping_quality = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2493
 *         self.iterdata.seq = NULL
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)             # <<<<<<<<<<<<<<
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_flag_require, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2493, __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_ERR(0, 2493, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->iterdata.flag_require = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2494
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)             # <<<<<<<<<<<<<<
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_flag_filter, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2494, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.flag_filter = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2495
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)             # <<<<<<<<<<<<<<
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_adjust_capq_threshold, __pyx_int_0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2495, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2495, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.adjust_capq_threshold = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2496
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)             # <<<<<<<<<<<<<<
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_compute_baq, Py_True); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2496, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.compute_baq = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2497
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)             # <<<<<<<<<<<<<<
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)
 * 
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_redo_baq, Py_False); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2497, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2497, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.redo_baq = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2498
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)             # <<<<<<<<<<<<<<
 * 
 *         self.tid = 0
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_ignore_orphans, Py_True); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2498, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2498, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.ignore_orphans = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2500
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)
 * 
 *         self.tid = 0             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         self.n_plp = 0
 */
  __pyx_v_self->tid = 0;

  /* "pysam/libcalignmentfile.pyx":2501
 * 
 *         self.tid = 0
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         self.n_plp = 0
 *         self.plp = NULL
 */
  __pyx_v_self->pos = 0;

  /* "pysam/libcalignmentfile.pyx":2502
 *         self.tid = 0
 *         self.pos = 0
 *         self.n_plp = 0             # <<<<<<<<<<<<<<
 *         self.plp = NULL
 *         self.pileup_iter = <bam_mplp_t>NULL
 */
  __pyx_v_self->n_plp = 0;

  /* "pysam/libcalignmentfile.pyx":2503
 *         self.pos = 0
 *         self.n_plp = 0
 *         self.plp = NULL             # <<<<<<<<<<<<<<
 *         self.pileup_iter = <bam_mplp_t>NULL
 * 
 */
  __pyx_v_self->plp = NULL;

  /* "pysam/libcalignmentfile.pyx":2504
 *         self.n_plp = 0
 *         self.plp = NULL
 *         self.pileup_iter = <bam_mplp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->pileup_iter = ((bam_mplp_t)NULL);

  /* "pysam/libcalignmentfile.pyx":2484
 *     '''
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2506
 *         self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2506, 0, __PYX_ERR(0, 2506, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2507
 * 
 *     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/libcalignmentfile.pyx":2506
 *         self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2509
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 2509, 0, __PYX_ERR(0, 2509, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2513
 *         '''
 *         # do not release gil here because of call-backs
 *         cdef int ret = bam_mplp_auto(self.pileup_iter,             # <<<<<<<<<<<<<<
 *                                      &self.tid,
 *                                      &self.pos,
 */
  __pyx_v_ret = bam_mplp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp), (&__pyx_v_self->plp));

  /* "pysam/libcalignmentfile.pyx":2518
 *                                      &self.n_plp,
 *                                      &self.plp)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     cdef char * get_sequence(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2509
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2520
 *         return ret
 * 
 *     cdef char * get_sequence(self):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  char *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_sequence", 0);
  __Pyx_TraceCall("get_sequence", __pyx_f[0], 2520, 0, __PYX_ERR(0, 2520, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2523
 *         '''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/libcalignmentfile.pyx":2520
 *         return ret
 * 
 *     cdef char * get_sequence(self):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.get_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2527
 *     property seq_len:
 *         '''current sequence length.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.iterdata.seq_len
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_14IteratorColumn_7seq_len___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2527, 0, __PYX_ERR(0, 2527, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2528
 *         '''current sequence length.'''
 *         def __get__(self):
 *             return self.iterdata.seq_len             # <<<<<<<<<<<<<<
 * 
 *     def add_reference(self, FastaFile fastafile):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2528, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2527
 *     property seq_len:
 *         '''current sequence length.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.iterdata.seq_len
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":2530
 *             return self.iterdata.seq_len
 * 
 *     def add_reference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference[] = "IteratorColumn.add_reference(self, FastaFile fastafile)\n\n       add reference sequences in `fastafile` to iterator.";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_reference (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9libcfaidx_FastaFile, 1, "fastafile", 0))) __PYX_ERR(0, 2530, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_9libcfaidx_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_17libcalignmentfile_14IteratorColumn_4add_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  faidx_t *__pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_reference", 0);
  __Pyx_TraceCall("add_reference", __pyx_f[0], 2530, 0, __PYX_ERR(0, 2530, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2533
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
 *        if self.iterdata.seq != NULL:
 *            free(self.iterdata.seq)
 */
  __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/libcalignmentfile.pyx":2534
 *        add reference sequences in `fastafile` to iterator.'''
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 */
  __pyx_t_1 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2535
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL:
 *            free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile
 */
    free(__pyx_v_self->iterdata.seq);

    /* "pysam/libcalignmentfile.pyx":2534
 *        add reference sequences in `fastafile` to iterator.'''
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 */
  }

  /* "pysam/libcalignmentfile.pyx":2536
 *        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/libcalignmentfile.pyx":2537
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 * 
 *     def has_reference(self):
 */
  __pyx_t_2 = __pyx_v_self->fastafile->fastafile;
  __pyx_v_self->iterdata.fastafile = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2530
 *             return self.iterdata.seq_len
 * 
 *     def add_reference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.add_reference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2539
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def has_reference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference[] = "IteratorColumn.has_reference(self)\n\n        return true if iterator is associated with a reference";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("has_reference (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("has_reference", 0);
  __Pyx_TraceCall("has_reference", __pyx_f[0], 2539, 0, __PYX_ERR(0, 2539, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2542
 *         '''
 *         return true if iterator is associated with a reference'''
 *         return self.fastafile             # <<<<<<<<<<<<<<
 * 
 *     cdef _setup_iterator(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_r = ((PyObject *)__pyx_v_self->fastafile);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2539
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def has_reference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.has_reference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2544
 *         return self.fastafile
 * 
 *     cdef _setup_iterator(self,             # <<<<<<<<<<<<<<
 *                          int tid,
 *                          int start,
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args) {
  int __pyx_v_multiple_iterators = ((int)0);
  void *__pyx_v_data[1];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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;
  int __pyx_t_10;
  faidx_t *__pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_setup_iterator", 0);
  __Pyx_TraceCall("_setup_iterator", __pyx_f[0], 2544, 0, __PYX_ERR(0, 2544, __pyx_L1_error));
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_multiple_iterators = __pyx_optional_args->multiple_iterators;
    }
  }

  /* "pysam/libcalignmentfile.pyx":2551
 *         '''setup the iterator structure'''
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators)             # <<<<<<<<<<<<<<
 *         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_ERR(0, 2551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __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 *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2551, __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_17libcalignmentfile_IteratorRowRegion *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2552
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators)
 *         self.iterdata.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 */
  __pyx_t_6 = __pyx_v_self->samfile->__pyx_base.htsfile;
  __pyx_v_self->iterdata.htsfile = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":2553
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators)
 *         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/libcalignmentfile.pyx":2554
 *         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.ptr
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/libcalignmentfile.pyx":2555
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/libcalignmentfile.pyx":2556
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile is not None:
 */
  __pyx_t_8 = __pyx_v_self->samfile->header->ptr;
  __pyx_v_self->iterdata.header = __pyx_t_8;

  /* "pysam/libcalignmentfile.pyx":2558
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
  __pyx_t_9 = (((PyObject *)__pyx_v_self->fastafile) != Py_None);
  __pyx_t_10 = (__pyx_t_9 != 0);
  if (__pyx_t_10) {

    /* "pysam/libcalignmentfile.pyx":2559
 * 
 *         if self.fastafile is not None:
 *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 *         else:
 *             self.iterdata.fastafile = NULL
 */
    __pyx_t_11 = __pyx_v_self->fastafile->fastafile;
    __pyx_v_self->iterdata.fastafile = __pyx_t_11;

    /* "pysam/libcalignmentfile.pyx":2558
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":2561
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *         # Free any previously allocated memory before reassigning
 */
  /*else*/ {
    __pyx_v_self->iterdata.fastafile = NULL;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":2565
 *         # Free any previously allocated memory before reassigning
 *         # pileup_iter
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 * 
 *         cdef void * data[1]
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2565, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2568
 * 
 *         cdef void * data[1]
 *         data[0] = <void*>&self.iterdata             # <<<<<<<<<<<<<<
 * 
 *         if self.stepper is None or self.stepper == "all":
 */
  (__pyx_v_data[0]) = ((void *)(&__pyx_v_self->iterdata));

  /* "pysam/libcalignmentfile.pyx":2570
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_9 = (__pyx_v_self->stepper == Py_None);
  __pyx_t_12 = (__pyx_t_9 != 0);
  if (!__pyx_t_12) {
  } else {
    __pyx_t_10 = __pyx_t_12;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2570, __pyx_L1_error)
  __pyx_t_10 = __pyx_t_12;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_10) {

    /* "pysam/libcalignmentfile.pyx":2571
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_all,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2572
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_all,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_all)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2571
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_all,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2570
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2575
 *                                                  <bam_plp_auto_f>&__advance_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2575, __pyx_L1_error)
  if (__pyx_t_10) {

    /* "pysam/libcalignmentfile.pyx":2576
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2577
 *         elif self.stepper == "nofilter":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_nofilter)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2576
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L12;
          }
          __pyx_L12:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2575
 *                                                  <bam_plp_auto_f>&__advance_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2580
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_samtools, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2580, __pyx_L1_error)
  if (likely(__pyx_t_10)) {

    /* "pysam/libcalignmentfile.pyx":2581
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2582
 *         elif self.stepper == "samtools":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_samtools)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2581
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L15;
          }
          __pyx_L15:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2580
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2586
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
  /*else*/ {

    /* "pysam/libcalignmentfile.pyx":2587
 *         else:
 *             raise ValueError(
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
 * 
 *         if self.max_depth:
 */
    __pyx_t_4 = __Pyx_PyString_FormatSafe(__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2587, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/libcalignmentfile.pyx":2586
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 2586, __pyx_L1_error)
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":2589
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  __pyx_t_10 = (__pyx_v_self->max_depth != 0);
  if (__pyx_t_10) {

    /* "pysam/libcalignmentfile.pyx":2590
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2591
 *         if self.max_depth:
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)             # <<<<<<<<<<<<<<
 * 
 *         if self.ignore_overlaps:
 */
          bam_mplp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
        }

        /* "pysam/libcalignmentfile.pyx":2590
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L19;
          }
          __pyx_L19:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2589
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2593
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  __pyx_t_10 = (__pyx_v_self->ignore_overlaps != 0);
  if (__pyx_t_10) {

    /* "pysam/libcalignmentfile.pyx":2594
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2595
 *         if self.ignore_overlaps:
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef _setup_raw_rest_iterator(self):
 */
          bam_mplp_init_overlaps(__pyx_v_self->pileup_iter);
        }

        /* "pysam/libcalignmentfile.pyx":2594
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L23;
          }
          __pyx_L23:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2593
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2544
 *         return self.fastafile
 * 
 *     cdef _setup_iterator(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.libcalignmentfile.IteratorColumn._setup_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2597
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef _setup_raw_rest_iterator(self):             # <<<<<<<<<<<<<<
 *         '''set up an "iterator" that just uses sam_read1(), similar to HTS_IDX_REST'''
 * 
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_raw_rest_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  void *__pyx_v_data[1];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  htsFile *__pyx_t_1;
  bam_hdr_t *__pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  faidx_t *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_setup_raw_rest_iterator", 0);
  __Pyx_TraceCall("_setup_raw_rest_iterator", __pyx_f[0], 2597, 0, __PYX_ERR(0, 2597, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2600
 *         '''set up an "iterator" that just uses sam_read1(), similar to HTS_IDX_REST'''
 * 
 *         self.iter = None             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = NULL
 *         self.iterdata.htsfile = self.samfile.htsfile
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->iter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None);

  /* "pysam/libcalignmentfile.pyx":2601
 * 
 *         self.iter = None
 *         self.iterdata.iter = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.seq = NULL
 */
  __pyx_v_self->iterdata.iter = NULL;

  /* "pysam/libcalignmentfile.pyx":2602
 *         self.iter = None
 *         self.iterdata.iter = NULL
 *         self.iterdata.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 */
  __pyx_t_1 = __pyx_v_self->samfile->__pyx_base.htsfile;
  __pyx_v_self->iterdata.htsfile = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2603
 *         self.iterdata.iter = NULL
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/libcalignmentfile.pyx":2604
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/libcalignmentfile.pyx":2605
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile is not None:
 */
  __pyx_t_2 = __pyx_v_self->samfile->header->ptr;
  __pyx_v_self->iterdata.header = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2607
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
  __pyx_t_3 = (((PyObject *)__pyx_v_self->fastafile) != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "pysam/libcalignmentfile.pyx":2608
 * 
 *         if self.fastafile is not None:
 *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 *         else:
 *             self.iterdata.fastafile = NULL
 */
    __pyx_t_5 = __pyx_v_self->fastafile->fastafile;
    __pyx_v_self->iterdata.fastafile = __pyx_t_5;

    /* "pysam/libcalignmentfile.pyx":2607
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":2610
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *         # Free any previously allocated memory before reassigning
 */
  /*else*/ {
    __pyx_v_self->iterdata.fastafile = NULL;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":2614
 *         # Free any previously allocated memory before reassigning
 *         # pileup_iter
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 * 
 *         cdef void * data[1]
 */
  __pyx_t_6 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2614, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "pysam/libcalignmentfile.pyx":2617
 * 
 *         cdef void * data[1]
 *         data[0] = <void*>&self.iterdata             # <<<<<<<<<<<<<<
 * 
 *         if self.stepper is None or self.stepper == "all":
 */
  (__pyx_v_data[0]) = ((void *)(&__pyx_v_self->iterdata));

  /* "pysam/libcalignmentfile.pyx":2619
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_3 = (__pyx_v_self->stepper == Py_None);
  __pyx_t_7 = (__pyx_t_3 != 0);
  if (!__pyx_t_7) {
  } else {
    __pyx_t_4 = __pyx_t_7;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2619, __pyx_L1_error)
  __pyx_t_4 = __pyx_t_7;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_4) {

    /* "pysam/libcalignmentfile.pyx":2620
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2621
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_raw_all)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2620
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2619
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2624
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2624, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "pysam/libcalignmentfile.pyx":2625
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2626
 *         elif self.stepper == "nofilter":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_raw_nofilter)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2625
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L12;
          }
          __pyx_L12:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2624
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2629
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_samtools, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2629, __pyx_L1_error)
  if (likely(__pyx_t_4)) {

    /* "pysam/libcalignmentfile.pyx":2630
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2631
 *         elif self.stepper == "samtools":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_samtools)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2630
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L15;
          }
          __pyx_L15:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2629
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2635
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
  /*else*/ {

    /* "pysam/libcalignmentfile.pyx":2636
 *         else:
 *             raise ValueError(
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
 * 
 *         if self.max_depth:
 */
    __pyx_t_6 = __Pyx_PyString_FormatSafe(__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2636, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "pysam/libcalignmentfile.pyx":2635
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2635, __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_ERR(0, 2635, __pyx_L1_error)
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":2638
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  __pyx_t_4 = (__pyx_v_self->max_depth != 0);
  if (__pyx_t_4) {

    /* "pysam/libcalignmentfile.pyx":2639
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2640
 *         if self.max_depth:
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)             # <<<<<<<<<<<<<<
 * 
 *         if self.ignore_overlaps:
 */
          bam_mplp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
        }

        /* "pysam/libcalignmentfile.pyx":2639
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L19;
          }
          __pyx_L19:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2638
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2642
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  __pyx_t_4 = (__pyx_v_self->ignore_overlaps != 0);
  if (__pyx_t_4) {

    /* "pysam/libcalignmentfile.pyx":2643
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2644
 *         if self.ignore_overlaps:
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef reset(self, tid, start, stop):
 */
          bam_mplp_init_overlaps(__pyx_v_self->pileup_iter);
        }

        /* "pysam/libcalignmentfile.pyx":2643
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L23;
          }
          __pyx_L23:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2642
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2597
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef _setup_raw_rest_iterator(self):             # <<<<<<<<<<<<<<
 *         '''set up an "iterator" that just uses sam_read1(), similar to HTS_IDX_REST'''
 * 
 */

  /* 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_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn._setup_raw_rest_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2646
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef reset(self, tid, start, stop):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_stop) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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;
  hts_itr_t *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("reset", 0);
  __Pyx_TraceCall("reset", __pyx_f[0], 2646, 0, __PYX_ERR(0, 2646, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2652
 *         having to incur the full set-up costs.
 *         '''
 *         if self.iter is None:             # <<<<<<<<<<<<<<
 *             raise TypeError("Raw iterator set up without region cannot be reset")
 * 
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->iter) == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2653
 *         '''
 *         if self.iter is None:
 *             raise TypeError("Raw iterator set up without region cannot be reset")             # <<<<<<<<<<<<<<
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2653, __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_ERR(0, 2653, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2652
 *         having to incur the full set-up costs.
 *         '''
 *         if self.iter is None:             # <<<<<<<<<<<<<<
 *             raise TypeError("Raw iterator set up without region cannot be reset")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2655
 *             raise TypeError("Raw iterator set up without region cannot be reset")
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 * 
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->samfile));
  __Pyx_INCREF(__pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_tid);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_start);
  __Pyx_INCREF(__pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_stop);
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2655, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_multiple_iterators, __pyx_int_0) < 0) __PYX_ERR(0, 2655, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2655, __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;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->iter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":2656
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 * 
 *         # invalidate sequence if different tid
 */
  __pyx_t_6 = __pyx_v_self->iter->iter;
  __pyx_v_self->iterdata.iter = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":2659
 * 
 *         # invalidate sequence if different tid
 *         if self.tid != tid:             # <<<<<<<<<<<<<<
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)
 */
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2659, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2659, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":2660
 *         # invalidate sequence if different tid
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
    __pyx_t_2 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2661
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1
 */
      free(__pyx_v_self->iterdata.seq);

      /* "pysam/libcalignmentfile.pyx":2660
 *         # invalidate sequence if different tid
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
    }

    /* "pysam/libcalignmentfile.pyx":2662
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *             self.iterdata.tid = -1
 * 
 */
    __pyx_v_self->iterdata.seq = NULL;

    /* "pysam/libcalignmentfile.pyx":2663
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 * 
 *         # self.pileup_iter = bam_mplp_init(1
 */
    __pyx_v_self->iterdata.tid = -1;

    /* "pysam/libcalignmentfile.pyx":2659
 * 
 *         # invalidate sequence if different tid
 *         if self.tid != tid:             # <<<<<<<<<<<<<<
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2668
 *         #                                  &__advancepileup,
 *         #                                  &self.iterdata)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bam_mplp_reset(self.pileup_iter)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2669
 *         #                                  &self.iterdata)
 *         with nogil:
 *             bam_mplp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef _free_pileup_iter(self):
 */
        bam_mplp_reset(__pyx_v_self->pileup_iter);
      }

      /* "pysam/libcalignmentfile.pyx":2668
 *         #                                  &__advancepileup,
 *         #                                  &self.iterdata)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bam_mplp_reset(self.pileup_iter)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L8;
        }
        __pyx_L8:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2646
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef reset(self, tid, start, stop):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

  /* 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_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2671
 *             bam_mplp_reset(self.pileup_iter)
 * 
 *     cdef _free_pileup_iter(self):             # <<<<<<<<<<<<<<
 *         '''free the memory alloc'd by bam_plp_init.
 * 
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_free_pileup_iter", 0);
  __Pyx_TraceCall("_free_pileup_iter", __pyx_f[0], 2671, 0, __PYX_ERR(0, 2671, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2676
 *         This is needed before setup_iterator allocates another
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)
 */
  __pyx_t_1 = ((__pyx_v_self->pileup_iter != ((bam_mplp_t)NULL)) != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2677
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2678
 *         if self.pileup_iter != <bam_mplp_t>NULL:
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 *                 bam_mplp_destroy(self.pileup_iter)
 *                 self.pileup_iter = <bam_mplp_t>NULL
 */
          bam_mplp_reset(__pyx_v_self->pileup_iter);

          /* "pysam/libcalignmentfile.pyx":2679
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = <bam_mplp_t>NULL
 * 
 */
          bam_mplp_destroy(__pyx_v_self->pileup_iter);

          /* "pysam/libcalignmentfile.pyx":2680
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)
 *                 self.pileup_iter = <bam_mplp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
          __pyx_v_self->pileup_iter = ((bam_mplp_t)NULL);
        }

        /* "pysam/libcalignmentfile.pyx":2677
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L6;
          }
          __pyx_L6:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2676
 *         This is needed before setup_iterator allocates another
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2671
 *             bam_mplp_reset(self.pileup_iter)
 * 
 *     cdef _free_pileup_iter(self):             # <<<<<<<<<<<<<<
 *         '''free the memory alloc'd by bam_plp_init.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn._free_pileup_iter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2682
 *                 self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     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_17libcalignmentfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

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

static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2682, 0, __PYX_ERR(0, 2682, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2685
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 *         self.plp = <const bam_pileup1_t*>NULL
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2686
 *         # that have not been fully consumed
 *         self._free_pileup_iter()
 *         self.plp = <const bam_pileup1_t*>NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.iterdata.seq != NULL:
 */
  __pyx_v_self->plp = ((bam_pileup1_t const *)NULL);

  /* "pysam/libcalignmentfile.pyx":2688
 *         self.plp = <const bam_pileup1_t*>NULL
 * 
 *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
  __pyx_t_2 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":2689
 * 
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 * 
 */
    free(__pyx_v_self->iterdata.seq);

    /* "pysam/libcalignmentfile.pyx":2690
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 * 
 *     # backwards compatibility
 */
    __pyx_v_self->iterdata.seq = NULL;

    /* "pysam/libcalignmentfile.pyx":2688
 *         self.plp = <const bam_pileup1_t*>NULL
 * 
 *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":2682
 *                 self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 */

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

/* "pysam/libcalignmentfile.pyx":2694
 *     # backwards compatibility
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference[] = "IteratorColumn.hasReference(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("hasReference (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("hasReference", 0);
  __Pyx_TraceCall("hasReference", __pyx_f[0], 2694, 0, __PYX_ERR(0, 2694, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2695
 * 
 *     def hasReference(self):
 *         return self.has_reference()             # <<<<<<<<<<<<<<
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_reference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2694
 *     # backwards compatibility
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 */

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

/* "pysam/libcalignmentfile.pyx":2696
 *     def hasReference(self):
 *         return self.has_reference()
 *     cdef char * getSequence(self):             # <<<<<<<<<<<<<<
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):
 */

static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  char *__pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getSequence", 0);
  __Pyx_TraceCall("getSequence", __pyx_f[0], 2696, 0, __PYX_ERR(0, 2696, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2697
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 *         return self.get_sequence()             # <<<<<<<<<<<<<<
 *     def addReference(self, FastaFile fastafile):
 *         return self.add_reference(fastafile)
 */
  __pyx_r = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->get_sequence(__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2696
 *     def hasReference(self):
 *         return self.has_reference()
 *     cdef char * getSequence(self):             # <<<<<<<<<<<<<<
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.getSequence", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2698
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *         return self.add_reference(fastafile)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference[] = "IteratorColumn.addReference(self, FastaFile fastafile)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  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_9libcfaidx_FastaFile, 1, "fastafile", 0))) __PYX_ERR(0, 2698, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_9libcfaidx_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_17libcalignmentfile_14IteratorColumn_12addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("addReference", 0);
  __Pyx_TraceCall("addReference", __pyx_f[0], 2698, 0, __PYX_ERR(0, 2698, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2699
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):
 *         return self.add_reference(fastafile)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_reference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_v_fastafile)) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_fastafile));
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2698
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *         return self.add_reference(fastafile)
 * 
 */

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

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__[] = "IteratorColumn.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__[] = "IteratorColumn.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

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

/* "pysam/libcalignmentfile.pyx":2705
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   int tid = 0,
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_start;
  int __pyx_v_stop;
  int __pyx_v_truncate;
  int __pyx_v_multiple_iterators;
  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_stop,&__pyx_n_s_truncate,&__pyx_n_s_multiple_iterators,0};
    PyObject* values[6] = {0,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  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          if (value) { values[5] = 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_ERR(0, 2705, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2707, __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_ERR(0, 2708, __pyx_L3_error)
    } else {
      __pyx_v_start = ((int)0);
    }
    if (values[3]) {
      __pyx_v_stop = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_stop == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2709, __pyx_L3_error)
    } else {
      __pyx_v_stop = __pyx_k__61;
    }
    if (values[4]) {
      __pyx_v_truncate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2710, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2710
 *                   int start = 0,
 *                   int stop = MAX_POS,
 *                   int truncate = False,             # <<<<<<<<<<<<<<
 *                   int multiple_iterators = True,
 *                   **kwargs ):
 */
      __pyx_v_truncate = ((int)0);
    }
    if (values[5]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2711, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2711
 *                   int stop = MAX_POS,
 *                   int truncate = False,
 *                   int multiple_iterators = True,             # <<<<<<<<<<<<<<
 *                   **kwargs ):
 * 
 */
      __pyx_v_multiple_iterators = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2705, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2706, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_stop, __pyx_v_truncate, __pyx_v_multiple_iterators, __pyx_v_kwargs);

  /* "pysam/libcalignmentfile.pyx":2705
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   int tid = 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_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, int __pyx_v_truncate, int __pyx_v_multiple_iterators, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __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;
  struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2705, 0, __PYX_ERR(0, 2705, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2716
 *         # initialize iterator. Multiple iterators not available
 *         # for CRAM.
 *         if multiple_iterators and samfile.is_cram:             # <<<<<<<<<<<<<<
 *             warnings.warn("multiple_iterators not implemented for CRAM")
 *             multiple_iterators = False
 */
  __pyx_t_2 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2716, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2716, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2717
 *         # for CRAM.
 *         if multiple_iterators and samfile.is_cram:
 *             warnings.warn("multiple_iterators not implemented for CRAM")             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_warnings); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2717, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2717, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_s_multiple_iterators_not_implement_2) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_s_multiple_iterators_not_implement_2);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2717, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":2718
 *         if multiple_iterators and samfile.is_cram:
 *             warnings.warn("multiple_iterators not implemented for CRAM")
 *             multiple_iterators = False             # <<<<<<<<<<<<<<
 * 
 *         self._setup_iterator(tid, start, stop, multiple_iterators)
 */
    __pyx_v_multiple_iterators = 0;

    /* "pysam/libcalignmentfile.pyx":2716
 *         # initialize iterator. Multiple iterators not available
 *         # for CRAM.
 *         if multiple_iterators and samfile.is_cram:             # <<<<<<<<<<<<<<
 *             warnings.warn("multiple_iterators not implemented for CRAM")
 *             multiple_iterators = False
 */
  }

  /* "pysam/libcalignmentfile.pyx":2720
 *             multiple_iterators = False
 * 
 *         self._setup_iterator(tid, start, stop, multiple_iterators)             # <<<<<<<<<<<<<<
 *         self.start = start
 *         self.stop = stop
 */
  __pyx_t_6.__pyx_n = 1;
  __pyx_t_6.multiple_iterators = __pyx_v_multiple_iterators;
  __pyx_t_3 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_stop, &__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2720, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/libcalignmentfile.pyx":2721
 * 
 *         self._setup_iterator(tid, start, stop, multiple_iterators)
 *         self.start = start             # <<<<<<<<<<<<<<
 *         self.stop = stop
 *         self.truncate = truncate
 */
  __pyx_v_self->start = __pyx_v_start;

  /* "pysam/libcalignmentfile.pyx":2722
 *         self._setup_iterator(tid, start, stop, multiple_iterators)
 *         self.start = start
 *         self.stop = stop             # <<<<<<<<<<<<<<
 *         self.truncate = truncate
 * 
 */
  __pyx_v_self->stop = __pyx_v_stop;

  /* "pysam/libcalignmentfile.pyx":2723
 *         self.start = start
 *         self.stop = stop
 *         self.truncate = truncate             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_v_self->truncate = __pyx_v_truncate;

  /* "pysam/libcalignmentfile.pyx":2705
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   int tid = 0,
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2725
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self) {
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2725, 0, __PYX_ERR(0, 2725, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2729
 *         cdef int n
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             n = self.cnext()
 *             if n < 0:
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2730
 * 
 *         while 1:
 *             n = self.cnext()             # <<<<<<<<<<<<<<
 *             if n < 0:
 *                 raise ValueError("error during iteration" )
 */
    __pyx_v_n = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

    /* "pysam/libcalignmentfile.pyx":2731
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    __pyx_t_1 = ((__pyx_v_n < 0) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":2732
 *             n = self.cnext()
 *             if n < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if n == 0:
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2732, __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_ERR(0, 2732, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2731
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2734
 *                 raise ValueError("error during iteration" )
 * 
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 * 
 */
    __pyx_t_1 = ((__pyx_v_n == 0) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":2735
 * 
 *             if n == 0:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             if self.truncate:
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      __PYX_ERR(0, 2735, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2734
 *                 raise ValueError("error during iteration" )
 * 
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2737
 *                 raise StopIteration
 * 
 *             if self.truncate:             # <<<<<<<<<<<<<<
 *                 if self.start > self.pos:
 *                     continue
 */
    __pyx_t_1 = (__pyx_v_self->truncate != 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2738
 * 
 *             if self.truncate:
 *                 if self.start > self.pos:             # <<<<<<<<<<<<<<
 *                     continue
 *                 if self.pos >= self.stop:
 */
      __pyx_t_1 = ((__pyx_v_self->start > __pyx_v_self->__pyx_base.pos) != 0);
      if (__pyx_t_1) {

        /* "pysam/libcalignmentfile.pyx":2739
 *             if self.truncate:
 *                 if self.start > self.pos:
 *                     continue             # <<<<<<<<<<<<<<
 *                 if self.pos >= self.stop:
 *                     raise StopIteration
 */
        goto __pyx_L3_continue;

        /* "pysam/libcalignmentfile.pyx":2738
 * 
 *             if self.truncate:
 *                 if self.start > self.pos:             # <<<<<<<<<<<<<<
 *                     continue
 *                 if self.pos >= self.stop:
 */
      }

      /* "pysam/libcalignmentfile.pyx":2740
 *                 if self.start > self.pos:
 *                     continue
 *                 if self.pos >= self.stop:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 * 
 */
      __pyx_t_1 = ((__pyx_v_self->__pyx_base.pos >= __pyx_v_self->stop) != 0);
      if (unlikely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":2741
 *                     continue
 *                 if self.pos >= self.stop:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             return makePileupColumn(&self.plp,
 */
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        __PYX_ERR(0, 2741, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":2740
 *                 if self.start > self.pos:
 *                     continue
 *                 if self.pos >= self.stop:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":2737
 *                 raise StopIteration
 * 
 *             if self.truncate:             # <<<<<<<<<<<<<<
 *                 if self.start > self.pos:
 *                     continue
 */
    }

    /* "pysam/libcalignmentfile.pyx":2743
 *                     raise StopIteration
 * 
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/libcalignmentfile.pyx":2749
 *                                     self.min_base_quality,
 *                                     self.iterdata.seq,
 *                                     self.samfile.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header);
    __Pyx_INCREF(__pyx_t_2);

    /* "pysam/libcalignmentfile.pyx":2743
 *                     raise StopIteration
 * 
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__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, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2743, __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;
    goto __pyx_L0;
    __pyx_L3_continue:;
  }

  /* "pysam/libcalignmentfile.pyx":2725
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

  /* 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_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__[] = "IteratorColumnRegion.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__[] = "IteratorColumnRegion.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

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

/* "pysam/libcalignmentfile.pyx":2756
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__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_ERR(0, 2756, __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_17libcalignmentfile_AlignmentFile *)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2756, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2757, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_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_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2756, 0, __PYX_ERR(0, 2756, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2761
 * 
 *         # 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_ERR(0, 2761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2761, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":2762
 *         # no iteration over empty files
 *         if not samfile.nreferences:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         # initialize iterator
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2762, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2761
 * 
 *         # no iteration over empty files
 *         if not samfile.nreferences:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2765
 * 
 *         # initialize iterator
 *         self._setup_iterator(self.tid, 0, MAX_POS, 1)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.multiple_iterators = 1;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2756
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2767
 *         self._setup_iterator(self.tid, 0, MAX_POS, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self) {
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2767, 0, __PYX_ERR(0, 2767, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2770
 * 
 *         cdef int n
 *         while 1:             # <<<<<<<<<<<<<<
 *             n = self.cnext()
 *             if n < 0:
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2771
 *         cdef int n
 *         while 1:
 *             n = self.cnext()             # <<<<<<<<<<<<<<
 *             if n < 0:
 *                 raise ValueError("error during iteration")
 */
    __pyx_v_n = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

    /* "pysam/libcalignmentfile.pyx":2772
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration")
 * 
 */
    __pyx_t_1 = ((__pyx_v_n < 0) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":2773
 *             n = self.cnext()
 *             if n < 0:
 *                 raise ValueError("error during iteration")             # <<<<<<<<<<<<<<
 * 
 *             # proceed to next reference or stop
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2773, __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_ERR(0, 2773, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2772
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2776
 * 
 *             # proceed to next reference or stop
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:
 */
    __pyx_t_1 = ((__pyx_v_n == 0) != 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2777
 *             # proceed to next reference or stop
 *             if n == 0:
 *                 self.tid += 1             # <<<<<<<<<<<<<<
 *                 if self.tid < self.samfile.nreferences:
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 */
      __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1);

      /* "pysam/libcalignmentfile.pyx":2778
 *             if n == 0:
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                     self._setup_iterator(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_ERR(0, 2778, __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_ERR(0, 2778, __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_ERR(0, 2778, __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_ERR(0, 2778, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (likely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":2779
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise StopIteration
 */
        __pyx_t_5.__pyx_n = 1;
        __pyx_t_5.multiple_iterators = 0;
        __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2779, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "pysam/libcalignmentfile.pyx":2778
 *             if n == 0:
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 *                 else:
 */
        goto __pyx_L7;
      }

      /* "pysam/libcalignmentfile.pyx":2781
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 *                 else:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 *                 continue
 * 
 */
      /*else*/ {
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        __PYX_ERR(0, 2781, __pyx_L1_error)
      }
      __pyx_L7:;

      /* "pysam/libcalignmentfile.pyx":2782
 *                 else:
 *                     raise StopIteration
 *                 continue             # <<<<<<<<<<<<<<
 * 
 *             # return result, if within same reference
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2776
 * 
 *             # proceed to next reference or stop
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2785
 * 
 *             # return result, if within same reference
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/libcalignmentfile.pyx":2791
 *                                     self.min_base_quality,
 *                                     self.iterdata.seq,
 *                                     self.samfile.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_4 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header);
    __Pyx_INCREF(__pyx_t_4);

    /* "pysam/libcalignmentfile.pyx":2785
 * 
 *             # return result, if within same reference
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__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, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2785, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    __pyx_L3_continue:;
  }

  /* "pysam/libcalignmentfile.pyx":2767
 *         self._setup_iterator(self.tid, 0, MAX_POS, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

  /* 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.libcalignmentfile.IteratorColumnAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__[] = "IteratorColumnAllRefs.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__[] = "IteratorColumnAllRefs.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

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

/* "pysam/libcalignmentfile.pyx":2798
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__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);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__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_ERR(0, 2798, __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_17libcalignmentfile_AlignmentFile *)values[0]);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2798, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2799, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__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_17libcalignmentfile_17IteratorColumnAll___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2798, 0, __PYX_ERR(0, 2798, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2802
 *                   **kwargs):
 * 
 *         self._setup_raw_rest_iterator()             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_raw_rest_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2798
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2804
 *         self._setup_raw_rest_iterator()
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_2__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self) {
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2804, 0, __PYX_ERR(0, 2804, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2807
 * 
 *         cdef int n
 *         n = self.cnext()             # <<<<<<<<<<<<<<
 *         if n < 0:
 *             raise ValueError("error during iteration")
 */
  __pyx_v_n = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* "pysam/libcalignmentfile.pyx":2808
 *         cdef int n
 *         n = self.cnext()
 *         if n < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("error during iteration")
 * 
 */
  __pyx_t_1 = ((__pyx_v_n < 0) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2809
 *         n = self.cnext()
 *         if n < 0:
 *             raise ValueError("error during iteration")             # <<<<<<<<<<<<<<
 * 
 *         if n == 0:
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2809, __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_ERR(0, 2809, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2808
 *         cdef int n
 *         n = self.cnext()
 *         if n < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("error during iteration")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2811
 *             raise ValueError("error during iteration")
 * 
 *         if n == 0:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = ((__pyx_v_n == 0) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2812
 * 
 *         if n == 0:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         return makePileupColumn(&self.plp,
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2812, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2811
 *             raise ValueError("error during iteration")
 * 
 *         if n == 0:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2814
 *             raise StopIteration
 * 
 *         return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                 self.tid,
 *                                 self.pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/libcalignmentfile.pyx":2820
 *                                 self.min_base_quality,
 *                                 self.iterdata.seq,
 *                                 self.samfile.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header);
  __Pyx_INCREF(__pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":2814
 *             raise StopIteration
 * 
 *         return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                 self.tid,
 *                                 self.pos,
 */
  __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__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, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2814, __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;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2804
 *         self._setup_raw_rest_iterator()
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

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

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__[] = "IteratorColumnAll.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__[] = "IteratorColumnAll.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */

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

/* "pysam/libcalignmentfile.pyx":2836
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2836, 0, __PYX_ERR(0, 2836, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2837
 *         '''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_ERR(0, 2837, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2836
 *     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.libcalignmentfile.SNPCall.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2841
 *     property pos:
 *        '''nucleotide position of SNP.'''
 *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
 * 
 *     property reference_base:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2841, 0, __PYX_ERR(0, 2841, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2841, __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.libcalignmentfile.SNPCall.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2845
 *     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_17libcalignmentfile_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_7SNPCall_14reference_base___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2845, 0, __PYX_ERR(0, 2845, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2845, __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.libcalignmentfile.SNPCall.reference_base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2849
 *     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_17libcalignmentfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2849, 0, __PYX_ERR(0, 2849, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2849, __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.libcalignmentfile.SNPCall.genotype.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2853
 *     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_17libcalignmentfile_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_7SNPCall_17consensus_quality___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2853, 0, __PYX_ERR(0, 2853, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2853, __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.libcalignmentfile.SNPCall.consensus_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2858
 *        '''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_17libcalignmentfile_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_7SNPCall_11snp_quality___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2858, 0, __PYX_ERR(0, 2858, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2858, __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.libcalignmentfile.SNPCall.snp_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2863
 *        '''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_17libcalignmentfile_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_7SNPCall_15mapping_quality___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2863, 0, __PYX_ERR(0, 2863, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2863, __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.libcalignmentfile.SNPCall.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2867
 *     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_17libcalignmentfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2867, 0, __PYX_ERR(0, 2867, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2867, __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.libcalignmentfile.SNPCall.coverage.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2869
 *        def __get__(self): return self._coverage
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( map(str, (
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_1__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_1__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 2869, 0, __PYX_ERR(0, 2869, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2871
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/libcalignmentfile.pyx":2872
 * 
 *         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_ERR(0, 2872, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":2873
 *         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_ERR(0, 2873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":2874
 *                     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_ERR(0, 2874, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/libcalignmentfile.pyx":2875
 *                     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_ERR(0, 2875, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/libcalignmentfile.pyx":2876
 *                     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_ERR(0, 2876, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/libcalignmentfile.pyx":2877
 *                     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_ERR(0, 2877, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/libcalignmentfile.pyx":2878
 *                     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_ERR(0, 2878, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/libcalignmentfile.pyx":2879
 *                     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_ERR(0, 2879, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/libcalignmentfile.pyx":2872
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2872, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 7, __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/libcalignmentfile.pyx":2871
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2871, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __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_ERR(0, 2871, __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__2, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2871, __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/libcalignmentfile.pyx":2869
 *        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.libcalignmentfile.SNPCall.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__[] = "SNPCall.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_v__dict = 0;
  int __pyx_v_use_setstate;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":5
 *     cdef object _dict
 *     cdef bint use_setstate
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)             # <<<<<<<<<<<<<<
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_char(__pyx_v_self->_genotype); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_char(__pyx_v_self->_reference_base); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 7, __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;
  __pyx_v_state = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "(tree fragment)":6
 *     cdef bint use_setstate
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)
 *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
 *     if _dict is not None:
 *         state += (_dict,)
 */
  __pyx_t_9 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_v__dict = __pyx_t_9;
  __pyx_t_9 = 0;

  /* "(tree fragment)":7
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
  __pyx_t_10 = (__pyx_v__dict != Py_None);
  __pyx_t_11 = (__pyx_t_10 != 0);
  if (__pyx_t_11) {

    /* "(tree fragment)":8
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 *         state += (_dict,)             # <<<<<<<<<<<<<<
 *         use_setstate = True
 *     else:
 */
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v__dict);
    __Pyx_GIVEREF(__pyx_v__dict);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v__dict);
    __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "(tree fragment)":9
 *     if _dict is not None:
 *         state += (_dict,)
 *         use_setstate = True             # <<<<<<<<<<<<<<
 *     else:
 *         use_setstate = False
 */
    __pyx_v_use_setstate = 1;

    /* "(tree fragment)":7
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
    goto __pyx_L3;
  }

  /* "(tree fragment)":11
 *         use_setstate = True
 *     else:
 *         use_setstate = False             # <<<<<<<<<<<<<<
 *     if use_setstate:
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, None), state
 */
  /*else*/ {
    __pyx_v_use_setstate = 0;
  }
  __pyx_L3:;

  /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, None), state
 *     else:
 */
  __pyx_t_11 = (__pyx_v_use_setstate != 0);
  if (__pyx_t_11) {

    /* "(tree fragment)":13
 *         use_setstate = False
 *     if use_setstate:
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, None), state             # <<<<<<<<<<<<<<
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, state)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pyx_unpickle_SNPCall); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_84615809);
    __Pyx_GIVEREF(__pyx_int_84615809);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_84615809);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_9, 2, Py_None);
    __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_9);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_state);
    __pyx_t_8 = 0;
    __pyx_t_9 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, None), state
 *     else:
 */
  }

  /* "(tree fragment)":15
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, None), state
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, state)             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pyx_unpickle_SNPCall); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_84615809);
    __Pyx_GIVEREF(__pyx_int_84615809);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_84615809);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_state);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_r = __pyx_t_8;
    __pyx_t_8 = 0;
    goto __pyx_L0;
  }

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

  /* 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.libcalignmentfile.SNPCall.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_state);
  __Pyx_XDECREF(__pyx_v__dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__[] = "SNPCall.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 16, 0, __PYX_ERR(1, 16, __pyx_L1_error));

  /* "(tree fragment)":17
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, state)
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
 */
  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0x50b2281, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2904
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_multiple_iterators;
  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_multiple_iterators,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators);
          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_ERR(0, 2904, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2904, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)1);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2904, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.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_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2904, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

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

static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  char *__pyx_v_cfilename;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  char *__pyx_t_3;
  htsFile *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2904, 0, __PYX_ERR(0, 2904, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2909
 *         # makes sure that samfile stays alive as long as this
 *         # object is alive.
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 *         cdef bam_hdr_t * hdr = NULL
 *         assert samfile.is_bam, "can only apply 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/libcalignmentfile.pyx":2910
 *         # object is alive.
 *         self.samfile = samfile
 *         cdef bam_hdr_t * hdr = NULL             # <<<<<<<<<<<<<<
 *         assert samfile.is_bam, "can only apply IndexReads on bam files"
 * 
 */
  __pyx_v_hdr = NULL;

  /* "pysam/libcalignmentfile.pyx":2911
 *         self.samfile = samfile
 *         cdef bam_hdr_t * hdr = NULL
 *         assert samfile.is_bam, "can only apply IndexReads on bam files"             # <<<<<<<<<<<<<<
 * 
 *         # multiple_iterators the file - note that this makes the iterator
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2911, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_can_only_apply_IndexReads_on_bam);
      __PYX_ERR(0, 2911, __pyx_L1_error)
    }
  }
  #endif

  /* "pysam/libcalignmentfile.pyx":2915
 *         # multiple_iterators the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 *             cfilename = samfile.filename
 *             with nogil:
 */
  __pyx_t_2 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":2916
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:
 *             cfilename = samfile.filename             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 */
    __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 2916, __pyx_L1_error)
    __pyx_v_cfilename = __pyx_t_3;

    /* "pysam/libcalignmentfile.pyx":2917
 *         if multiple_iterators:
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2918
 *             cfilename = samfile.filename
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')             # <<<<<<<<<<<<<<
 *             if self.htsfile == NULL:
 *                 raise OSError("unable to reopen htsfile")
 */
          __pyx_v_self->htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r"));
        }

        /* "pysam/libcalignmentfile.pyx":2917
 *         if multiple_iterators:
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L6;
          }
          __pyx_L6:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2919
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to reopen htsfile")
 * 
 */
    __pyx_t_2 = ((__pyx_v_self->htsfile == NULL) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2920
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 *                 raise OSError("unable to reopen htsfile")             # <<<<<<<<<<<<<<
 * 
 *             # need to advance in newly opened file to position after header
 */
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2920, __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_ERR(0, 2920, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2919
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to reopen htsfile")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2924
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2925
 *             # better: use seek/tell?
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             if hdr == NULL:
 *                 raise OSError("unable to read header information")
 */
          __pyx_v_hdr = sam_hdr_read(__pyx_v_self->htsfile);
        }

        /* "pysam/libcalignmentfile.pyx":2924
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L10;
          }
          __pyx_L10:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2926
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    __pyx_t_2 = ((__pyx_v_hdr == NULL) != 0);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2927
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:
 *                 raise OSError("unable to read header information")             # <<<<<<<<<<<<<<
 *             self.header = makeAlignmentHeader(hdr)
 *             self.owns_samfile = True
 */
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2927, __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_ERR(0, 2927, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2926
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    }

    /* "pysam/libcalignmentfile.pyx":2928
 *             if hdr == NULL:
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 *             self.owns_samfile = True
 *         else:
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF(__pyx_v_self->header);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":2929
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 *         else:
 *             self.htsfile = self.samfile.htsfile
 */
    __pyx_v_self->owns_samfile = 1;

    /* "pysam/libcalignmentfile.pyx":2915
 *         # multiple_iterators the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 *             cfilename = samfile.filename
 *             with nogil:
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":2931
 *             self.owns_samfile = True
 *         else:
 *             self.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.header = samfile.header
 *             self.owns_samfile = False
 */
  /*else*/ {
    __pyx_t_4 = __pyx_v_self->samfile->__pyx_base.htsfile;
    __pyx_v_self->htsfile = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":2932
 *         else:
 *             self.htsfile = self.samfile.htsfile
 *             self.header = samfile.header             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 * 
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_samfile->header);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF(__pyx_v_self->header);
    __Pyx_DECREF(((PyObject *)__pyx_v_self->header));
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":2933
 *             self.htsfile = self.samfile.htsfile
 *             self.header = samfile.header
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *     def build(self):
 */
    __pyx_v_self->owns_samfile = 0;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":2904
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2935
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build the index.'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_3build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_2build[] = "IndexedReads.build(self)\nbuild the index.";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_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_17libcalignmentfile_12IndexedReads_2build(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self) {
  int __pyx_v_ret;
  bam1_t *__pyx_v_b;
  uint64_t __pyx_v_pos;
  bam_hdr_t *__pyx_v_hdr;
  PyObject *__pyx_v_qname = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  bam_hdr_t *__pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("build", 0);
  __Pyx_TraceCall("build", __pyx_f[0], 2935, 0, __PYX_ERR(0, 2935, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2938
 *         '''build the index.'''
 * 
 *         self.index = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 * 
 *         # this method will start indexing from the current file position
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2938, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2938, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)(&PyList_Type)));
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2938, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->index);
  __Pyx_DECREF(__pyx_v_self->index);
  __pyx_v_self->index = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2941
 * 
 *         # this method will start indexing from the current file position
 *         cdef int ret = 1             # <<<<<<<<<<<<<<
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:
 */
  __pyx_v_ret = 1;

  /* "pysam/libcalignmentfile.pyx":2942
 *         # this method will start indexing from the current file position
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))             # <<<<<<<<<<<<<<
 *         if b == NULL:
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))
 */
  __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/libcalignmentfile.pyx":2943
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))
 * 
 */
  __pyx_t_4 = ((__pyx_v_b == NULL) != 0);
  if (unlikely(__pyx_t_4)) {

    /* "pysam/libcalignmentfile.pyx":2944
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))             # <<<<<<<<<<<<<<
 * 
 *         cdef uint64_t pos
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2944, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2944, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2943
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2947
 * 
 *         cdef uint64_t pos
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 * 
 *         while ret > 0:
 */
  __pyx_t_6 = __pyx_v_self->header->ptr;
  __pyx_v_hdr = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":2949
 *         cdef bam_hdr_t * hdr = self.header.ptr
 * 
 *         while ret > 0:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 */
  while (1) {
    __pyx_t_4 = ((__pyx_v_ret > 0) != 0);
    if (!__pyx_t_4) break;

    /* "pysam/libcalignmentfile.pyx":2950
 * 
 *         while ret > 0:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *                 ret = sam_read1(self.htsfile,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2951
 *         while ret > 0:
 *             with nogil:
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))             # <<<<<<<<<<<<<<
 *                 ret = sam_read1(self.htsfile,
 *                                 hdr,
 */
          __pyx_v_pos = bgzf_tell(hts_get_bgzfp(__pyx_v_self->htsfile));

          /* "pysam/libcalignmentfile.pyx":2952
 *             with nogil:
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *                 ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                                 hdr,
 *                                 b)
 */
          __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_hdr, __pyx_v_b);
        }

        /* "pysam/libcalignmentfile.pyx":2950
 * 
 *         while ret > 0:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *                 ret = sam_read1(self.htsfile,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L10;
          }
          __pyx_L10:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2956
 *                                 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/libcalignmentfile.pyx":2957
 * 
 *             if ret > 0:
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))             # <<<<<<<<<<<<<<
 *                 self.index[qname].append(pos)
 * 
 */
      __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(pysam_bam_get_qname(__pyx_v_b), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2957, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_qname, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/libcalignmentfile.pyx":2958
 *             if ret > 0:
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)             # <<<<<<<<<<<<<<
 * 
 *         bam_destroy1(b)
 */
      __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2958, __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_ERR(0, 2958, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 2958, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":2956
 *                                 b)
 * 
 *             if ret > 0:             # <<<<<<<<<<<<<<
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)
 */
    }
  }

  /* "pysam/libcalignmentfile.pyx":2960
 *                 self.index[qname].append(pos)
 * 
 *         bam_destroy1(b)             # <<<<<<<<<<<<<<
 * 
 *     def find(self, query_name):
 */
  bam_destroy1(__pyx_v_b);

  /* "pysam/libcalignmentfile.pyx":2935
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build the 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_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.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, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2962
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find `query_name` in index.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_query_name); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find[] = "IndexedReads.find(self, query_name)\nfind `query_name` in index.\n\n        Returns\n        -------\n\n        IteratorRowSelection\n            Returns an iterator over all reads with query_name.\n\n        Raises\n        ------\n\n        KeyError\n            if the `query_name` is not in the index.\n\n        ";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_query_name) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), ((PyObject *)__pyx_v_query_name));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_query_name) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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_RefNannySetupContext("find", 0);
  __Pyx_TraceCall("find", __pyx_f[0], 2962, 0, __PYX_ERR(0, 2962, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2978
 * 
 *         '''
 *         if query_name in self.index:             # <<<<<<<<<<<<<<
 *             return IteratorRowSelection(
 *                 self.samfile,
 */
  __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_query_name, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2978, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (likely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2979
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/libcalignmentfile.pyx":2981
 *             return IteratorRowSelection(
 *                 self.samfile,
 *                 self.index[query_name],             # <<<<<<<<<<<<<<
 *                 multiple_iterators = False)
 *         else:
 */
    __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2981, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/libcalignmentfile.pyx":2979
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2979, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self->samfile));
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":2982
 *                 self.samfile,
 *                 self.index[query_name],
 *                 multiple_iterators = False)             # <<<<<<<<<<<<<<
 *         else:
 *             raise KeyError("read %s not found" % query_name)
 */
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2982, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, Py_False) < 0) __PYX_ERR(0, 2982, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2979
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection), __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2979, __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;

    /* "pysam/libcalignmentfile.pyx":2978
 * 
 *         '''
 *         if query_name in self.index:             # <<<<<<<<<<<<<<
 *             return IteratorRowSelection(
 *                 self.samfile,
 */
  }

  /* "pysam/libcalignmentfile.pyx":2984
 *                 multiple_iterators = False)
 *         else:
 *             raise KeyError("read %s not found" % query_name)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  /*else*/ {
    __pyx_t_5 = __Pyx_PyString_FormatSafe(__pyx_kp_s_read_s_not_found, __pyx_v_query_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2984, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2984, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2984, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2962
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find `query_name` in index.
 * 
 */

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

/* "pysam/libcalignmentfile.pyx":2986
 *             raise KeyError("read %s not found" % query_name)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self));

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

static void __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2986, 0, __PYX_ERR(0, 2986, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2987
 * 
 *     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/libcalignmentfile.pyx":2988
 *     def __dealloc__(self):
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 */
    (void)(hts_close(__pyx_v_self->htsfile));

    /* "pysam/libcalignmentfile.pyx":2987
 * 
 *     def __dealloc__(self):
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2986
 *             raise KeyError("read %s not found" % query_name)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IndexedReads.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__[] = "IndexedReads.__reduce_cython__(self)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__70, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __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_ERR(1, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 */

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

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__[] = "IndexedReads.__setstate_cython__(self, __pyx_state)";
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__71, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __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_ERR(1, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 */

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

/* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall[] = "__pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state)";
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall = {"__pyx_unpickle_SNPCall", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v___pyx_type = 0;
  long __pyx_v___pyx_checksum;
  PyObject *__pyx_v___pyx_state = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SNPCall", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SNPCall", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_SNPCall") < 0)) __PYX_ERR(1, 1, __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___pyx_type = values[0];
    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error)
    __pyx_v___pyx_state = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SNPCall", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.__pyx_unpickle_SNPCall", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);

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

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_v___pyx_PickleError = 0;
  PyObject *__pyx_v___pyx_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__72)
  __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall", 0);
  __Pyx_TraceCall("__pyx_unpickle_SNPCall", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error));

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum != 0x50b2281:             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)
 */
  __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x50b2281) != 0);
  if (__pyx_t_1) {

    /* "(tree fragment)":5
 *     cdef object __pyx_result
 *     if __pyx_checksum != 0x50b2281:
 *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 */
    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_n_s_PickleError);
    __Pyx_GIVEREF(__pyx_n_s_PickleError);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_v___pyx_PickleError = __pyx_t_2;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "(tree fragment)":6
 *     if __pyx_checksum != 0x50b2281:
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)             # <<<<<<<<<<<<<<
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:
 */
    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x50, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_v___pyx_PickleError);
    __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(1, 6, __pyx_L1_error)

    /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum != 0x50b2281:             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)
 */
  }

  /* "(tree fragment)":7
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)
 *     __pyx_result = SNPCall.__new__(__pyx_type)             # <<<<<<<<<<<<<<
 *     if __pyx_state is not None:
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_SNPCall), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v___pyx_result = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  __pyx_t_1 = (__pyx_v___pyx_state != Py_None);
  __pyx_t_6 = (__pyx_t_1 != 0);
  if (__pyx_t_6) {

    /* "(tree fragment)":9
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 */
    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error)
    __pyx_t_3 = __pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum)
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  }

  /* "(tree fragment)":10
 *     if __pyx_state is not None:
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result             # <<<<<<<<<<<<<<
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v___pyx_result);
  __pyx_r = __pyx_v___pyx_result;
  goto __pyx_L0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.__pyx_unpickle_SNPCall", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
  __Pyx_XDECREF(__pyx_v___pyx_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":11
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  char __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall__set_state", 0);
  __Pyx_TraceCall("__pyx_unpickle_SNPCall__set_state", __pyx_f[1], 11, 0, __PYX_ERR(1, 11, __pyx_L1_error));

  /* "(tree fragment)":12
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]             # <<<<<<<<<<<<<<
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[8])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __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_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_consensus_quality = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __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_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_coverage = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_As_char(__pyx_t_1); if (unlikely((__pyx_t_3 == (char)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_genotype = __pyx_t_3;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __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_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_pos = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_As_char(__pyx_t_1); if (unlikely((__pyx_t_3 == (char)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_reference_base = __pyx_t_3;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __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_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_rms_mapping_quality = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __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_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_snp_quality = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __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_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_tid = __pyx_t_2;

  /* "(tree fragment)":13
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[8])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 13, __pyx_L1_error)
  }
  __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_6 = ((__pyx_t_5 > 8) != 0);
  if (__pyx_t_6) {
  } else {
    __pyx_t_4 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_7 = (__pyx_t_6 != 0);
  __pyx_t_4 = __pyx_t_7;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_4) {

    /* "(tree fragment)":14
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[8])             # <<<<<<<<<<<<<<
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(__pyx_v___pyx_state == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(1, 14, __pyx_L1_error)
    }
    __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":13
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[8])
 */
  }

  /* "(tree fragment)":11
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 */

  /* 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_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.libcalignmentfile.__pyx_unpickle_SNPCall__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":93
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) {
  PyObject *__pyx_v_item_count = NULL;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  char __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (__pyx_v_info == NULL) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);
  __Pyx_TraceCall("__getbuffer__", __pyx_f[3], 93, 0, __PYX_ERR(3, 93, __pyx_L1_error));

  /* "array.pxd":98
 *             # In particular strided access is always provided regardless
 *             # of flags
 *             item_count = Py_SIZE(self)             # <<<<<<<<<<<<<<
 * 
 *             info.suboffsets = NULL
 */
  __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 98, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_item_count = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "array.pxd":100
 *             item_count = Py_SIZE(self)
 * 
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 */
  __pyx_v_info->suboffsets = NULL;

  /* "array.pxd":101
 * 
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars             # <<<<<<<<<<<<<<
 *             info.readonly = 0
 *             info.ndim = 1
 */
  __pyx_t_2 = __pyx_v_self->data.as_chars;
  __pyx_v_info->buf = __pyx_t_2;

  /* "array.pxd":102
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars
 *             info.readonly = 0             # <<<<<<<<<<<<<<
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 */
  __pyx_v_info->readonly = 0;

  /* "array.pxd":103
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 *             info.ndim = 1             # <<<<<<<<<<<<<<
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count
 */
  __pyx_v_info->ndim = 1;

  /* "array.pxd":104
 *             info.readonly = 0
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)             # <<<<<<<<<<<<<<
 *             info.len = info.itemsize * item_count
 * 
 */
  __pyx_t_3 = __pyx_v_self->ob_descr->itemsize;
  __pyx_v_info->itemsize = __pyx_t_3;

  /* "array.pxd":105
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count             # <<<<<<<<<<<<<<
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 */
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(3, 105, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_info->len = __pyx_t_5;

  /* "array.pxd":107
 *             info.len = info.itemsize * item_count
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)             # <<<<<<<<<<<<<<
 *             if not info.shape:
 *                 raise MemoryError()
 */
  __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2)));

  /* "array.pxd":108
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
  __pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "array.pxd":109
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:
 *                 raise MemoryError()             # <<<<<<<<<<<<<<
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize
 */
    PyErr_NoMemory(); __PYX_ERR(3, 109, __pyx_L1_error)

    /* "array.pxd":108
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
  }

  /* "array.pxd":110
 *             if not info.shape:
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing             # <<<<<<<<<<<<<<
 *             info.strides = &info.itemsize
 * 
 */
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(3, 110, __pyx_L1_error)
  (__pyx_v_info->shape[0]) = __pyx_t_5;

  /* "array.pxd":111
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize             # <<<<<<<<<<<<<<
 * 
 *             info.format = <char*> (info.shape + 1)
 */
  __pyx_v_info->strides = (&__pyx_v_info->itemsize);

  /* "array.pxd":113
 *             info.strides = &info.itemsize
 * 
 *             info.format = <char*> (info.shape + 1)             # <<<<<<<<<<<<<<
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 */
  __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1));

  /* "array.pxd":114
 * 
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode             # <<<<<<<<<<<<<<
 *             info.format[1] = 0
 *             info.obj = self
 */
  __pyx_t_7 = __pyx_v_self->ob_descr->typecode;
  (__pyx_v_info->format[0]) = __pyx_t_7;

  /* "array.pxd":115
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0             # <<<<<<<<<<<<<<
 *             info.obj = self
 * 
 */
  (__pyx_v_info->format[1]) = 0;

  /* "array.pxd":116
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 *             info.obj = self             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "array.pxd":93
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_item_count);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":118
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

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

static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);
  __Pyx_TraceCall("__releasebuffer__", __pyx_f[3], 118, 0, __PYX_ERR(3, 118, __pyx_L1_error));

  /* "array.pxd":119
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 *             PyObject_Free(info.shape)             # <<<<<<<<<<<<<<
 * 
 *     array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr)
 */
  PyObject_Free(__pyx_v_info->shape);

  /* "array.pxd":118
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("cpython.array.array.__releasebuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "array.pxd":130
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) {
  arrayobject *__pyx_v_op = 0;
  arrayobject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clone", 0);
  __Pyx_TraceCall("clone", __pyx_f[3], 130, 0, __PYX_ERR(3, 130, __pyx_L1_error));

  /* "array.pxd":134
 *     type will be same as template.
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)             # <<<<<<<<<<<<<<
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 */
  __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":135
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
  __pyx_t_3 = (__pyx_v_zero != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "array.pxd":136
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
    (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize)));

    /* "array.pxd":135
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
  }

  /* "array.pxd":137
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline array copy(array self):
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_op));
  __pyx_r = __pyx_v_op;
  goto __pyx_L0;

  /* "array.pxd":130
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_op);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":139
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) {
  arrayobject *__pyx_v_op = 0;
  arrayobject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy", 0);
  __Pyx_TraceCall("copy", __pyx_f[3], 139, 0, __PYX_ERR(3, 139, __pyx_L1_error));

  /* "array.pxd":141
 * cdef inline array copy(array self):
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)             # <<<<<<<<<<<<<<
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op
 */
  __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":142
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
  (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize)));

  /* "array.pxd":143
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_op));
  __pyx_r = __pyx_v_op;
  goto __pyx_L0;

  /* "array.pxd":139
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_op);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":145
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficient appending of new stuff of same type
 *     (e.g. of same array type)
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) {
  Py_ssize_t __pyx_v_itemsize;
  Py_ssize_t __pyx_v_origsize;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend_buffer", 0);
  __Pyx_TraceCall("extend_buffer", __pyx_f[3], 145, 0, __PYX_ERR(3, 145, __pyx_L1_error));

  /* "array.pxd":149
 *     (e.g. of same array type)
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 */
  __pyx_t_1 = __pyx_v_self->ob_descr->itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "array.pxd":150
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)             # <<<<<<<<<<<<<<
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 */
  __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self));

  /* "array.pxd":151
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)             # <<<<<<<<<<<<<<
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0
 */
  __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(3, 151, __pyx_L1_error)

  /* "array.pxd":152
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
  (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize)));

  /* "array.pxd":153
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend(array self, array other) except -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "array.pxd":145
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficient appending of new stuff of same type
 *     (e.g. of same array type)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":155
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend", 0);
  __Pyx_TraceCall("extend", __pyx_f[3], 155, 0, __PYX_ERR(3, 155, __pyx_L1_error));

  /* "array.pxd":157
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
  __pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0);
  if (__pyx_t_1) {

    /* "array.pxd":158
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()             # <<<<<<<<<<<<<<
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 */
    __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(3, 158, __pyx_L1_error)

    /* "array.pxd":157
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
  }

  /* "array.pxd":159
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))             # <<<<<<<<<<<<<<
 * 
 * cdef inline void zero(array self):
 */
  __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(3, 159, __pyx_L1_error)
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "array.pxd":155
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":161
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zero", 0);
  __Pyx_TraceCall("zero", __pyx_f[3], 161, 0, __PYX_ERR(3, 161, __pyx_L1_error));

  /* "array.pxd":163
 * cdef inline void zero(array self):
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 */
  (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize)));

  /* "array.pxd":161
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("cpython.array.zero", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(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;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}
static PyObject *__pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(o, i, v);
  }
  else {
    PyErr_Format(PyExc_NotImplementedError,
      "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader[] = {
  {"_from_text_and_lengths", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths},
  {"from_text", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text},
  {"from_dict", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict},
  {"from_references", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references},
  {"copy", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy},
  {"_build_sequence_section", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section},
  {"to_dict", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict},
  {"as_dict", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict},
  {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name},
  {"get_reference_length", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length},
  {"is_valid_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid},
  {"get_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid},
  {"items", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items},
  {"iteritems", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems},
  {"keys", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys},
  {"values", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values},
  {"get", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader[] = {
  {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_nreferences, 0, (char *)"int with the number of :term:`reference` sequences in the file.\n\n        This is a read-only attribute.", 0},
  {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_references, 0, (char *)"tuple with the names of :term:`reference` sequences. This is a\n        read-only attribute", 0},
  {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_lengths, 0, (char *)"tuple of the lengths of the :term:`reference` sequences. This is a\n        read-only attribute. The lengths are in the same order as\n        :attr:`pysam.AlignmentFile.references`\n        ", 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_AlignmentHeader = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  0, /*nb_index*/
  #if PY_VERSION_HEX >= 0x03050000
  0, /*nb_matrix_multiply*/
  #endif
  #if PY_VERSION_HEX >= 0x03050000
  0, /*nb_inplace_matrix_multiply*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_AlignmentHeader = {
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_AlignmentHeader = {
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__, /*mp_length*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader, /*mp_ass_subscript*/
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.AlignmentHeader", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_AlignmentHeader, /*tp_as_number*/
  &__pyx_tp_as_sequence_AlignmentHeader, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_AlignmentHeader, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__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*/
  "AlignmentHeader()\nheader information for a :class:`AlignmentFile` object\n\n    Parameters\n    ----------\n    header_dict : dict\n        build header from a multi-level dictionary. The\n        first level are the four types ('HD', 'SQ', ...). The second\n        level are a list of lines, with each line being a list of\n        tag-value pairs. The header is constructed first from all the\n        defined fields, followed by user tags in alphabetical\n        order. Alternatively, an :class:`~pysam.AlignmentHeader`\n        object can be passed directly.\n\n    text : string\n        use the string provided as the header\n\n    reference_names : list\n        see reference_lengths\n\n    reference_lengths : list\n        build header from list of chromosome names and lengths.  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    add_sq_text : bool\n        do not add 'SQ' and 'LN' tags to header. This option permits\n        construction :term:`SAM` formatted files without a header.\n\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader, /*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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p;
  PyObject *o = __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_new(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile;
  p->reference_filename = Py_None; Py_INCREF(Py_None);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->reference_filename);
  Py_CLEAR(p->header);
  PyObject_GC_Track(o);
  if (likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dealloc(o); else __Pyx_call_next_tp_dealloc(o, __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o;
  e = ((likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) ? ((__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_traverse) ? __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile)); if (e) return e;
  if (p->reference_filename) {
    e = (*v)(p->reference_filename, a); if (e) return e;
  }
  if (p->header) {
    e = (*v)(((PyObject *)p->header), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o;
  if (likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) { if (__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_clear) __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile);
  tmp = ((PyObject*)p->reference_filename);
  p->reference_filename = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->header);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_mapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nocoordinate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_reference_filename(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(o);
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_AlignmentFile[] = {
  {"has_index", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index},
  {"check_index", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index},
  {"_open", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open},
  {"fetch", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch},
  {"head", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head},
  {"mate", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate},
  {"pileup", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup},
  {"count", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count},
  {"count_coverage", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage},
  {"find_introns_slow", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow},
  {"find_introns", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns},
  {"close", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close},
  {"write", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28write},
  {"__enter__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__},
  {"__exit__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__},
  {"get_index_statistics", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics},
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__, METH_NOARGS|METH_COEXIST, 0},
  {"is_valid_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid},
  {"get_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid},
  {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name},
  {"get_reference_length", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length},
  {"gettid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid},
  {"getrname", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile[] = {
  {(char *)"mapped", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_mapped, 0, (char *)"int with total number of mapped alignments according to the\n        statistics recorded in the index. This is a read-only\n        attribute.\n        (This will be 0 for a CRAM file indexed by a .crai index, as that\n        index format does not record these statistics.)\n        ", 0},
  {(char *)"unmapped", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_unmapped, 0, (char *)"int with total number of unmapped reads according to the statistics\n        recorded in the index. This number of reads includes the number of reads\n        without coordinates. This is a read-only attribute.\n        (This will be 0 for a CRAM file indexed by a .crai index, as that\n        index format does not record these statistics.)\n        ", 0},
  {(char *)"nocoordinate", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nocoordinate, 0, (char *)"int with total number of reads without coordinates according to the\n        statistics recorded in the index, i.e., the statistic printed for \"*\"\n        by the ``samtools idxstats`` command. This is a read-only attribute.\n        (This will be 0 for a CRAM file indexed by a .crai index, as that\n        index format does not record these statistics.)\n        ", 0},
  {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences, 0, (char *)"int with the number of :term:`reference` sequences in the file.\n        This is a read-only attribute.", 0},
  {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references, 0, (char *)"tuple with the names of :term:`reference` sequences. This is a\n        read-only attribute", 0},
  {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths, 0, (char *)"tuple of the lengths of the :term:`reference` sequences. This is a\n        read-only attribute. The lengths are in the same order as\n        :attr:`pysam.AlignmentFile.references`\n\n        ", 0},
  {(char *)"text", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text, 0, (char *)"deprecated, use :attr:`references` and :attr:`lengths` instead", 0},
  {(char *)"reference_filename", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_reference_filename, 0, (char *)0, 0},
  {(char *)"header", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_AlignmentFile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.AlignmentFile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "AlignmentFile(filepath_or_object, mode=None, template=None,\n    reference_names=None, reference_lengths=None, text=NULL,\n    header=None, add_sq_text=False, check_header=True, check_sq=True,\n    reference_filename=None, filename=None, index_filename=None,\n    filepath_index=None, require_index=False, duplicate_filehandle=True,\n    ignore_truncation=False, threads=1)\n\n    A :term:`SAM`/:term:`BAM`/:term:`CRAM` formatted file.\n\n    If `filepath_or_object` is a string, the file is automatically\n    opened. If `filepath_or_object` is a python File object, the\n    already opened file will be used.\n\n    If the file is opened for reading and an index exists (if file is BAM, a\n    .bai file or if CRAM a .crai file), it will be opened automatically.\n    `index_filename` may be specified explicitly. If the index is not named\n    in the standard manner, not located in the same directory as the\n    BAM/CRAM file, or is remote.  Without an index, random access via\n    :meth:`~pysam.AlignmentFile.fetch` and :meth:`~pysam.AlignmentFile.pileup`\n    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 another\n           `AlignmentFile` (`template` must be a\n           :class:`~pysam.AlignmentFile`).\n\n        2. If `header` is given, the header is built from a\n           multi-level dictionary.\n\n        3. If `text` is given, new header text is copied from raw\n           text.\n\n        4. The names (`reference_names`) and lengths\n           (`reference_lengths`) are supplied directly as lists.\n\n    When reading or writing a CRAM file, the filename of a FASTA-formatted\n    reference can be specified with `reference_filename`.\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    chr""omosome names (`check_sq` = True).\n\n    Parameters\n    ----------\n    mode : string\n        `mode` should be ``r`` for reading or ``w`` for writing. The\n        default is text mode (:term:`SAM`). For binary (:term:`BAM`)\n        I/O you should append ``b`` for compressed or ``u`` for\n        uncompressed :term:`BAM` output.  Use ``h`` to output header\n        information in text (:term:`TAM`) mode. Use ``c`` for\n        :term:`CRAM` formatted files.\n\n        If ``b`` is present, it must immediately follow ``r`` or\n        ``w``.  Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``,\n        ``wbu``, ``wb0``, ``rc`` and ``wc``. For instance, to open a\n        :term:`BAM` formatted file for reading, type::\n\n           f = pysam.AlignmentFile('ex1.bam','rb')\n\n        If mode is not specified, the method will try to auto-detect\n        in the order 'rb', 'r', thus both the following should work::\n\n            f1 = pysam.AlignmentFile('ex1.bam')\n            f2 = pysam.AlignmentFile('ex1.sam')\n\n    template : AlignmentFile\n        when writing, copy header from file `template`.\n\n    header :  dict or AlignmentHeader\n        when writing, build header from a multi-level dictionary. The\n        first level are the four types ('HD', 'SQ', ...). The second\n        level are a list of lines, with each line being a list of\n        tag-value pairs. The header is constructed first from all the\n        defined fields, followed by user tags in alphabetical\n        order. Alternatively, an :class:`~pysam.AlignmentHeader`\n        object can be passed directly.\n\n    text : string\n        when writing, use the string provided as the header\n\n    reference_names : list\n        see reference_lengths\n\n    reference_lengths : list\n        when writing or opening a SAM file without header build header\n        from list of chromosome names and lengths.  By default, 'SQ'\n        and 'LN' tags will be added to the header text. This option\n        ""can be changed by unsetting the flag `add_sq_text`.\n\n    add_sq_text : bool\n        do not add 'SQ' and 'LN' tags to header. This option permits\n        construction :term:`SAM` formatted files without a header.\n\n    add_sam_header : bool\n        when outputting SAM the default is to output a header. This is\n        equivalent to opening the file in 'wh' mode. If this option is\n        set to False, no header will be output. To read such a file,\n        set `check_header=False`.\n\n    check_header : bool\n        obsolete: when reading a SAM file, check if header is present\n        (default=True)\n\n    check_sq : bool\n        when reading, check if SQ entries are present in header\n        (default=True)\n\n    reference_filename : string\n        Path to a FASTA-formatted reference file. Valid only for CRAM files.\n        When reading a CRAM file, this overrides both ``$REF_PATH`` and the URL\n        specified in the header (``UR`` tag), which are normally used to find\n        the reference.\n\n    index_filename : string\n        Explicit path to the index file.  Only needed if the index is not\n        named in the standard manner, not located in the same directory as\n        the BAM/CRAM file, or is remote.  An IOError is raised if the index\n        cannot be found or is invalid.\n\n    filepath_index : string\n        Alias for `index_filename`.\n\n    require_index : bool\n        When reading, require that an index file is present and is valid or\n        raise an IOError.  (default=False)\n\n    filename : string\n        Alternative to filepath_or_object. Filename of the file\n        to be opened.\n\n    duplicate_filehandle: bool\n        By default, file handles passed either directly or through\n        File-like objects will be duplicated before passing them to\n        htslib. The duplication prevents issues where the same stream\n        will be closed by htslib and through destruction of the\n        high-level python object. Set ""to False to turn off\n        duplication.\n\n    ignore_truncation: bool\n        Issue a warning, instead of raising an error if the current file\n        appears to be truncated due to a missing EOF marker.  Only applies\n        to bgzipped formats. (Default=False)\n\n    format_options: list\n        A list of key=value strings, as accepted by --input-fmt-option and\n        --output-fmt-option in samtools.\n    threads: integer\n        Number of threads to use for compressing/decompressing BAM/CRAM files.\n        Setting threads to > 1 cannot be combined with `ignore_truncation`.\n        (Default=1)\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_AlignmentFile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile, /*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_17libcalignmentfile_AlignmentFile, /*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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_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_17libcalignmentfile_IteratorRow *)o);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_3__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->header);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o;
  if (p->samfile) {
    e = (*v)(((PyObject *)p->samfile), a); if (e) return e;
  }
  if (p->header) {
    e = (*v)(((PyObject *)p->header), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->header);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRow[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRow = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorRow", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IteratorRow(AlignmentFile samfile, int multiple_iterators=False)\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:`AlignmentFile.fetch` returns an IteratorRow.\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_11IteratorRow_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion;
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowRegion(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_7__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(o);
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowRegion[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorRowRegion", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowRegion, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IteratorRowRegion(AlignmentFile samfile, int tid, int beg, int stop, int multiple_iterators=False)\n*(AlignmentFile samfile, int tid, int beg, int stop,\n    int multiple_iterators=False)*\n\n    iterate over mapped reads in a region.\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_17IteratorRowRegion_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead;
  return o;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowHead[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorRowHead", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IteratorRowHead(AlignmentFile samfile, int n, int multiple_iterators=False)\n*(AlignmentFile samfile, n, int multiple_iterators=False)*\n\n    iterate over first n reads in `samfile`\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.head`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_15IteratorRowHead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll;
  return o;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowAll[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorRowAll", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IteratorRowAll(AlignmentFile samfile, int multiple_iterators=False)\n*(AlignmentFile samfile, int multiple_iterators=False)*\n\n    iterate over all reads in `samfile`\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_14IteratorRowAll_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o);
  p->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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_17libcalignmentfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o;
  e = __pyx_tp_traverse_5pysam_17libcalignmentfile_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_17libcalignmentfile_IteratorRowAllRefs(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o;
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(o);
  tmp = ((PyObject*)p->rowiter);
  p->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowAllRefs[] = {
  {"nextiter", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter},
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorRowAllRefs", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IteratorRowAllRefs(AlignmentFile samfile, multiple_iterators=False)\niterates over all mapped reads by chaining iterators over each\n    reference\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_18IteratorRowAllRefs_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection;
  p->positions = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowSelection(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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_17libcalignmentfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowSelection(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o;
  e = __pyx_tp_traverse_5pysam_17libcalignmentfile_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_17libcalignmentfile_IteratorRowSelection(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o;
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(o);
  tmp = ((PyObject*)p->positions);
  p->positions = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowSelection[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorRowSelection", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IteratorRowSelection(AlignmentFile samfile, positions, int multiple_iterators=True)\n*(AlignmentFile 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        explicitly. It is returned as a result of call to a :meth:`AlignmentFile.fetch`.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_20IteratorRowSelection_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_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_17libcalignmentfile_IteratorColumn *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  p->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)Py_None); Py_INCREF(Py_None);
  p->stepper = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_9__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    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_17libcalignmentfile_IteratorColumn(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_17libcalignmentfile_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_17libcalignmentfile_IteratorColumn(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)o;
  tmp = ((PyObject*)p->iter);
  p->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->fastafile);
  p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_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_17libcalignmentfile_14IteratorColumn_seq_len(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumn[] = {
  {"add_reference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference},
  {"has_reference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference},
  {"hasReference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference},
  {"addReference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_IteratorColumn[] = {
  {(char *)"seq_len", __pyx_getprop_5pysam_17libcalignmentfile_14IteratorColumn_seq_len, 0, (char *)"current sequence length.", 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorColumn", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "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 behaviour. For example,\n    consider the conversion to a list::\n\n       f = AlignmentFile(\"file.bam\", \"rb\")\n       result = list(f.pileup())\n\n    Here, ``result`` will contain ``n`` objects of type\n    :class:`~pysam.PileupColumn` 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\n    :class:`~pysam.PileupRead`.\n\n    If the iterator is associated with a :class:`~pysam.Fastafile`\n    using the :meth:`add_reference` method, then the iterator will\n    export the current sequence via the methods :meth:`get_sequence`\n    and :meth:`seq_len`.\n\n    See :class:`~AlignmentFile.pileup` for kwargs to the iterator.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorColumn, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_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_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnRegion[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorColumnRegion", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "iterates over a region only.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAllRefs[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorColumnAllRefs", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "iterates over all columns by chaining iterators over each reference\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAll;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {return __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(self);}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAll[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IteratorColumnAll", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "iterates over all columns, without using an index\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAll, /*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_17libcalignmentfile_IteratorColumnAll, /*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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_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_17libcalignmentfile_IndexedReads *)o);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->index = Py_None; Py_INCREF(Py_None);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_7__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->index);
  Py_CLEAR(p->header);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IndexedReads(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_17libcalignmentfile_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;
  }
  if (p->header) {
    e = (*v)(((PyObject *)p->header), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IndexedReads(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->index);
  p->index = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->header);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IndexedReads[] = {
  {"build", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_3build, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_2build},
  {"find", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find, METH_O, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IndexedReads = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.IndexedReads", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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*/
  "IndexedReads(AlignmentFile samfile, int multiple_iterators=True)\nIndex a Sam/BAM-file by query name while keeping the\n    original sort order intact.\n\n    The index is kept in memory and can be substantial.\n\n    By default, the file is re-opened to avoid conflicts if multiple\n    operators work on the same file. Set `multiple_iterators` = False\n    to not re-open `samfile`.\n\n    Parameters\n    ----------\n\n    samfile : AlignmentFile\n        File to be indexed.\n\n    multiple_iterators : bool\n        Flag indicating whether the file should be reopened. Reopening prevents\n        existing iterators being affected by the indexing.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IndexedReads, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IndexedReads, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_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_17libcalignmentfile_12IndexedReads_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_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_17libcalignmentfile_SNPCall(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && 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_17libcalignmentfile_7SNPCall_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3tid_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_reference_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_14reference_base_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_genotype(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8genotype_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_consensus_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_snp_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_11snp_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_coverage(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8coverage_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_SNPCall[] = {
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_SNPCall[] = {
  {(char *)"tid", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_tid, 0, (char *)"the chromosome ID as is defined in the header", 0},
  {(char *)"pos", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_pos, 0, (char *)"nucleotide position of SNP.", 0},
  {(char *)"reference_base", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_reference_base, 0, (char *)"reference base at pos. ``N`` if no reference sequence supplied.", 0},
  {(char *)"genotype", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_genotype, 0, (char *)"the genotype called.", 0},
  {(char *)"consensus_quality", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_consensus_quality, 0, (char *)"the genotype quality (Phred-scaled).", 0},
  {(char *)"snp_quality", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_snp_quality, 0, (char *)"the snp quality (Phred scaled) - probability of consensus being\n       identical to reference sequence.", 0},
  {(char *)"mapping_quality", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_mapping_quality, 0, (char *)"the root mean square (rms) of the mapping quality of all reads\n       involved in the call.", 0},
  {(char *)"coverage", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_coverage, 0, (char *)"coverage or read depth - the number of reads involved in the call.", 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_SNPCall = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.SNPCall", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_SNPCall, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #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_17libcalignmentfile_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*/
  "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_17libcalignmentfile_SNPCall, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_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_17libcalignmentfile_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*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_libcalignmentfile(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_libcalignmentfile},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "libcalignmentfile",
    0, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1},
  {&__pyx_n_s_AH, __pyx_k_AH, sizeof(__pyx_k_AH), 0, 0, 1, 1},
  {&__pyx_n_s_AS, __pyx_k_AS, sizeof(__pyx_k_AS), 0, 0, 1, 1},
  {&__pyx_kp_s_AlignedSegment_refers_to_referen, __pyx_k_AlignedSegment_refers_to_referen, sizeof(__pyx_k_AlignedSegment_refers_to_referen), 0, 0, 1, 0},
  {&__pyx_n_s_AlignmentFile, __pyx_k_AlignmentFile, sizeof(__pyx_k_AlignmentFile), 0, 0, 1, 1},
  {&__pyx_kp_s_AlignmentFile_mapped_only_availa, __pyx_k_AlignmentFile_mapped_only_availa, sizeof(__pyx_k_AlignmentFile_mapped_only_availa), 0, 0, 1, 0},
  {&__pyx_n_s_AlignmentHeader, __pyx_k_AlignmentHeader, sizeof(__pyx_k_AlignmentHeader), 0, 0, 1, 1},
  {&__pyx_kp_s_AlignmentHeader_does_not_support, __pyx_k_AlignmentHeader_does_not_support, sizeof(__pyx_k_AlignmentHeader_does_not_support), 0, 0, 1, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
  {&__pyx_n_s_CL, __pyx_k_CL, sizeof(__pyx_k_CL), 0, 0, 1, 1},
  {&__pyx_n_s_CN, __pyx_k_CN, sizeof(__pyx_k_CN), 0, 0, 1, 1},
  {&__pyx_n_s_CO, __pyx_k_CO, sizeof(__pyx_k_CO), 0, 0, 1, 1},
  {&__pyx_kp_s_Cannot_add_extra_threads_when_ig, __pyx_k_Cannot_add_extra_threads_when_ig, sizeof(__pyx_k_Cannot_add_extra_threads_when_ig), 0, 0, 1, 0},
  {&__pyx_n_s_Counter, __pyx_k_Counter, sizeof(__pyx_k_Counter), 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_FO, __pyx_k_FO, sizeof(__pyx_k_FO), 0, 0, 1, 1},
  {&__pyx_n_s_G, __pyx_k_G, sizeof(__pyx_k_G), 0, 0, 1, 1},
  {&__pyx_n_s_GO, __pyx_k_GO, sizeof(__pyx_k_GO), 0, 0, 1, 1},
  {&__pyx_n_s_HD, __pyx_k_HD, sizeof(__pyx_k_HD), 0, 0, 1, 1},
  {&__pyx_n_s_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_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_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_kp_s_Incompatible_checksums_s_vs_0x50, __pyx_k_Incompatible_checksums_s_vs_0x50, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x50), 0, 0, 1, 0},
  {&__pyx_n_s_IndexStats, __pyx_k_IndexStats, sizeof(__pyx_k_IndexStats), 0, 0, 1, 1},
  {&__pyx_n_s_IndexedReads, __pyx_k_IndexedReads, sizeof(__pyx_k_IndexedReads), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorColumn, __pyx_k_IteratorColumn, sizeof(__pyx_k_IteratorColumn), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorColumnAll, __pyx_k_IteratorColumnAll, sizeof(__pyx_k_IteratorColumnAll), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorColumnAllRefs, __pyx_k_IteratorColumnAllRefs, sizeof(__pyx_k_IteratorColumnAllRefs), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorColumnRegion, __pyx_k_IteratorColumnRegion, sizeof(__pyx_k_IteratorColumnRegion), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRow, __pyx_k_IteratorRow, sizeof(__pyx_k_IteratorRow), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRowAll, __pyx_k_IteratorRowAll, sizeof(__pyx_k_IteratorRowAll), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRowAllRefs, __pyx_k_IteratorRowAllRefs, sizeof(__pyx_k_IteratorRowAllRefs), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRowHead, __pyx_k_IteratorRowHead, sizeof(__pyx_k_IteratorRowHead), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRowRegion, __pyx_k_IteratorRowRegion, sizeof(__pyx_k_IteratorRowRegion), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRowSelection, __pyx_k_IteratorRowSelection, sizeof(__pyx_k_IteratorRowSelection), 0, 0, 1, 1},
  {&__pyx_n_s_KNOWN_HEADER_FIELDS, __pyx_k_KNOWN_HEADER_FIELDS, sizeof(__pyx_k_KNOWN_HEADER_FIELDS), 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_L, __pyx_k_L, sizeof(__pyx_k_L), 0, 0, 1, 1},
  {&__pyx_n_s_LB, __pyx_k_LB, sizeof(__pyx_k_LB), 0, 0, 1, 1},
  {&__pyx_n_s_LN, __pyx_k_LN, sizeof(__pyx_k_LN), 0, 0, 1, 1},
  {&__pyx_n_s_M5, __pyx_k_M5, sizeof(__pyx_k_M5), 0, 0, 1, 1},
  {&__pyx_n_s_Mapping, __pyx_k_Mapping, sizeof(__pyx_k_Mapping), 0, 0, 1, 1},
  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1},
  {&__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_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 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_PM, __pyx_k_PM, sizeof(__pyx_k_PM), 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_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_RG, __pyx_k_RG, sizeof(__pyx_k_RG), 0, 0, 1, 1},
  {&__pyx_kp_s_Raw_iterator_set_up_without_regi, __pyx_k_Raw_iterator_set_up_without_regi, sizeof(__pyx_k_Raw_iterator_set_up_without_regi), 0, 0, 1, 0},
  {&__pyx_kp_s_SAM_file_does_not_have_a_valid_h, __pyx_k_SAM_file_does_not_have_a_valid_h, sizeof(__pyx_k_SAM_file_does_not_have_a_valid_h), 0, 0, 1, 0},
  {&__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_SNPCall, __pyx_k_SNPCall, sizeof(__pyx_k_SNPCall), 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_kp_s_SQ, __pyx_k_SQ, sizeof(__pyx_k_SQ), 0, 0, 1, 0},
  {&__pyx_n_s_SQ_2, __pyx_k_SQ_2, sizeof(__pyx_k_SQ_2), 0, 0, 1, 1},
  {&__pyx_kp_s_SQ_SN_LN, __pyx_k_SQ_SN_LN, sizeof(__pyx_k_SQ_SN_LN), 0, 0, 1, 0},
  {&__pyx_n_s_Sequence, __pyx_k_Sequence, sizeof(__pyx_k_Sequence), 0, 0, 1, 1},
  {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1},
  {&__pyx_n_s_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 0, 0, 1, 1},
  {&__pyx_n_s_T, __pyx_k_T, sizeof(__pyx_k_T), 0, 0, 1, 1},
  {&__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_n_s_VALID_HEADERS, __pyx_k_VALID_HEADERS, sizeof(__pyx_k_VALID_HEADERS), 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_kp_s__11, __pyx_k__11, sizeof(__pyx_k__11), 0, 0, 1, 0},
  {&__pyx_kp_s__12, __pyx_k__12, sizeof(__pyx_k__12), 0, 0, 1, 0},
  {&__pyx_kp_s__13, __pyx_k__13, sizeof(__pyx_k__13), 0, 0, 1, 0},
  {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0},
  {&__pyx_kp_b__24, __pyx_k__24, sizeof(__pyx_k__24), 0, 0, 0, 0},
  {&__pyx_kp_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 0},
  {&__pyx_kp_s__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 0, 1, 0},
  {&__pyx_kp_s_access_from_StringIO_objects_not, __pyx_k_access_from_StringIO_objects_not, sizeof(__pyx_k_access_from_StringIO_objects_not), 0, 0, 1, 0},
  {&__pyx_n_s_add_hts_options, __pyx_k_add_hts_options, sizeof(__pyx_k_add_hts_options), 0, 0, 1, 1},
  {&__pyx_n_s_add_reference, __pyx_k_add_reference, sizeof(__pyx_k_add_reference), 0, 0, 1, 1},
  {&__pyx_n_s_add_sam_header, __pyx_k_add_sam_header, sizeof(__pyx_k_add_sam_header), 0, 0, 1, 1},
  {&__pyx_n_s_add_sq_text, __pyx_k_add_sq_text, sizeof(__pyx_k_add_sq_text), 0, 0, 1, 1},
  {&__pyx_n_s_adjust_capq_threshold, __pyx_k_adjust_capq_threshold, sizeof(__pyx_k_adjust_capq_threshold), 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_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_s_beg, __pyx_k_beg, sizeof(__pyx_k_beg), 0, 0, 1, 1},
  {&__pyx_n_s_build_header_line, __pyx_k_build_header_line, sizeof(__pyx_k_build_header_line), 0, 0, 1, 1},
  {&__pyx_n_s_build_sequence_section, __pyx_k_build_sequence_section, sizeof(__pyx_k_build_sequence_section), 0, 0, 1, 1},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__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_apply_IndexReads_on_bam, __pyx_k_can_only_apply_IndexReads_on_bam, sizeof(__pyx_k_can_only_apply_IndexReads_on_bam), 0, 0, 1, 0},
  {&__pyx_kp_s_cannot_create_AlignmentHeader_re, __pyx_k_cannot_create_AlignmentHeader_re, sizeof(__pyx_k_cannot_create_AlignmentHeader_re), 0, 0, 1, 0},
  {&__pyx_n_s_check_header, __pyx_k_check_header, sizeof(__pyx_k_check_header), 0, 0, 1, 1},
  {&__pyx_n_s_check_index, __pyx_k_check_index, sizeof(__pyx_k_check_index), 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_check_truncation, __pyx_k_check_truncation, sizeof(__pyx_k_check_truncation), 0, 0, 1, 1},
  {&__pyx_n_s_cigarstring, __pyx_k_cigarstring, sizeof(__pyx_k_cigarstring), 0, 0, 1, 1},
  {&__pyx_n_s_cigartuples, __pyx_k_cigartuples, sizeof(__pyx_k_cigartuples), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_closed, __pyx_k_closed, sizeof(__pyx_k_closed), 0, 0, 1, 1},
  {&__pyx_n_s_code, __pyx_k_code, sizeof(__pyx_k_code), 0, 0, 1, 1},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_collections_abc, __pyx_k_collections_abc, sizeof(__pyx_k_collections_abc), 0, 0, 1, 1},
  {&__pyx_n_s_compute_baq, __pyx_k_compute_baq, sizeof(__pyx_k_compute_baq), 0, 0, 1, 1},
  {&__pyx_n_s_consensus_quality, __pyx_k_consensus_quality, sizeof(__pyx_k_consensus_quality), 0, 0, 1, 1},
  {&__pyx_n_s_contains, __pyx_k_contains, sizeof(__pyx_k_contains), 0, 0, 1, 1},
  {&__pyx_n_s_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 0, 1, 1},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_kp_s_could_not_allocate_bytes, __pyx_k_could_not_allocate_bytes, sizeof(__pyx_k_could_not_allocate_bytes), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_allocate_memory_of_siz, __pyx_k_could_not_allocate_memory_of_siz, sizeof(__pyx_k_could_not_allocate_memory_of_siz), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_create_header, __pyx_k_could_not_create_header, sizeof(__pyx_k_could_not_create_header), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_open_alignment_file, __pyx_k_could_not_open_alignment_file, sizeof(__pyx_k_could_not_open_alignment_file), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_open_alignment_file_2, __pyx_k_could_not_open_alignment_file_2, sizeof(__pyx_k_could_not_open_alignment_file_2), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_parse_header, __pyx_k_could_not_parse_header, sizeof(__pyx_k_could_not_parse_header), 0, 0, 1, 0},
  {&__pyx_n_s_coverage, __pyx_k_coverage, sizeof(__pyx_k_coverage), 0, 0, 1, 1},
  {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1},
  {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
  {&__pyx_n_s_duplicate_filehandle, __pyx_k_duplicate_filehandle, sizeof(__pyx_k_duplicate_filehandle), 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_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__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_reading_file, __pyx_k_error_while_reading_file, sizeof(__pyx_k_error_while_reading_file), 0, 0, 1, 0},
  {&__pyx_kp_s_error_while_reading_file_2, __pyx_k_error_while_reading_file_2, sizeof(__pyx_k_error_while_reading_file_2), 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_kp_s_failure_when_setting_reference_f, __pyx_k_failure_when_setting_reference_f, sizeof(__pyx_k_failure_when_setting_reference_f), 0, 0, 1, 0},
  {&__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_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_contain_alignment, __pyx_k_file_does_not_contain_alignment, sizeof(__pyx_k_file_does_not_contain_alignment), 0, 0, 1, 0},
  {&__pyx_kp_s_file_does_not_have_a_valid_heade, __pyx_k_file_does_not_have_a_valid_heade, sizeof(__pyx_k_file_does_not_have_a_valid_heade), 0, 0, 1, 0},
  {&__pyx_kp_s_file_has_no_sequences_defined_mo, __pyx_k_file_has_no_sequences_defined_mo, sizeof(__pyx_k_file_has_no_sequences_defined_mo), 0, 0, 1, 0},
  {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1},
  {&__pyx_n_s_fileno, __pyx_k_fileno, sizeof(__pyx_k_fileno), 0, 0, 1, 1},
  {&__pyx_n_s_filepath_index, __pyx_k_filepath_index, sizeof(__pyx_k_filepath_index), 0, 0, 1, 1},
  {&__pyx_n_s_filepath_or_object, __pyx_k_filepath_or_object, sizeof(__pyx_k_filepath_or_object), 0, 0, 1, 1},
  {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1},
  {&__pyx_n_s_flag_filter, __pyx_k_flag_filter, sizeof(__pyx_k_flag_filter), 0, 0, 1, 1},
  {&__pyx_n_s_flag_require, __pyx_k_flag_require, sizeof(__pyx_k_flag_require), 0, 0, 1, 1},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_format_options, __pyx_k_format_options, sizeof(__pyx_k_format_options), 0, 0, 1, 1},
  {&__pyx_n_s_from_dict, __pyx_k_from_dict, sizeof(__pyx_k_from_dict), 0, 0, 1, 1},
  {&__pyx_n_s_from_references, __pyx_k_from_references, sizeof(__pyx_k_from_references), 0, 0, 1, 1},
  {&__pyx_n_s_from_text, __pyx_k_from_text, sizeof(__pyx_k_from_text), 0, 0, 1, 1},
  {&__pyx_n_s_from_text_and_lengths, __pyx_k_from_text_and_lengths, sizeof(__pyx_k_from_text_and_lengths), 0, 0, 1, 1},
  {&__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_get_aligned_pairs, __pyx_k_get_aligned_pairs, sizeof(__pyx_k_get_aligned_pairs), 0, 0, 1, 1},
  {&__pyx_n_s_get_reference_length, __pyx_k_get_reference_length, sizeof(__pyx_k_get_reference_length), 0, 0, 1, 1},
  {&__pyx_n_s_get_reference_name, __pyx_k_get_reference_name, sizeof(__pyx_k_get_reference_name), 0, 0, 1, 1},
  {&__pyx_n_s_get_tid, __pyx_k_get_tid, sizeof(__pyx_k_get_tid), 0, 0, 1, 1},
  {&__pyx_n_s_getitem, __pyx_k_getitem, sizeof(__pyx_k_getitem), 0, 0, 1, 1},
  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
  {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1},
  {&__pyx_n_s_has_index, __pyx_k_has_index, sizeof(__pyx_k_has_index), 0, 0, 1, 1},
  {&__pyx_n_s_has_reference, __pyx_k_has_reference, sizeof(__pyx_k_has_reference), 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_header_not_available_in_closed_f, __pyx_k_header_not_available_in_closed_f, sizeof(__pyx_k_header_not_available_in_closed_f), 0, 0, 1, 0},
  {&__pyx_n_s_ignore_orphans, __pyx_k_ignore_orphans, sizeof(__pyx_k_ignore_orphans), 0, 0, 1, 1},
  {&__pyx_n_s_ignore_overlaps, __pyx_k_ignore_overlaps, sizeof(__pyx_k_ignore_overlaps), 0, 0, 1, 1},
  {&__pyx_n_s_ignore_truncation, __pyx_k_ignore_truncation, sizeof(__pyx_k_ignore_truncation), 0, 0, 1, 1},
  {&__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_index_filename, __pyx_k_index_filename, sizeof(__pyx_k_index_filename), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
  {&__pyx_kp_s_interval_of_size_0, __pyx_k_interval_of_size_0, sizeof(__pyx_k_interval_of_size_0), 0, 0, 1, 0},
  {&__pyx_kp_s_interval_of_size_less_than_0, __pyx_k_interval_of_size_less_than_0, sizeof(__pyx_k_interval_of_size_less_than_0), 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_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_io, __pyx_k_io, sizeof(__pyx_k_io), 0, 0, 1, 1},
  {&__pyx_n_s_is_bam, __pyx_k_is_bam, sizeof(__pyx_k_is_bam), 0, 0, 1, 1},
  {&__pyx_n_s_is_cram, __pyx_k_is_cram, sizeof(__pyx_k_is_cram), 0, 0, 1, 1},
  {&__pyx_n_s_is_open, __pyx_k_is_open, sizeof(__pyx_k_is_open), 0, 0, 1, 1},
  {&__pyx_n_s_is_valid_tid, __pyx_k_is_valid_tid, sizeof(__pyx_k_is_valid_tid), 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_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
  {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
  {&__pyx_n_s_len, __pyx_k_len, sizeof(__pyx_k_len), 0, 0, 1, 1},
  {&__pyx_n_s_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_make, __pyx_k_make, sizeof(__pyx_k_make), 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_n_s_mapped, __pyx_k_mapped, sizeof(__pyx_k_mapped), 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_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_depth, __pyx_k_max_depth, sizeof(__pyx_k_max_depth), 0, 0, 1, 1},
  {&__pyx_n_s_min_base_quality, __pyx_k_min_base_quality, sizeof(__pyx_k_min_base_quality), 0, 0, 1, 1},
  {&__pyx_n_s_min_mapping_quality, __pyx_k_min_mapping_quality, sizeof(__pyx_k_min_mapping_quality), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_multiple_iterators, __pyx_k_multiple_iterators, sizeof(__pyx_k_multiple_iterators), 0, 0, 1, 1},
  {&__pyx_kp_s_multiple_iterators_not_implement, __pyx_k_multiple_iterators_not_implement, sizeof(__pyx_k_multiple_iterators_not_implement), 0, 0, 1, 0},
  {&__pyx_kp_s_multiple_iterators_not_implement_2, __pyx_k_multiple_iterators_not_implement_2, sizeof(__pyx_k_multiple_iterators_not_implement_2), 0, 0, 1, 0},
  {&__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_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
  {&__pyx_n_s_namedtuple, __pyx_k_namedtuple, sizeof(__pyx_k_namedtuple), 0, 0, 1, 1},
  {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
  {&__pyx_n_s_nextiter, __pyx_k_nextiter, sizeof(__pyx_k_nextiter), 0, 0, 1, 1},
  {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
  {&__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_nofilter, __pyx_k_nofilter, sizeof(__pyx_k_nofilter), 0, 0, 1, 1},
  {&__pyx_kp_s_not_enough_information_to_constr, __pyx_k_not_enough_information_to_constr, sizeof(__pyx_k_not_enough_information_to_constr), 0, 0, 1, 0},
  {&__pyx_n_s_nreferences, __pyx_k_nreferences, sizeof(__pyx_k_nreferences), 0, 0, 1, 1},
  {&__pyx_kp_s_number_of_reference_names_and_le, __pyx_k_number_of_reference_names_and_le, sizeof(__pyx_k_number_of_reference_names_and_le), 0, 0, 1, 0},
  {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_parse_region, __pyx_k_parse_region, sizeof(__pyx_k_parse_region), 0, 0, 1, 1},
  {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 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_pysam_libcalignmentfile, __pyx_k_pysam_libcalignmentfile, sizeof(__pyx_k_pysam_libcalignmentfile), 0, 0, 1, 1},
  {&__pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_k_pysam_libcalignmentfile_pyx, sizeof(__pyx_k_pysam_libcalignmentfile_pyx), 0, 0, 1, 0},
  {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_unpickle_SNPCall, __pyx_k_pyx_unpickle_SNPCall, sizeof(__pyx_k_pyx_unpickle_SNPCall), 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_quality_threshold, __pyx_k_quality_threshold, sizeof(__pyx_k_quality_threshold), 0, 0, 1, 1},
  {&__pyx_n_s_query_name, __pyx_k_query_name, sizeof(__pyx_k_query_name), 0, 0, 1, 1},
  {&__pyx_n_s_query_qualities, __pyx_k_query_qualities, sizeof(__pyx_k_query_qualities), 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_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 0, 1, 1},
  {&__pyx_n_s_rc, __pyx_k_rc, sizeof(__pyx_k_rc), 0, 0, 1, 1},
  {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
  {&__pyx_n_s_read_callback, __pyx_k_read_callback, sizeof(__pyx_k_read_callback), 0, 0, 1, 1},
  {&__pyx_n_s_read_failure_reason, __pyx_k_read_failure_reason, sizeof(__pyx_k_read_failure_reason), 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_redo_baq, __pyx_k_redo_baq, sizeof(__pyx_k_redo_baq), 0, 0, 1, 1},
  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 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_n_s_reference_filename, __pyx_k_reference_filename, sizeof(__pyx_k_reference_filename), 0, 0, 1, 1},
  {&__pyx_kp_s_reference_id_i_out_of_range_0_ti, __pyx_k_reference_id_i_out_of_range_0_ti, sizeof(__pyx_k_reference_id_i_out_of_range_0_ti), 0, 0, 1, 0},
  {&__pyx_n_s_reference_lengths, __pyx_k_reference_lengths, sizeof(__pyx_k_reference_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_reference_names, __pyx_k_reference_names, sizeof(__pyx_k_reference_names), 0, 0, 1, 1},
  {&__pyx_kp_s_reference_sequence_for_tid_not_f, __pyx_k_reference_sequence_for_tid_not_f, sizeof(__pyx_k_reference_sequence_for_tid_not_f), 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_require_index, __pyx_k_require_index, sizeof(__pyx_k_require_index), 0, 0, 1, 1},
  {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0},
  {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0},
  {&__pyx_kp_s_sam_write1_failed_with_error_cod, __pyx_k_sam_write1_failed_with_error_cod, sizeof(__pyx_k_sam_write1_failed_with_error_cod), 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_kp_s_self_b_self_htsfile_self_index_c, __pyx_k_self_b_self_htsfile_self_index_c, sizeof(__pyx_k_self_b_self_htsfile_self_index_c), 0, 0, 1, 0},
  {&__pyx_kp_s_self_b_self_htsfile_self_index_s, __pyx_k_self_b_self_htsfile_self_index_s, sizeof(__pyx_k_self_b_self_htsfile_self_index_s), 0, 0, 1, 0},
  {&__pyx_kp_s_self_htsfile_cannot_be_converted, __pyx_k_self_htsfile_cannot_be_converted, sizeof(__pyx_k_self_htsfile_cannot_be_converted), 0, 0, 1, 0},
  {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 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_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_splitlines, __pyx_k_splitlines, sizeof(__pyx_k_splitlines), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
  {&__pyx_n_s_stepper, __pyx_k_stepper, sizeof(__pyx_k_stepper), 0, 0, 1, 1},
  {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
  {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 0, 0, 1, 1},
  {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
  {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1},
  {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
  {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 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_threads, __pyx_k_threads, sizeof(__pyx_k_threads), 0, 0, 1, 1},
  {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1},
  {&__pyx_n_s_to_dict, __pyx_k_to_dict, sizeof(__pyx_k_to_dict), 0, 0, 1, 1},
  {&__pyx_n_s_total, __pyx_k_total, sizeof(__pyx_k_total), 0, 0, 1, 1},
  {&__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_kp_s_truncated_file, __pyx_k_truncated_file, sizeof(__pyx_k_truncated_file), 0, 0, 1, 0},
  {&__pyx_kp_s_unable_to_open_index_file, __pyx_k_unable_to_open_index_file, sizeof(__pyx_k_unable_to_open_index_file), 0, 0, 1, 0},
  {&__pyx_kp_s_unable_to_open_index_file_s, __pyx_k_unable_to_open_index_file_s, sizeof(__pyx_k_unable_to_open_index_file_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unable_to_read_header_informatio, __pyx_k_unable_to_read_header_informatio, sizeof(__pyx_k_unable_to_read_header_informatio), 0, 0, 1, 0},
  {&__pyx_kp_s_unable_to_reopen_htsfile, __pyx_k_unable_to_reopen_htsfile, sizeof(__pyx_k_unable_to_reopen_htsfile), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_reference, __pyx_k_unknown_reference, sizeof(__pyx_k_unknown_reference), 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_n_s_unmapped, __pyx_k_unmapped, sizeof(__pyx_k_unmapped), 0, 0, 1, 1},
  {&__pyx_n_s_until_eof, __pyx_k_until_eof, sizeof(__pyx_k_until_eof), 0, 0, 1, 1},
  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 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_wb0, __pyx_k_wb0, sizeof(__pyx_k_wb0), 0, 0, 1, 1},
  {&__pyx_n_s_wbu, __pyx_k_wbu, sizeof(__pyx_k_wbu), 0, 0, 1, 1},
  {&__pyx_n_s_wc, __pyx_k_wc, sizeof(__pyx_k_wc), 0, 0, 1, 1},
  {&__pyx_n_s_wh, __pyx_k_wh, sizeof(__pyx_k_wh), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_kp_s_wrong_sequence_information_in_s, __pyx_k_wrong_sequence_information_in_s, sizeof(__pyx_k_wrong_sequence_information_in_s), 0, 0, 1, 0},
  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(0, 62, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 170, __pyx_L1_error)
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 235, __pyx_L1_error)
  __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 259, __pyx_L1_error)
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 288, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 344, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 372, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 451, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 554, __pyx_L1_error)
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 779, __pyx_L1_error)
  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 857, __pyx_L1_error)
  __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 924, __pyx_L1_error)
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 1874, __pyx_L1_error)
  __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 2871, __pyx_L1_error)
  __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 2920, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pysam/libcalignmentfile.pyx":170
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')             # <<<<<<<<<<<<<<
 * 
 *     # check: is AlignmetHeader.__cinit__ called?
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_AlignmentHeader_re); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "pysam/libcalignmentfile.pyx":235
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 *             raise MemoryError("could not create header")             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_could_not_create_header); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "pysam/libcalignmentfile.pyx":284
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
  __pyx_slice__6 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__6)) __PYX_ERR(0, 284, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__6);
  __Pyx_GIVEREF(__pyx_slice__6);
  __pyx_tuple__8 = PyTuple_Pack(2, __pyx_kp_s__7, __pyx_int_1); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 284, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "pysam/libcalignmentfile.pyx":340
 * 
 *         if len(reference_names) != len(reference_lengths):
 *             raise ValueError("number of reference names and lengths do not match")             # <<<<<<<<<<<<<<
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_number_of_reference_names_and_le); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pysam/libcalignmentfile.pyx":453
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):
 */
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_malformatted_header_no_in_field); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "pysam/libcalignmentfile.pyx":533
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:
 *             raise ValueError('could not parse header')             # <<<<<<<<<<<<<<
 *         return tid
 * 
 */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_could_not_parse_header); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "pysam/libcalignmentfile.pyx":554
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, key):
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_AlignmentHeader_does_not_support); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "pysam/libcalignmentfile.pyx":777
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "pysam/libcalignmentfile.pyx":779
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(             # <<<<<<<<<<<<<<
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_AlignmentFile_mapped_only_availa); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "pysam/libcalignmentfile.pyx":782
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "mapping information not recorded in index "
 *                 "or index not available")
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_mapping_information_not_recorded); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 782, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pysam/libcalignmentfile.pyx":828
 *            # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888)
 *            # Better to avoid this (for now) than to produce seemingly correct results.
 *            raise ValueError('Cannot add extra threads when "ignore_truncation" is True')             # <<<<<<<<<<<<<<
 *         self.threads = threads
 * 
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_Cannot_add_extra_threads_when_ig); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "pysam/libcalignmentfile.pyx":857
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_access_from_StringIO_objects_not); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "pysam/libcalignmentfile.pyx":897
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 *                     "and `reference_lengths` for writing")
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_either_supply_options_template_h); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 897, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "pysam/libcalignmentfile.pyx":918
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 *                 raise ValueError("not enough information to construct header. Please provide template, "             # <<<<<<<<<<<<<<
 *                                  "header, text or reference_names/reference_lengths")
 *             self.htsfile = self._open_htsfile()
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_not_enough_information_to_constr); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 918, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "pysam/libcalignmentfile.pyx":936
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")             # <<<<<<<<<<<<<<
 * 
 *             # write header to htsfile
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_failure_when_setting_reference_f); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "pysam/libcalignmentfile.pyx":956
 * 
 *             if self.htsfile.format.category != sequence_data:
 *                 raise ValueError("file does not contain alignment data")             # <<<<<<<<<<<<<<
 * 
 *             if format_options and len(format_options):
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_file_does_not_contain_alignment); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "pysam/libcalignmentfile.pyx":987
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 *                         raise ValueError(             # <<<<<<<<<<<<<<
 *                             "SAM? file does not have a valid header (mode='%s'), "
 *                             "please provide reference_names and reference_lengths")
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_SAM_file_does_not_have_a_valid_h); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 987, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "pysam/libcalignmentfile.pyx":1021
 * 
 *                 elif require_index:
 *                     raise IOError('unable to open index file')             # <<<<<<<<<<<<<<
 * 
 *                 # save start of data section
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_unable_to_open_index_file); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "pysam/libcalignmentfile.pyx":1102
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "fetch called on bamfile without index")
 * 
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_on_bamfile_without); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 1102, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "pysam/libcalignmentfile.pyx":1122
 *         else:
 *             if has_coord:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetching by region is not available for SAM files")
 * 
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_fetching_by_region_is_not_availa); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 1122, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "pysam/libcalignmentfile.pyx":1126
 * 
 *             if multiple_iterators == True:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "multiple iterators not implemented for SAM files")
 * 
 */
  __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_multiple_iterators_not_implement); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 1126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "pysam/libcalignmentfile.pyx":1209
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_mate_not_found); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 1209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "pysam/libcalignmentfile.pyx":1340
 *         if has_coord:
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorColumnRegion(self,
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_pileup); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 1340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "pysam/libcalignmentfile.pyx":1537
 * 
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")             # <<<<<<<<<<<<<<
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_interval_of_size_0); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 1537, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "pysam/libcalignmentfile.pyx":1539
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")             # <<<<<<<<<<<<<<
 * 
 *         cdef int length = _stop - _start
 */
  __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_interval_of_size_less_than_0); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 1539, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "pysam/libcalignmentfile.pyx":1850
 * 
 *         if not self.is_bam and self.header.nreferences == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
  __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_can_not_iterate_over_samfile_wit); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 1850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "pysam/libcalignmentfile.pyx":1887
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.is_valid_tid(tid)
 * 
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 1887, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "pysam/libcalignmentfile.pyx":2025
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")             # <<<<<<<<<<<<<<
 *             self.header = makeAlignmentHeader(hdr)
 * 
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_unable_to_read_header_informatio); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 2025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "pysam/libcalignmentfile.pyx":2073
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for iteration")             # <<<<<<<<<<<<<<
 * 
 *         IteratorRow.__init__(self, samfile,
 */
  __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_iteration); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 2073, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "pysam/libcalignmentfile.pyx":2108
 *             # returns -2 for a truncated file.
 *             # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 2108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_s); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_s); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "pysam/libcalignmentfile.pyx":2232
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
  __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_fetch); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 2232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "(tree fragment)":4
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);

  /* "pysam/libcalignmentfile.pyx":2653
 *         '''
 *         if self.iter is None:
 *             raise TypeError("Raw iterator set up without region cannot be reset")             # <<<<<<<<<<<<<<
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)
 */
  __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_Raw_iterator_set_up_without_regi); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 2653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);

  /* "pysam/libcalignmentfile.pyx":2732
 *             n = self.cnext()
 *             if n < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if n == 0:
 */
  __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 2732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__66 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__66);
  __Pyx_GIVEREF(__pyx_tuple__66);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 */
  __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);

  /* "(tree fragment)":4
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);

  /* "pysam/libcalignmentfile.pyx":2920
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 *                 raise OSError("unable to reopen htsfile")             # <<<<<<<<<<<<<<
 * 
 *             # need to advance in newly opened file to position after header
 */
  __pyx_tuple__69 = PyTuple_Pack(1, __pyx_kp_s_unable_to_reopen_htsfile); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 2920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 */
  __pyx_tuple__70 = PyTuple_Pack(1, __pyx_kp_s_self_htsfile_cannot_be_converted); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(1, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__70);
  __Pyx_GIVEREF(__pyx_tuple__70);

  /* "(tree fragment)":4
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError("self.htsfile cannot be converted to a Python object for pickling")             # <<<<<<<<<<<<<<
 */
  __pyx_tuple__71 = PyTuple_Pack(1, __pyx_kp_s_self_htsfile_cannot_be_converted); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);

  /* "pysam/libcalignmentfile.pyx":95
 * 
 * IndexStats = collections.namedtuple("IndexStats",
 *                                     ("contig",             # <<<<<<<<<<<<<<
 *                                      "mapped",
 *                                      "unmapped",
 */
  __pyx_tuple__73 = PyTuple_Pack(4, __pyx_n_s_contig, __pyx_n_s_mapped, __pyx_n_s_unmapped, __pyx_n_s_total); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 95, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);

  /* "pysam/libcalignmentfile.pyx":94
 *     "IndexedReads"]
 * 
 * IndexStats = collections.namedtuple("IndexStats",             # <<<<<<<<<<<<<<
 *                                     ("contig",
 *                                      "mapped",
 */
  __pyx_tuple__74 = PyTuple_Pack(2, __pyx_n_s_IndexStats, __pyx_tuple__73); if (unlikely(!__pyx_tuple__74)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__74);
  __Pyx_GIVEREF(__pyx_tuple__74);

  /* "pysam/libcalignmentfile.pyx":114
 * 
 * # order of records within SAM headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # default type conversions within SAM header records
 */
  __pyx_tuple__75 = PyTuple_Pack(5, __pyx_n_s_HD, __pyx_n_s_SQ_2, __pyx_n_s_RG, __pyx_n_s_PG, __pyx_n_s_CO); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);

  /* "pysam/libcalignmentfile.pyx":131
 * # output order of fields within records. Ensure that CL is at
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP", "AH"),
 */
  __pyx_tuple__76 = PyTuple_Pack(3, __pyx_n_s_VN, __pyx_n_s_SO, __pyx_n_s_GO); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);

  /* "pysam/libcalignmentfile.pyx":132
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),
 *                       "SQ" : ("SN", "LN", "AS", "M5",             # <<<<<<<<<<<<<<
 *                                "UR", "SP", "AH"),
 *                       "RG" : ("ID", "CN", "SM", "LB",
 */
  __pyx_tuple__77 = PyTuple_Pack(7, __pyx_n_s_SN, __pyx_n_s_LN, __pyx_n_s_AS, __pyx_n_s_M5, __pyx_n_s_UR, __pyx_n_s_SP, __pyx_n_s_AH); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);

  /* "pysam/libcalignmentfile.pyx":134
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP", "AH"),
 *                       "RG" : ("ID", "CN", "SM", "LB",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "DT", "DS",
 *                               "PL", "FO", "KS", "PG",
 */
  __pyx_tuple__78 = PyTuple_Pack(13, __pyx_n_s_ID, __pyx_n_s_CN, __pyx_n_s_SM, __pyx_n_s_LB, __pyx_n_s_PU, __pyx_n_s_PI, __pyx_n_s_DT, __pyx_n_s_DS, __pyx_n_s_PL, __pyx_n_s_FO, __pyx_n_s_KS, __pyx_n_s_PG, __pyx_n_s_PM); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);

  /* "pysam/libcalignmentfile.pyx":138
 *                               "PL", "FO", "KS", "PG",
 *                               "PM"),
 *                       "PG" : ("PN", "ID", "VN", "PP",             # <<<<<<<<<<<<<<
 *                               "DS", "CL"),}
 * 
 */
  __pyx_tuple__79 = PyTuple_Pack(6, __pyx_n_s_PN, __pyx_n_s_ID, __pyx_n_s_VN, __pyx_n_s_PP, __pyx_n_s_DS, __pyx_n_s_CL); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);

  /* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */
  __pyx_tuple__80 = PyTuple_Pack(4, __pyx_n_s_fields, __pyx_n_s_record, __pyx_n_s_line, __pyx_n_s_key); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__80);
  __Pyx_GIVEREF(__pyx_tuple__80);
  __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__80, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_build_header_line, 142, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 142, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */
  __pyx_tuple__81 = PyTuple_Pack(1, __pyx_n_s_code); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);
  __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__81, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_read_failure_reason, 178, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 178, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_tuple__82 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__82, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_SNPCall, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_13 = PyInt_FromLong(13); if (unlikely(!__pyx_int_13)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1796 = PyInt_FromLong(1796); if (unlikely(!__pyx_int_1796)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_84615809 = PyInt_FromLong(84615809L); if (unlikely(!__pyx_int_84615809)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_2 = PyInt_FromLong(-2); if (unlikely(!__pyx_int_neg_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 195, __pyx_L1_error)
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__.doc = __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__;
    }
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_AlignmentHeader, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = &__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader;
  __pyx_t_1 = PyImport_ImportModule("pysam.libchtslib"); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType(__pyx_t_1, "pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_10libchtslib_HTSFile) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile = &__pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.__pyx_base = *__pyx_vtabptr_5pysam_10libchtslib_HTSFile;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.write = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write;
  __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_base = __pyx_ptype_5pysam_10libchtslib_HTSFile;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_AlignmentFile, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = &__pyx_type_5pysam_17libcalignmentfile_AlignmentFile;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1966, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRow, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1966, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1966, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = &__pyx_type_5pysam_17libcalignmentfile_IteratorRow;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *))__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *))__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext;
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2054, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2054, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowRegion, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2054, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2054, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *))__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *))__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext;
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2116, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2116, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowHead, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2116, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2116, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *))__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *))__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext;
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2169, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2169, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowAll, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2169, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2169, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll;
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2214, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowAllRefs, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2214, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2214, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *))__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *))__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext;
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2279, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2279, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowSelection, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2279, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2279, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.get_sequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._setup_iterator = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._setup_raw_rest_iterator = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_raw_rest_iterator;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._free_pileup_iter = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2452, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2452, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumn, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2452, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2452, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumn;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2702, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2702, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumnRegion, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2702, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2702, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2752, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2752, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumnAllRefs, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2752, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2752, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAll;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAll.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2794, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2794, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumnAll, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2794, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2794, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2882, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IndexedReads, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2882, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2882, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = &__pyx_type_5pysam_17libcalignmentfile_IndexedReads;
  if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2823, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_SNPCall, (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2823, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2823, __pyx_L1_error)
  __pyx_ptype_5pysam_17libcalignmentfile_SNPCall = &__pyx_type_5pysam_17libcalignmentfile_SNPCall;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", 
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(4, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(5, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(6, 15, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("array"); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_5array_array = __Pyx_ImportType(__pyx_t_1, "array", "array", sizeof(arrayobject), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_7cpython_5array_array) __PYX_ERR(3, 58, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("pysam.libcfaidx"); if (unlikely(!__pyx_t_1)) __PYX_ERR(7, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5pysam_9libcfaidx_FastaFile = __Pyx_ImportType(__pyx_t_1, "pysam.libcfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastaFile), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_9libcfaidx_FastaFile) __PYX_ERR(7, 37, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(7, 37, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastqProxy = __Pyx_ImportType(__pyx_t_1, "pysam.libcfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_9libcfaidx_FastqProxy) __PYX_ERR(7, 45, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastxRecord = __Pyx_ImportType(__pyx_t_1, "pysam.libcfaidx", "FastxRecord", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_9libcfaidx_FastxRecord) __PYX_ERR(7, 52, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxRecord->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(7, 52, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType(__pyx_t_1, "pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_9libcfaidx_FastxFile) __PYX_ERR(7, 61, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 61, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType(__pyx_t_1, "pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_9libcfaidx_FastqFile) __PYX_ERR(7, 73, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 73, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType(__pyx_t_1, "pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_9libcfaidx_Fastafile) __PYX_ERR(7, 78, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 78, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("pysam.libcalignedsegment"); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = __Pyx_ImportType(__pyx_t_1, "pysam.libcalignedsegment", "AlignedSegment", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment) __PYX_ERR(8, 34, __pyx_L1_error)
  __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment = (struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment*)__Pyx_GetVtable(__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment)) __PYX_ERR(8, 34, __pyx_L1_error)
  __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = __Pyx_ImportType(__pyx_t_1, "pysam.libcalignedsegment", "PileupColumn", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn) __PYX_ERR(8, 65, __pyx_L1_error)
  __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = __Pyx_ImportType(__pyx_t_1, "pysam.libcalignedsegment", "PileupRead", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5pysam_18libcalignedsegment_PileupRead) __PYX_ERR(8, 75, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __pyx_t_1 = PyImport_ImportModule("pysam.libcalignedsegment"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "makeAlignedSegment", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment, "struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "makePileupColumn", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makePileupColumn, "struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(bam_pileup1_t const **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("pysam.libcutils"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "encode_filename", (void (**)(void))&__pyx_f_5pysam_9libcutils_encode_filename, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "from_string_and_size", (void (**)(void))&__pyx_f_5pysam_9libcutils_from_string_and_size, "PyObject *(char const *, size_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}


#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initlibcalignmentfile(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initlibcalignmentfile(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec_libcalignmentfile(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  __Pyx_TraceDeclarations
  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;
  int __pyx_t_6;
  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_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module 'libcalignmentfile' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #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("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("libcalignmentfile", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __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_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_pysam__libcalignmentfile) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "pysam.libcalignmentfile")) {
      if (unlikely(PyDict_SetItemString(modules, "pysam.libcalignmentfile", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  (void)__Pyx_modinit_function_export_code();
  if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_variable_import_code();
  if (unlikely(__Pyx_modinit_function_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":58
 * #
 * ########################################################
 * import os             # <<<<<<<<<<<<<<
 * import collections
 * try:
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":59
 * ########################################################
 * import os
 * import collections             # <<<<<<<<<<<<<<
 * try:
 *     from collections.abc import Sequence, Mapping  # noqa
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":60
 * import os
 * import collections
 * try:             # <<<<<<<<<<<<<<
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    /*try:*/ {

      /* "pysam/libcalignmentfile.pyx":61
 * import collections
 * try:
 *     from collections.abc import Sequence, Mapping  # noqa             # <<<<<<<<<<<<<<
 * except ImportError:
 *     from collections import Sequence, Mapping  # noqa
 */
      __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_n_s_Sequence);
      __Pyx_GIVEREF(__pyx_n_s_Sequence);
      PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Sequence);
      __Pyx_INCREF(__pyx_n_s_Mapping);
      __Pyx_GIVEREF(__pyx_n_s_Mapping);
      PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_Mapping);
      __pyx_t_5 = __Pyx_Import(__pyx_n_s_collections_abc, __pyx_t_1, -1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Sequence, __pyx_t_1) < 0) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Mapping, __pyx_t_1) < 0) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":60
 * import os
 * import collections
 * try:             # <<<<<<<<<<<<<<
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 */
    }
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L7_try_end;
    __pyx_L2_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":62
 * try:
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:             # <<<<<<<<<<<<<<
 *     from collections import Sequence, Mapping  # noqa
 * import re
 */
    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ImportError);
    if (__pyx_t_6) {
      __Pyx_AddTraceback("pysam.libcalignmentfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_1, &__pyx_t_7) < 0) __PYX_ERR(0, 62, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_7);

      /* "pysam/libcalignmentfile.pyx":63
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 *     from collections import Sequence, Mapping  # noqa             # <<<<<<<<<<<<<<
 * import re
 * import warnings
 */
      __pyx_t_8 = PyList_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_n_s_Sequence);
      __Pyx_GIVEREF(__pyx_n_s_Sequence);
      PyList_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_Sequence);
      __Pyx_INCREF(__pyx_n_s_Mapping);
      __Pyx_GIVEREF(__pyx_n_s_Mapping);
      PyList_SET_ITEM(__pyx_t_8, 1, __pyx_n_s_Mapping);
      __pyx_t_9 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_8, -1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_ImportFrom(__pyx_t_9, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Sequence, __pyx_t_8) < 0) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_ImportFrom(__pyx_t_9, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Mapping, __pyx_t_8) < 0) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L3_exception_handled;
    }
    goto __pyx_L4_except_error;
    __pyx_L4_except_error:;

    /* "pysam/libcalignmentfile.pyx":60
 * import os
 * import collections
 * try:             # <<<<<<<<<<<<<<
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 */
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L1_error;
    __pyx_L3_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    __pyx_L7_try_end:;
  }

  /* "pysam/libcalignmentfile.pyx":64
 * except ImportError:
 *     from collections import Sequence, Mapping  # noqa
 * import re             # <<<<<<<<<<<<<<
 * import warnings
 * import array
 */
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 64, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_7) < 0) __PYX_ERR(0, 64, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":65
 *     from collections import Sequence, Mapping  # noqa
 * import re
 * import warnings             # <<<<<<<<<<<<<<
 * import array
 * from libc.errno  cimport errno, EPIPE
 */
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_warnings, 0, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 65, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_7) < 0) __PYX_ERR(0, 65, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":66
 * import re
 * import warnings
 * import array             # <<<<<<<<<<<<<<
 * from libc.errno  cimport errno, EPIPE
 * from libc.string cimport strcmp, strpbrk, strerror
 */
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_7) < 0) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":79
 * from pysam.libchtslib cimport HTSFile, hisremote
 * 
 * if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
 *     from io import StringIO
 * else:
 */
  __pyx_t_10 = ((PY_MAJOR_VERSION >= 3) != 0);
  if (__pyx_t_10) {

    /* "pysam/libcalignmentfile.pyx":80
 * 
 * if PY_MAJOR_VERSION >= 3:
 *     from io import StringIO             # <<<<<<<<<<<<<<
 * else:
 *     from StringIO import StringIO
 */
    __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_n_s_StringIO);
    __Pyx_GIVEREF(__pyx_n_s_StringIO);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_StringIO);
    __pyx_t_1 = __Pyx_Import(__pyx_n_s_io, __pyx_t_7, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_7) < 0) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":79
 * from pysam.libchtslib cimport HTSFile, hisremote
 * 
 * if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
 *     from io import StringIO
 * else:
 */
    goto __pyx_L10;
  }

  /* "pysam/libcalignmentfile.pyx":82
 *     from io import StringIO
 * else:
 *     from StringIO import StringIO             # <<<<<<<<<<<<<<
 * 
 * cimport cython
 */
  /*else*/ {
    __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_n_s_StringIO);
    __Pyx_GIVEREF(__pyx_n_s_StringIO);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_StringIO);
    __pyx_t_7 = __Pyx_Import(__pyx_n_s_StringIO, __pyx_t_1, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_1) < 0) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __pyx_L10:;

  /* "pysam/libcalignmentfile.pyx":87
 * 
 * 
 * __all__ = [             # <<<<<<<<<<<<<<
 *     "AlignmentFile",
 *     "AlignmentHeader",
 */
  __pyx_t_7 = PyList_New(5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_AlignmentFile);
  __Pyx_GIVEREF(__pyx_n_s_AlignmentFile);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_AlignmentFile);
  __Pyx_INCREF(__pyx_n_s_AlignmentHeader);
  __Pyx_GIVEREF(__pyx_n_s_AlignmentHeader);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_AlignmentHeader);
  __Pyx_INCREF(__pyx_n_s_IteratorRow);
  __Pyx_GIVEREF(__pyx_n_s_IteratorRow);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_n_s_IteratorRow);
  __Pyx_INCREF(__pyx_n_s_IteratorColumn);
  __Pyx_GIVEREF(__pyx_n_s_IteratorColumn);
  PyList_SET_ITEM(__pyx_t_7, 3, __pyx_n_s_IteratorColumn);
  __Pyx_INCREF(__pyx_n_s_IndexedReads);
  __Pyx_GIVEREF(__pyx_n_s_IndexedReads);
  PyList_SET_ITEM(__pyx_t_7, 4, __pyx_n_s_IndexedReads);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all_2, __pyx_t_7) < 0) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":94
 *     "IndexedReads"]
 * 
 * IndexStats = collections.namedtuple("IndexStats",             # <<<<<<<<<<<<<<
 *                                     ("contig",
 *                                      "mapped",
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_collections); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_namedtuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":95
 * 
 * IndexStats = collections.namedtuple("IndexStats",
 *                                     ("contig",             # <<<<<<<<<<<<<<
 *                                      "mapped",
 *                                      "unmapped",
 */
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__74, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_IndexStats, __pyx_t_7) < 0) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":104
 * # maximum genomic coordinace
 * # for some reason, using 'int' causes overflow
 * cdef int MAX_POS = (1 << 31) - 1             # <<<<<<<<<<<<<<
 * 
 * # valid types for SAM headers
 */
  __pyx_v_5pysam_17libcalignmentfile_MAX_POS = 0x7FFFFFFF;

  /* "pysam/libcalignmentfile.pyx":107
 * 
 * # valid types for SAM headers
 * VALID_HEADER_TYPES = {"HD" : Mapping,             # <<<<<<<<<<<<<<
 *                       "SQ" : Sequence,
 *                       "RG" : Sequence,
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_HD, __pyx_t_1) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":108
 * # valid types for SAM headers
 * VALID_HEADER_TYPES = {"HD" : Mapping,
 *                       "SQ" : Sequence,             # <<<<<<<<<<<<<<
 *                       "RG" : Sequence,
 *                       "PG" : Sequence,
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_SQ_2, __pyx_t_1) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":109
 * VALID_HEADER_TYPES = {"HD" : Mapping,
 *                       "SQ" : Sequence,
 *                       "RG" : Sequence,             # <<<<<<<<<<<<<<
 *                       "PG" : Sequence,
 *                       "CO" : Sequence}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_RG, __pyx_t_1) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":110
 *                       "SQ" : Sequence,
 *                       "RG" : Sequence,
 *                       "PG" : Sequence,             # <<<<<<<<<<<<<<
 *                       "CO" : Sequence}
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_PG, __pyx_t_1) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":111
 *                       "RG" : Sequence,
 *                       "PG" : Sequence,
 *                       "CO" : Sequence}             # <<<<<<<<<<<<<<
 * 
 * # order of records within SAM headers
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_CO, __pyx_t_1) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_TYPES, __pyx_t_7) < 0) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":114
 * 
 * # order of records within SAM headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # default type conversions within SAM header records
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADERS, __pyx_tuple__75) < 0) __PYX_ERR(0, 114, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":117
 * 
 * # default type conversions within SAM header records
 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},             # <<<<<<<<<<<<<<
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_VN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_GO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_HD, __pyx_t_1) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":118
 * # default type conversions within SAM header records
 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,             # <<<<<<<<<<<<<<
 *                                "M5" : str, "SP" : str, "UR" : str,
 *                                "AH" : str,},
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_LN, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_AS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":119
 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,             # <<<<<<<<<<<<<<
 *                                "AH" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_M5, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SP, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_UR, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":120
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,
 *                                "AH" : str,},             # <<<<<<<<<<<<<<
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_AH, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_SQ_2, __pyx_t_1) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":121
 *                                "M5" : str, "SP" : str, "UR" : str,
 *                                "AH" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,             # <<<<<<<<<<<<<<
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_ID, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_CN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_DS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":122
 *                                "AH" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,             # <<<<<<<<<<<<<<
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PM" : str, "PU" : str,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_DT, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_FO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_KS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":123
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,             # <<<<<<<<<<<<<<
 *                                "PL" : str, "PM" : str, "PU" : str,
 *                                "SM" : str,},
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_LB, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PI, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":124
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PM" : str, "PU" : str,             # <<<<<<<<<<<<<<
 *                                "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PL, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PM, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PU, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":125
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PM" : str, "PU" : str,
 *                                "SM" : str,},             # <<<<<<<<<<<<<<
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SM, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_RG, __pyx_t_1) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":126
 *                                "PL" : str, "PM" : str, "PU" : str,
 *                                "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,             # <<<<<<<<<<<<<<
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 * 
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_ID, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_CL, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 126, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":127
 *                                "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}             # <<<<<<<<<<<<<<
 * 
 * # output order of fields within records. Ensure that CL is at
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PP, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_DS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_VN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 126, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_PG, __pyx_t_1) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_KNOWN_HEADER_FIELDS, __pyx_t_7) < 0) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":131
 * # output order of fields within records. Ensure that CL is at
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP", "AH"),
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_HD, __pyx_tuple__76) < 0) __PYX_ERR(0, 131, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":132
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),
 *                       "SQ" : ("SN", "LN", "AS", "M5",             # <<<<<<<<<<<<<<
 *                                "UR", "SP", "AH"),
 *                       "RG" : ("ID", "CN", "SM", "LB",
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_SQ_2, __pyx_tuple__77) < 0) __PYX_ERR(0, 131, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":134
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP", "AH"),
 *                       "RG" : ("ID", "CN", "SM", "LB",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "DT", "DS",
 *                               "PL", "FO", "KS", "PG",
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_RG, __pyx_tuple__78) < 0) __PYX_ERR(0, 131, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":138
 *                               "PL", "FO", "KS", "PG",
 *                               "PM"),
 *                       "PG" : ("PN", "ID", "VN", "PP",             # <<<<<<<<<<<<<<
 *                               "DS", "CL"),}
 * 
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_PG, __pyx_tuple__79) < 0) __PYX_ERR(0, 131, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_ORDER, __pyx_t_7) < 0) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_5pysam_17libcalignmentfile_1build_header_line, NULL, __pyx_n_s_pysam_libcalignmentfile); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_header_line, __pyx_t_7) < 0) __PYX_ERR(0, 142, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_5pysam_17libcalignmentfile_3read_failure_reason, NULL, __pyx_n_s_pysam_libcalignmentfile); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_failure_reason, __pyx_t_7) < 0) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":238
 * 
 *     @classmethod
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):             # <<<<<<<<<<<<<<
 * 
 *         cdef AlignmentHeader self = AlignmentHeader()
 */
  __Pyx_GetNameInClass(__pyx_t_7, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/libcalignmentfile.pyx":237
 *             raise MemoryError("could not create header")
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 */
  __pyx_t_1 = __Pyx_Method_ClassMethod(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_text_and_lengths, __pyx_t_1) < 0) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":279
 * 
 *     @classmethod
 *     def from_text(cls, text):             # <<<<<<<<<<<<<<
 * 
 *         reference_names, reference_lengths = [], []
 */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 279, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":278
 *         return self
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_text(cls, text):
 * 
 */
  __pyx_t_7 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_text, __pyx_t_7) < 0) __PYX_ERR(0, 279, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":296
 * 
 *     @classmethod
 *     def from_dict(cls, header_dict):             # <<<<<<<<<<<<<<
 * 
 *         cdef list lines = []
 */
  __Pyx_GetNameInClass(__pyx_t_7, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/libcalignmentfile.pyx":295
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_dict(cls, header_dict):
 * 
 */
  __pyx_t_1 = __Pyx_Method_ClassMethod(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_dict, __pyx_t_1) < 0) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":337
 * 
 *     @classmethod
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):             # <<<<<<<<<<<<<<
 * 
 *         if len(reference_names) != len(reference_lengths):
 */
  __Pyx_GetNameInClass(__pyx_t_1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_references); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":336
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 */
  __pyx_t_7 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_references, __pyx_t_7) < 0) __PYX_ERR(0, 337, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":2709
 *                   int tid = 0,
 *                   int start = 0,
 *                   int stop = MAX_POS,             # <<<<<<<<<<<<<<
 *                   int truncate = False,
 *                   int multiple_iterators = True,
 */
  __pyx_k__61 = __pyx_v_5pysam_17libcalignmentfile_MAX_POS;

  /* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall, NULL, __pyx_n_s_pysam_libcalignmentfile); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_SNPCall, __pyx_t_7) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=True
 * ########################################################
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_7) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "array.pxd":161
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */
  __Pyx_TraceReturn(Py_None, 0);

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init pysam.libcalignmentfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_CLEAR(__pyx_m);
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysam.libcalignmentfile");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
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);
}
#endif

/* GetBuiltinName */
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;
}

/* RaiseArgTupleInvalid */
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);
}

/* RaiseDoubleKeywords */
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
}

/* ParseKeywords */
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_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
                    (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(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
                        (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(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;
}

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* Profile */
#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   PyThreadState* tstate,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    PyObject *type, *value, *traceback;
    int retval;
    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
    }
    __Pyx_PyFrame_SetLineNumber(*frame, firstlineno);
    retval = 1;
    __Pyx_EnterTracing(tstate);
    __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
    #if CYTHON_TRACE
    if (tstate->c_tracefunc)
        retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
    if (retval && tstate->c_profilefunc)
    #endif
        retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
    __Pyx_LeaveTracing(tstate);
    if (retval) {
        __Pyx_ErrRestoreInState(tstate, type, value, traceback);
        return __Pyx_IsTracing(tstate, 0, 0) && retval;
    } else {
        Py_XDECREF(type);
        Py_XDECREF(value);
        Py_XDECREF(traceback);
        return -1;
    }
}
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
    PyCodeObject *py_code = 0;
#if PY_MAJOR_VERSION >= 3
    py_code = PyCode_NewEmpty(srcfile, funcname, firstlineno);
    if (likely(py_code)) {
        py_code->co_flags |= CO_OPTIMIZED | CO_NEWLOCALS;
    }
#else
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    py_funcname = PyString_FromString(funcname);
    if (unlikely(!py_funcname)) goto bad;
    py_srcfile = PyString_FromString(srcfile);
    if (unlikely(!py_srcfile)) goto bad;
    py_code = PyCode_New(
        0,
        0,
        0,
        CO_OPTIMIZED | CO_NEWLOCALS,
        __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,
        __pyx_empty_bytes      /*PyObject *lnotab*/
    );
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
#endif
    return py_code;
}
#endif

/* BytesEquals */
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;
#if CYTHON_USE_UNICODE_INTERNALS
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            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
}

/* UnicodeEquals */
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 (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        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, (size_t)(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_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        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
}

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
#else
    if (likely(PyCFunction_Check(func)))
#endif
    {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
    }
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (__Pyx_PyFastCFunction_Check(func)) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* GetItemInt */
static 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,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_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,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_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,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(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(__Pyx_is_valid_index(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))
                        return NULL;
                    PyErr_Clear();
                }
            }
            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));
}

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
    PyObject *runerr;
    Py_ssize_t key_value;
    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
    if (unlikely(!(m && m->sq_item))) {
        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
        return NULL;
    }
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
    if (likely(m && m->mp_subscript)) {
        return m->mp_subscript(obj, key);
    }
    return __Pyx_PyObject_GetIndex(obj, key);
}
#endif

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* StringJoin */
#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

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    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 (PyType_Check(type)) {
#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;
        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;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
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) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        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 (cause) {
        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) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_FALSE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_FALSE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_EQ));
}

/* PyObjectCall2Args */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *result = NULL;
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyFunction_FastCall(function, args, 2);
    }
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyCFunction_FastCall(function, args, 2);
    }
    #endif
    args = PyTuple_New(2);
    if (unlikely(!args)) goto done;
    Py_INCREF(arg1);
    PyTuple_SET_ITEM(args, 0, arg1);
    Py_INCREF(arg2);
    PyTuple_SET_ITEM(args, 1, arg2);
    Py_INCREF(function);
    result = __Pyx_PyObject_Call(function, args, NULL);
    Py_DECREF(args);
    Py_DECREF(function);
done:
    return result;
}

/* KeywordStringCheck */
static int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_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_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;
}

/* SliceObject */
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_USE_TYPE_SLOTS
    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))
                    goto bad;
                PyErr_Clear();
            }
        }
        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_USE_TYPE_SLOTS
        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;
}

/* DictGetItem */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            if (unlikely(PyTuple_Check(key))) {
                PyObject* args = PyTuple_Pack(1, key);
                if (likely(args)) {
                    PyErr_SetObject(PyExc_KeyError, args);
                    Py_DECREF(args);
                }
            } else {
                PyErr_SetObject(PyExc_KeyError, key);
            }
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    #endif
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    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;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    if (unlikely(PyTuple_Check(err)))
        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* GetException */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
#endif
{
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    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_FAST_THREAD_STATE
    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_FAST_THREAD_STATE
    #if CYTHON_USE_EXC_INFO_STACK
    {
        _PyErr_StackItem *exc_info = tstate->exc_info;
        tmp_type = exc_info->exc_type;
        tmp_value = exc_info->exc_value;
        tmp_tb = exc_info->exc_traceback;
        exc_info->exc_type = local_type;
        exc_info->exc_value = local_value;
        exc_info->exc_traceback = local_tb;
    }
    #else
    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;
    #endif
    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;
}

/* RaiseTooManyValuesToUnpack */
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);
}

/* RaiseNeedMoreValuesToUnpack */
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");
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(__Pyx_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
}

/* UnpackItemEndCheck */
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;
}

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __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);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* PyObjectGetMethod */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
    PyObject *attr;
#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
    PyTypeObject *tp = Py_TYPE(obj);
    PyObject *descr;
    descrgetfunc f = NULL;
    PyObject **dictptr, *dict;
    int meth_found = 0;
    assert (*method == NULL);
    if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
        attr = __Pyx_PyObject_GetAttrStr(obj, name);
        goto try_unpack;
    }
    if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
        return 0;
    }
    descr = _PyType_Lookup(tp, name);
    if (likely(descr != NULL)) {
        Py_INCREF(descr);
#if PY_MAJOR_VERSION >= 3
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type)))
        #endif
#else
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr)))
        #endif
#endif
        {
            meth_found = 1;
        } else {
            f = Py_TYPE(descr)->tp_descr_get;
            if (f != NULL && PyDescr_IsData(descr)) {
                attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
                Py_DECREF(descr);
                goto try_unpack;
            }
        }
    }
    dictptr = _PyObject_GetDictPtr(obj);
    if (dictptr != NULL && (dict = *dictptr) != NULL) {
        Py_INCREF(dict);
        attr = __Pyx_PyDict_GetItemStr(dict, name);
        if (attr != NULL) {
            Py_INCREF(attr);
            Py_DECREF(dict);
            Py_XDECREF(descr);
            goto try_unpack;
        }
        Py_DECREF(dict);
    }
    if (meth_found) {
        *method = descr;
        return 1;
    }
    if (f != NULL) {
        attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
        Py_DECREF(descr);
        goto try_unpack;
    }
    if (descr != NULL) {
        *method = descr;
        return 0;
    }
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(name));
#endif
    return 0;
#else
    attr = __Pyx_PyObject_GetAttrStr(obj, name);
    goto try_unpack;
#endif
try_unpack:
#if CYTHON_UNPACK_METHODS
    if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
        PyObject *function = PyMethod_GET_FUNCTION(attr);
        Py_INCREF(function);
        Py_DECREF(attr);
        *method = function;
        return 1;
    }
#endif
    *method = attr;
    return 0;
}

/* PyObjectCallMethod1 */
static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
    PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
    Py_DECREF(method);
    return result;
}
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method = NULL, *result;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_Call2Args(method, obj, arg);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) return NULL;
    return __Pyx__PyObject_CallMethod1(method, arg);
}

/* append */
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;
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

/* GetAttr */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* HasAttr */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (unlikely(!r)) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* ExtTypeTest */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(__Pyx_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_FALSE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a != b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_TRUE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_TRUE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a != (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_NE));
}

/* PyObjectCallMethod0 */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method = NULL, *result = NULL;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_CallOneArg(method, obj);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) goto bad;
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

/* RaiseNoneIterError */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* UnpackTupleError */
static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
    if (t == Py_None) {
      __Pyx_RaiseNoneNotIterableError();
    } else if (PyTuple_GET_SIZE(t) < index) {
      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
    } else {
      __Pyx_RaiseTooManyValuesError(index);
    }
}

/* UnpackTuple2 */
static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
        PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
    PyObject *value1 = NULL, *value2 = NULL;
#if CYTHON_COMPILING_IN_PYPY
    value1 = PySequence_ITEM(tuple, 0);  if (unlikely(!value1)) goto bad;
    value2 = PySequence_ITEM(tuple, 1);  if (unlikely(!value2)) goto bad;
#else
    value1 = PyTuple_GET_ITEM(tuple, 0);  Py_INCREF(value1);
    value2 = PyTuple_GET_ITEM(tuple, 1);  Py_INCREF(value2);
#endif
    if (decref_tuple) {
        Py_DECREF(tuple);
    }
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
#if CYTHON_COMPILING_IN_PYPY
bad:
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
#endif
}
static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
                                       int has_known_size, int decref_tuple) {
    Py_ssize_t index;
    PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
    iternextfunc iternext;
    iter = PyObject_GetIter(tuple);
    if (unlikely(!iter)) goto bad;
    if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
    iternext = Py_TYPE(iter)->tp_iternext;
    value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
    value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
    if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
    Py_DECREF(iter);
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
unpacking_failed:
    if (!has_known_size && __Pyx_IterFinish() == 0)
        __Pyx_RaiseNeedMoreValuesError(index);
bad:
    Py_XDECREF(iter);
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
}

/* dict_iter */
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_source_is_dict) {
    is_dict = is_dict || likely(PyDict_CheckExact(iterable));
    *p_source_is_dict = is_dict;
    if (is_dict) {
#if !CYTHON_COMPILING_IN_PYPY
        *p_orig_length = PyDict_Size(iterable);
        Py_INCREF(iterable);
        return iterable;
#elif PY_MAJOR_VERSION >= 3
        static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL;
        PyObject **pp = NULL;
        if (method_name) {
            const char *name = PyUnicode_AsUTF8(method_name);
            if (strcmp(name, "iteritems") == 0) pp = &py_items;
            else if (strcmp(name, "iterkeys") == 0) pp = &py_keys;
            else if (strcmp(name, "itervalues") == 0) pp = &py_values;
            if (pp) {
                if (!*pp) {
                    *pp = PyUnicode_FromString(name + 4);
                    if (!*pp)
                        return NULL;
                }
                method_name = *pp;
            }
        }
#endif
    }
    *p_orig_length = 0;
    if (method_name) {
        PyObject* iter;
        iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
        if (!iterable)
            return NULL;
#if !CYTHON_COMPILING_IN_PYPY
        if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
            return iterable;
#endif
        iter = PyObject_GetIter(iterable);
        Py_DECREF(iterable);
        return iter;
    }
    return PyObject_GetIter(iterable);
}
static CYTHON_INLINE int __Pyx_dict_iter_next(
        PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
        PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
    PyObject* next_item;
#if !CYTHON_COMPILING_IN_PYPY
    if (source_is_dict) {
        PyObject *key, *value;
        if (unlikely(orig_length != PyDict_Size(iter_obj))) {
            PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
            return -1;
        }
        if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
            return 0;
        }
        if (pitem) {
            PyObject* tuple = PyTuple_New(2);
            if (unlikely(!tuple)) {
                return -1;
            }
            Py_INCREF(key);
            Py_INCREF(value);
            PyTuple_SET_ITEM(tuple, 0, key);
            PyTuple_SET_ITEM(tuple, 1, value);
            *pitem = tuple;
        } else {
            if (pkey) {
                Py_INCREF(key);
                *pkey = key;
            }
            if (pvalue) {
                Py_INCREF(value);
                *pvalue = value;
            }
        }
        return 1;
    } else if (PyTuple_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyTuple_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else if (PyList_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyList_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else
#endif
    {
        next_item = PyIter_Next(iter_obj);
        if (unlikely(!next_item)) {
            return __Pyx_IterFinish();
        }
    }
    if (pitem) {
        *pitem = next_item;
    } else if (pkey && pvalue) {
        if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
            return -1;
    } else if (pkey) {
        *pkey = next_item;
    } else {
        *pvalue = next_item;
    }
    return 1;
}

/* MergeKeywords */
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
    PyObject *iter, *key = NULL, *value = NULL;
    int source_is_dict, result;
    Py_ssize_t orig_length, ppos = 0;
    iter = __Pyx_dict_iterator(source_mapping, 0, __pyx_n_s_items, &orig_length, &source_is_dict);
    if (unlikely(!iter)) {
        PyObject *args;
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        args = PyTuple_Pack(1, source_mapping);
        if (likely(args)) {
            PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL);
            Py_DECREF(args);
            if (likely(fallback)) {
                iter = __Pyx_dict_iterator(fallback, 1, __pyx_n_s_items, &orig_length, &source_is_dict);
                Py_DECREF(fallback);
            }
        }
        if (unlikely(!iter)) goto bad;
    }
    while (1) {
        result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict);
        if (unlikely(result < 0)) goto bad;
        if (!result) break;
        if (unlikely(PyDict_Contains(kwdict, key))) {
            __Pyx_RaiseDoubleKeywordsError("function", key);
            result = -1;
        } else {
            result = PyDict_SetItem(kwdict, key, value);
        }
        Py_DECREF(key);
        Py_DECREF(value);
        if (unlikely(result < 0)) goto bad;
    }
    Py_XDECREF(iter);
    return 0;
bad:
    Py_XDECREF(iter);
    return -1;
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
            return PyInt_FromLong(a & b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_and(op1, op2);
            }
        }
                x = a & b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla & llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceAnd : PyNumber_And)(op1, op2);
}
#endif

/* None */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* pyfrozenset_new */
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
    if (it) {
        PyObject* result;
#if CYTHON_COMPILING_IN_PYPY
        PyObject* args;
        args = PyTuple_Pack(1, it);
        if (unlikely(!args))
            return NULL;
        result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL);
        Py_DECREF(args);
        return result;
#else
        if (PyFrozenSet_CheckExact(it)) {
            Py_INCREF(it);
            return it;
        }
        result = PyFrozenSet_New(it);
        if (unlikely(!result))
            return NULL;
        if ((PY_VERSION_HEX >= 0x031000A1) || likely(PySet_GET_SIZE(result)))
            return result;
        Py_DECREF(result);
#endif
    }
#if CYTHON_USE_TYPE_SLOTS
    return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#else
    return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#endif
}

/* PySetContains */
static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) {
    int result = -1;
    if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) {
        PyObject *tmpkey;
        PyErr_Clear();
        tmpkey = __Pyx_PyFrozenSet_New(key);
        if (tmpkey != NULL) {
            result = PySet_Contains(set, tmpkey);
            Py_DECREF(tmpkey);
        }
    }
    return result;
}
static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) {
    int result = PySet_Contains(set, key);
    if (unlikely(result < 0)) {
        result = __Pyx_PySet_ContainsUnhashable(set, key);
    }
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* UnpackUnboundCMethod */
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
    }
#endif
    return 0;
}

/* CallUnboundCMethod1 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
    if (likely(cfunc->func)) {
        int flag = cfunc->flag;
        if (flag == METH_O) {
            return (*(cfunc->func))(self, arg);
        } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) {
            if (PY_VERSION_HEX >= 0x030700A0) {
                return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
            } else {
                return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
            }
        } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) {
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
        }
    }
    return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 0, arg);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 1, arg);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(2, self, arg);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* CallUnboundCMethod2 */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
    if (likely(cfunc->func)) {
        PyObject *args[2] = {arg1, arg2};
        if (cfunc->flag == METH_FASTCALL) {
            #if PY_VERSION_HEX >= 0x030700A0
            return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
            #else
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
            #endif
        }
        #if PY_VERSION_HEX >= 0x030700A0
        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
        #endif
    }
    return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 0, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 1, arg2);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(3);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 1, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 2, arg2);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(3, self, arg1, arg2);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* dict_getitem_default */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            return NULL;
        value = default_value;
    }
    Py_INCREF(value);
    if ((1));
#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);
    }
#endif
    else {
        if (default_value == Py_None)
            value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key);
        else
            value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value);
    }
    return value;
}

/* GetAttr3 */
static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    Py_INCREF(d);
    return d;
}
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r = __Pyx_GetAttr(o, n);
    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
}

/* Import */
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_MAJOR_VERSION < 3
    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_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CallNextTpDealloc */
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc) {
    PyTypeObject* type = Py_TYPE(obj);
    while (type && type->tp_dealloc != current_tp_dealloc)
        type = type->tp_base;
    while (type && type->tp_dealloc == current_tp_dealloc)
        type = type->tp_base;
    if (type)
        type->tp_dealloc(obj);
}

/* CallNextTpTraverse */
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) {
    PyTypeObject* type = Py_TYPE(obj);
    while (type && type->tp_traverse != current_tp_traverse)
        type = type->tp_base;
    while (type && type->tp_traverse == current_tp_traverse)
        type = type->tp_base;
    if (type && type->tp_traverse)
        return type->tp_traverse(obj, v, a);
    return 0;
}

/* CallNextTpClear */
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
    PyTypeObject* type = Py_TYPE(obj);
    while (type && type->tp_clear != current_tp_clear)
        type = type->tp_base;
    while (type && type->tp_clear == current_tp_clear)
        type = type->tp_base;
    if (type && type->tp_clear)
        type->tp_clear(obj);
}

/* PyObject_GenericGetAttrNoDict */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, attr_name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(attr_name));
#endif
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* PyObjectGetAttrStrNoError */
static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
        return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
    }
#endif
    result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
    if (unlikely(!result)) {
        __Pyx_PyObject_GetAttrStr_ClearAttributeError();
    }
    return result;
}

/* SetupReduce */
static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
  int ret;
  PyObject *name_attr;
  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name_2);
  if (likely(name_attr)) {
      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
  } else {
      ret = -1;
  }
  if (unlikely(ret < 0)) {
      PyErr_Clear();
      ret = 0;
  }
  Py_XDECREF(name_attr);
  return ret;
}
static int __Pyx_setup_reduce(PyObject* type_obj) {
    int ret = 0;
    PyObject *object_reduce = NULL;
    PyObject *object_reduce_ex = NULL;
    PyObject *reduce = NULL;
    PyObject *reduce_ex = NULL;
    PyObject *reduce_cython = NULL;
    PyObject *setstate = NULL;
    PyObject *setstate_cython = NULL;
#if CYTHON_USE_PYTYPE_LOOKUP
    if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD;
#else
    if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD;
#endif
#if CYTHON_USE_PYTYPE_LOOKUP
    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#else
    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#endif
    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD;
    if (reduce_ex == object_reduce_ex) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#else
        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#endif
        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD;
        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
            reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython);
            if (likely(reduce_cython)) {
                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
            } else if (reduce == object_reduce || PyErr_Occurred()) {
                goto __PYX_BAD;
            }
            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
            if (!setstate) PyErr_Clear();
            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
                setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython);
                if (likely(setstate_cython)) {
                    ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                    ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                } else if (!setstate || PyErr_Occurred()) {
                    goto __PYX_BAD;
                }
            }
            PyType_Modified((PyTypeObject*)type_obj);
        }
    }
    goto __PYX_GOOD;
__PYX_BAD:
    if (!PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
    ret = -1;
__PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
    Py_XDECREF(object_reduce);
    Py_XDECREF(object_reduce_ex);
#endif
    Py_XDECREF(reduce);
    Py_XDECREF(reduce_ex);
    Py_XDECREF(reduce_cython);
    Py_XDECREF(setstate);
    Py_XDECREF(setstate_cython);
    return ret;
}

/* TypeImport */
#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
    size_t size, enum __Pyx_ImportType_CheckSize check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    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 ((size_t)basicsize < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* GetVTable */
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
    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;
}

/* SetVTable */
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    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;
}

/* ClassMethod */
static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
#if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM <= 0x05080000
    if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) {
        return PyClassMethod_New(method);
    }
#else
#if CYTHON_COMPILING_IN_PYSTON || CYTHON_COMPILING_IN_PYPY
    if (PyMethodDescr_Check(method))
#else
    #if PY_MAJOR_VERSION == 2
    static PyTypeObject *methoddescr_type = NULL;
    if (methoddescr_type == NULL) {
       PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append");
       if (!meth) return NULL;
       methoddescr_type = Py_TYPE(meth);
       Py_DECREF(meth);
    }
    #else
    PyTypeObject *methoddescr_type = &PyMethodDescr_Type;
    #endif
    if (__Pyx_TypeCheck(method, methoddescr_type))
#endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
        #if PY_VERSION_HEX < 0x03020000
        PyTypeObject *d_type = descr->d_type;
        #else
        PyTypeObject *d_type = descr->d_common.d_type;
        #endif
        return PyDescr_NewClassMethod(d_type, descr->d_method);
    }
#endif
    else if (PyMethod_Check(method)) {
        return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
    }
    else {
        return PyClassMethod_New(method);
    }
}

/* GetNameInClass */
static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) {
    PyObject *result;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    __Pyx_GetModuleGlobalNameUncached(result, name);
    return result;
}
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
    PyObject *result;
    result = __Pyx_PyObject_GetAttrStr(nmspace, name);
    if (!result) {
        result = __Pyx_GetGlobalNameAfterAttributeLookup(name);
    }
    return result;
}

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
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 - start) / 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, ((size_t)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);
}

/* AddTraceback */
#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 = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __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,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);  // XDECREF since it's only set on Py3 if cline
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    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_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(char) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(char),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(char) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (char) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case  1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0])
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) {
                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) {
                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) {
                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (char) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(char) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(char,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(char) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            char val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(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 (char) -1;
        }
    } else {
        char val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (char) -1;
        val = __Pyx_PyInt_As_char(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to char");
    return (char) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to char");
    return (char) -1;
}

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint32_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint32_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint32_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(uint32_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) >= 2 * PyLong_SHIFT) {
                            return (uint32_t) (((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint32_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) >= 3 * PyLong_SHIFT) {
                            return (uint32_t) (((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint32_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) >= 4 * PyLong_SHIFT) {
                            return (uint32_t) (((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (uint32_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(uint32_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint32_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(uint32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(uint32_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(uint32_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint32_t) (((uint32_t)-1)*(((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(uint32_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint32_t) ((((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint32_t) (((uint32_t)-1)*(((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint32_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint32_t) ((((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint32_t) (((uint32_t)-1)*(((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint32_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint32_t) ((((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(uint32_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(x);
        if (!tmp) return (uint32_t) -1;
        val = __Pyx_PyInt_As_uint32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint32_t");
    return (uint32_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint32_t");
    return (uint32_t) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        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);
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(uint32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        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);
    }
}

/* CIntFromPy */
static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int64_t neg_one = (int64_t) -1, const_zero = (int64_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int64_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int64_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int64_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(int64_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) >= 2 * PyLong_SHIFT) {
                            return (int64_t) (((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int64_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) >= 3 * PyLong_SHIFT) {
                            return (int64_t) (((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int64_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) >= 4 * PyLong_SHIFT) {
                            return (int64_t) (((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int64_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int64_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int64_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int64_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int64_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int64_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
                            return (int64_t) (((int64_t)-1)*(((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int64_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
                            return (int64_t) ((((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
                            return (int64_t) (((int64_t)-1)*(((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int64_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
                            return (int64_t) ((((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT) {
                            return (int64_t) (((int64_t)-1)*(((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int64_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT) {
                            return (int64_t) ((((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int64_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int64_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(x);
        if (!tmp) return (int64_t) -1;
        val = __Pyx_PyInt_As_int64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int64_t");
    return (int64_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int64_t");
    return (int64_t) -1;
}

/* CIntFromPy */
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int32_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int32_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int32_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) >= 2 * PyLong_SHIFT) {
                            return (int32_t) (((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) >= 3 * PyLong_SHIFT) {
                            return (int32_t) (((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) >= 4 * PyLong_SHIFT) {
                            return (int32_t) (((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int32_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int32_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int32_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int32_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int32_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
                            return (int32_t) (((int32_t)-1)*(((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
                            return (int32_t) ((((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
                            return (int32_t) (((int32_t)-1)*(((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
                            return (int32_t) ((((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
                            return (int32_t) (((int32_t)-1)*(((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
                            return (int32_t) ((((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int32_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyInt_As_int32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int32_t");
    return (int32_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int32_t");
    return (int32_t) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(uint64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        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);
    }
}

/* CIntFromPy */
static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    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(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint64_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint64_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint64_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(uint64_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) >= 2 * PyLong_SHIFT) {
                            return (uint64_t) (((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint64_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) >= 3 * PyLong_SHIFT) {
                            return (uint64_t) (((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint64_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) >= 4 * PyLong_SHIFT) {
                            return (uint64_t) (((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (uint64_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(uint64_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint64_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(uint64_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(uint64_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(uint64_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint64_t) (((uint64_t)-1)*(((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(uint64_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint64_t) ((((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint64_t) (((uint64_t)-1)*(((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint64_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint64_t) ((((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint64_t) (((uint64_t)-1)*(((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint64_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint64_t) ((((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(uint64_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(x);
        if (!tmp) return (uint64_t) -1;
        val = __Pyx_PyInt_As_uint64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint64_t");
    return (uint64_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint64_t");
    return (uint64_t) -1;
}

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* CheckBinaryVersion */
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);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* FunctionImport */
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, desc);
        goto bad;
    }
    tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* InitStrings */
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
        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;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    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
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const 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)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#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 int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
